-
-
Notifications
You must be signed in to change notification settings - Fork 723
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
feat: keyboard navigation in search #4651
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Ignored Deployment
|
@@ -111,14 +112,15 @@ export const Search = ({ | |||
} | |||
); | |||
useKeyboardShortcut({ key: 'Escape' }, () => { | |||
if (document.activeElement === searchInputRef.current) { | |||
if (searchContainerRef.current?.contains(document.activeElement)) { |
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.
escape anywhere in the search area should hide suggestions
@@ -57,6 +61,10 @@ export const SearchInstructions: VFC<ISearchInstructionsProps> = ({ | |||
condition={filter.options.length > 0} | |||
show={ | |||
<StyledCode | |||
tabIndex={0} |
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.
previously we only supported clicks, now we support on enter when tab index is selected
).toBeInTheDocument(); | ||
|
||
screen.getByText(/Title A/i).click(); | ||
expect(recordedSuggestion).toBe('Title A'); |
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.
previously undefined from filters was added
? '' | ||
: filters.map( | ||
filter => `${filter.name}:${filter.suggestedOption}` | ||
)[0]; |
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.
select index only when filters are present
filter => `${filter.name}:${filter.suggestedOption}` | ||
)[0]; | ||
|
||
const onFilter = (suggestion: string) => { |
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.
extracted existing methods since we use them in click and key down handlers
@@ -0,0 +1,31 @@ | |||
import { useEffect } from 'react'; | |||
|
|||
export const useOnBlur = ( |
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.
reusable hook for navigation away from the element
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.
LGTM
About the changes
Important files
Discussion points
For now the elements we tab between are spans even though button would be more correct. Buttons add too many styles that we'd need to remove.