Attach keydown listeners to searchbar #9845
Open
+60
−3
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.
Closes #7916
I have implemented the suggested behaviors from #7916 but would like to know if there are additional navigation features/more preferred navigation flows for this component.
I wasn't entirely sure what the intended behavior should be when a user presses Tab while focused on the Form input field and left it as the default behavior.
Fix
Technical
Implements the suggested keyboard functionality by attaching jQuery
.on
event handlers to listen forArrowUp, ArrowDown, Escape, Tab, and Shift + Tab
keycodes.tabindex
has been attached to eachli
element to allow users to navigate the search bar results with their keyboard.Testing
Go to
localhost:8080
and use a search term that returns at least 3 titles.The expected behaviors are:
Form input <ArrowUp/ArrowDown> - Goes to the first or last item in the results list
Form input <Escape> - Removes focus from the search bar input, clears search results
Result li element <ArrowUp/Shift + Tab> - Navigates to the previous list sibling if exists, otherwise will focus on the Form input
Result li element <ArrowDown/Tab> - Navigates to the next list sibling if exists, otherwise will loop focus back to the Form input
Result li element - Redirects the user to the title
Result li element - Blurs focus from
input[type="text"]
and clears the results list.Search facet <Shift + Tab> - Clears the results list since focus is no longer within the relevant search bar component
Screenshot
This video demos all but the Result li element keyboard behaviors.
https://github.com/user-attachments/assets/aa4c8261-b888-43b6-806a-5b4e28ff7424
Stakeholders
@RayBB