-
Notifications
You must be signed in to change notification settings - Fork 2.8k
DRAFT: (Feat)Typeahead search support #35441
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
mindlessroman
wants to merge
3
commits into
microsoft:master
Choose a base branch
from
mindlessroman:mindlessroman/feat-type-ahead-search-support
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+252
−2
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
packages/react-components/react-search/library/cypress.config.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| import { baseConfig } from '@fluentui/scripts-cypress'; | ||
|
|
||
| export default baseConfig; | ||
138 changes: 138 additions & 0 deletions
138
packages/react-components/react-search/library/docs/TYPEAHEAD-SEARCHBOX-SPEC.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| # @fluentui/react-search Typeahead Search spec | ||
|
|
||
| ## Background | ||
|
|
||
| The [FluentUI design docs for SearchBox](https://fluent2.microsoft.design/components/web/react/core/searchbox/usage#content) | ||
| give the guidance about search results that render beneath the search box input box. The current | ||
| implementation of the Searchbox doesn't have a native typeahead feature. | ||
|
|
||
| ## Prior Art | ||
|
|
||
| - [OpenUI research for ComboBox](https://open-ui.org/components/combobox.research/) | ||
| - A combobox is a close comparison for this kind of typeahead search. However, a combobox | ||
| appears to be better suited to a finite, known set of options, whereas support for dynamically | ||
| fetched options of an unknown size isn't there. | ||
| - [FluentUI design docs for SearchBox](https://fluent2.microsoft.design/components/web/react/core/searchbox/usage#content) | ||
| - The design docs make a mention of how to sort results, but how to render those results | ||
| would be left to a developer | ||
| - [Autocomplete or typeahead - Azure AI search | Microsoft Learn](https://learn.microsoft.com/en-us/azure/search/search-add-autocomplete-suggestions) | ||
| - [FluentUI Blazor Search](https://www.fluentui-blazor.net/Search#documentation) | ||
| - There is an "autocomplete" section | ||
| - [Typeahead.js](https://typeahead.js.org/examples/) | ||
| - The examples do mostly have pre-fetched options versus dynamically fetching | ||
|
|
||
| ## Sample Code | ||
|
|
||
| _Provide some representative example code that uses the proposed API for the component_ | ||
|
|
||
| ```typescript | ||
| <TypeaheadSearchbox | ||
| onInputChange={handleSearch} // User-defined, using something like TanStack Query | ||
| onItemSelect={handleSelectedResult} // User-defined | ||
| isLoading={isLoading} // User-defined, using something like TanStack Query | ||
| resultList={listOfResults} // User-defined, using something like TanStack Query | ||
| > | ||
| // Searchbox | ||
| <SearchBox | ||
| {...props} | ||
| loadingComponent={<Spinner {...props}/>} // If user wants to have a spinner in the searchbox itself | ||
| > | ||
| // Dropdown | ||
| <TypeaheadResultsDropdown | ||
| appearance="" | ||
| loadingComponent={<Spinner {...props}/>} // If user wants to have a spinner in the dropdown | ||
| > | ||
| // List of search results | ||
| {resultList.map(() => { | ||
| // for every search result | ||
| return ( | ||
| <ResultItem | ||
| text="something-derived" | ||
| media={<someComponent/>} | ||
| onClick={handleResultSelect} // User-defined; eg. Go to specific url for Result | ||
| disabled={} | ||
| > | ||
| <SomeCustomObject> // Maybe some flexibility of whether there can be a child component | ||
| </ResultItem> | ||
| ) | ||
| })} | ||
| </TypeaheadResultsDropdown> | ||
| <TypeaheadSearchbox> | ||
| ``` | ||
|
|
||
| ## Variants | ||
|
|
||
| This could be a wrapper around an existing searchbox component - such that there was a searchbox | ||
| child component - or maybe this could be a variant/configurable part of the existing searchbox | ||
| component. | ||
|
|
||
| ## API | ||
|
|
||
| _List the **Props** and **Slots** proposed for the component. Ideally this would just be a link to the component's `.types.ts` file_ | ||
|
|
||
| ## Structure | ||
|
|
||
| ### Public | ||
|
|
||
| ```tsx | ||
| <TypeaheadSearchbox onInputChange={} onItemSelect={} isLoading={} resultList={}></TypeaheadSearchbox> | ||
| ``` | ||
|
|
||
| - _**Internal**_ | ||
| - _**DOM** - how the component will be rendered as HTML elements_ | ||
|
|
||
| ## Migration | ||
|
|
||
| n/a | ||
|
|
||
| ## Behaviors | ||
|
|
||
| _Explain how the component will behave in use, including:_ | ||
|
|
||
| - _Component States_ - Input should visually behave like a regular searchbox in most cases | ||
|
|
||
| - Rest: no text has been entered | ||
|  | ||
|
|
||
| - Focus: cursor to type ready | ||
| - Focus: typing begins | ||
|
|
||
| - Option 1: The dropdown has a Spinner to indicate the results are loading | ||
|
|
||
|  | ||
|
|
||
| - Option 2: The searchbox itself has a slot for a spinner while the results are loading | ||
|
|
||
|  | ||
|
|
||
| - Focus: Typing has stopped, results have returned and are rendered in a finite list in a dropdown. | ||
| The results have some indicators of uniqueness (name as text, maybe something like an Avatar | ||
| as media, etc). _Optionally_ there could be a `show more results` to link to a more robust | ||
| search result page. | ||
|
|
||
|  | ||
|
|
||
| - _Interaction_ | ||
| - _Keyboard_: A user of the searchbox should be able to navigate the options using the `ArrowUp` and | ||
| `ArrowDown` keys to traverse the list. To select a result, `Enter` (should achieve the same | ||
| functionality as clicking on the item with a cursor). To clear results, `Escape` or similar key. | ||
| - _Cursor_: A user can click on the result from the list that they want to interact with. If this | ||
| is merely to select a fetched option (like a combobox), that is supported. If the selection | ||
| should navigate to a new page/URL, that is supported. | ||
| - _Touch_: Should behave the same as a cursor | ||
| - _Screen readers_: Should indicate that the items are being fetched when in the `isLoading` state | ||
| is active, and should reader the results list much like a regular dropdown | ||
|
|
||
| ## Accessibility | ||
|
|
||
| Base accessibility information is included in the design document. After the spec is filled and review, outcomes from it need to be communicated to design and incorporated in the design document. | ||
|
|
||
| - Decide whether to use **native element** or follow **ARIA** and provide reasons | ||
| - Identify the **[ARIA](https://www.w3.org/TR/wai-aria-practices-1.2/) pattern** and, if the component is listed there, follow its specification as possible. | ||
| - Identify accessibility **variants**, the `role` ([ARIA roles](https://www.w3.org/TR/wai-aria-1.1/#role_definitions)) of the component, its `slots` and `aria-*` props. | ||
| - Describe the **keyboard navigation**: Tab Oder and Arrow Key Navigation. Describe any other keyboard **shortcuts** used | ||
| - Specify texts for **state change announcements** - [ARIA live regions | ||
| ](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Live_Regions) (number of available items in dropdown, error messages, confirmations, ...) | ||
| - Identify UI parts that appear on **hover or focus** and specify keyboard and screen reader interaction with them | ||
| - List cases when **focus** needs to be **trapped** in sections of the UI (for dialogs and popups or for hierarchical navigation) | ||
| - List cases when **focus** needs to be **moved programmatically** (if parts of the UI are appearing/disappearing or other cases) |
20 changes: 20 additions & 0 deletions
20
packages/react-components/react-search/library/docs/erdiagram.mmd
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| erDiagram | ||
| TypeaheadSearchbox ||--o| Searchbox : "child Component" | ||
| ResultList ||--o{ ResultItem : "list of" | ||
| TypeaheadSearchbox ||--o{ ResultList : "prop?" | ||
| TypeaheadSearchbox ||--o| Dropdown : "Child Component" | ||
| Dropdown ||--|| ResultList : "has Child components" | ||
| TypeaheadSearchbox { | ||
| hook onSearchBoxChange() | ||
| state isLoading | ||
|
|
||
| } | ||
| Searchbox {} | ||
| ResultList {} | ||
| ResultItem { | ||
| object resultComponent | ||
| object media | ||
| string textShown | ||
| bool disabled | ||
| func onClick() | ||
| } |
Binary file added
BIN
+10.6 KB
packages/react-components/react-search/library/docs/no-text-entered.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+39.5 KB
packages/react-components/react-search/library/docs/results-fetched.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+23.1 KB
...es/react-components/react-search/library/docs/typing-loading-search-option1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+17.6 KB
...es/react-components/react-search/library/docs/typing-loading-search-option2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
packages/react-components/react-search/library/src/components/SearchBox/SearchBox.cy.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| import 'cypress-real-events'; | ||
| import * as React from 'react'; | ||
| import { mount as mountBase } from '@fluentui/scripts-cypress'; | ||
| import { FluentProvider } from '@fluentui/react-provider'; | ||
| import { teamsLightTheme } from '@fluentui/react-theme'; | ||
| import type { JSXElement } from '@fluentui/react-utilities'; | ||
| import { SearchBox, SearchBoxProps } from '@fluentui/react-search'; | ||
|
|
||
| import { Field } from '@fluentui/react-field'; | ||
|
|
||
| const mount = (element: JSXElement) => { | ||
| mountBase(<FluentProvider theme={teamsLightTheme}>{element}</FluentProvider>); | ||
| }; | ||
|
|
||
| describe('Search box', () => { | ||
| it('clicking the search box should focus', () => { | ||
| mount( | ||
| <Field label="Example"> | ||
| <SearchBox appearance="outline" data-testid="searchbox" /> | ||
| </Field>, | ||
| ); | ||
|
|
||
| cy.get('[data-testid="searchbox"]').click().should('have.focus'); | ||
| }); | ||
|
|
||
| it('clicking the X should delete', () => { | ||
| mount( | ||
| <Field label="Example"> | ||
| <SearchBox appearance="outline" data-testid="searchbox" /> | ||
| </Field>, | ||
| ); | ||
|
|
||
| cy.get('[data-testid="searchbox"]').click().should('have.focus'); | ||
| cy.get('.fui-SearchBox__dismiss').click(); | ||
| cy.get('[data-testid="searchbox"]').should('be.empty'); | ||
| }); | ||
|
|
||
| it('clicking the X should delete text if there has been typing', () => { | ||
| mount( | ||
| <Field label="Example"> | ||
| <SearchBox appearance="outline" data-testid="searchbox" /> | ||
| </Field>, | ||
| ); | ||
|
|
||
| cy.get('[data-testid="searchbox"]').click().should('have.focus'); | ||
| cy.get('[data-testid="searchbox"]').realType('something'); | ||
| cy.get('.fui-SearchBox__dismiss').click(); | ||
| cy.get('[data-testid="searchbox"]').should('be.empty'); | ||
| }); | ||
|
|
||
| it('hitting esc key should delete text if there has been typing', () => { | ||
| mount( | ||
| <Field label="Example"> | ||
| <SearchBox appearance="outline" data-testid="searchbox" /> | ||
| </Field>, | ||
| ); | ||
|
|
||
| cy.get('[data-testid="searchbox"]').click().should('have.focus'); | ||
| cy.get('[data-testid="searchbox"]').realType('something'); | ||
| cy.get('[data-testid="searchbox"]').realPress('Escape'); | ||
| cy.get('[data-testid="searchbox"]').should('be.empty'); | ||
| }); | ||
|
|
||
| it('hitting esc key should delete text if there has been typing', () => { | ||
| mount( | ||
| <Field label="Example"> | ||
| <SearchBox appearance="outline" data-testid="searchbox" /> | ||
| </Field>, | ||
| ); | ||
|
|
||
| cy.get('[data-testid="searchbox"]').click().should('have.focus'); | ||
| cy.get('[data-testid="searchbox"]').realType('something'); | ||
| cy.get('[data-testid="searchbox"]').realPress('Escape'); | ||
| cy.get('[data-testid="searchbox"]').should('be.empty'); | ||
| }); | ||
| }); |
9 changes: 9 additions & 0 deletions
9
packages/react-components/react-search/library/tsconfig.cy.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "extends": "./tsconfig.json", | ||
| "compilerOptions": { | ||
| "isolatedModules": false, | ||
| "types": ["node", "cypress", "cypress-real-events"], | ||
| "typeRoots": ["../../../../node_modules", "../../../../node_modules/@types"] | ||
| }, | ||
| "include": ["**/*.cy.ts", "**/*.cy.tsx"] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🕵🏾♀️ visual changes to review in the Visual Change Report
vr-tests-react-components/Charts-DonutChart 3 screenshots
vr-tests-react-components/Positioning 2 screenshots
vr-tests-react-components/Skeleton converged 1 screenshots