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: accessible search bar #36784
feat: accessible search bar #36784
Conversation
cb51009
to
393571b
Compare
Thank you for checking this out, @xyozio. I think you caught it while I was making some changes. Had to move some stuff around to add a bit more functionality. Please give it another look if you have a chance. |
0dcfc35
to
823d25e
Compare
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.
Thanks for the PR, Looks good. But, I am wondering if this can quickly become unmanageable. How about we do dedicated handling of the hotkeys and this way we can extend this to other areas of the app such as in curriculum navigation (@ojeytonwilliams is working on some of those).
I found https://github.com/greena13/react-hotkeys to be quite well documented, but there could be other similar libs.
Let me know what you think?
@raisedadead, yes, that sounds good to me. Right now focusing on the search bar is handled by Algolia's |
d7c4edf
to
d8829e5
Compare
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.
I'll probably re-review if I get the time, but I figured a partial review was better than nothing! Anyway:
I can't put the second half of the suggestion in, sadly, but I think
// Allow react-hotkeys to work on the searchbar
configure({ ignoreTags: ['select', 'textarea'] });
Should appear just after the imports in SearchBar
, since it only needs to happen once.
Also, I noticed:
when, after reloading the page, you start typing in the text box. I think SearchHits
is the culprit, as it calls handleHits
which sets state.
@ojeytonwilliams, thank you for your detailed review. I'll go through and implement your suggestions as soon as possible. |
ff1100a
to
cd2ae80
Compare
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.
Thanks for implementing those suggestions @scissorsneedfoodtoo! After another read through, I have a few more ideas. Let me know what you think, particularly if I'm being overly picky.
…of with the keyboard. Moved all logic for number of hits to WithInstantSearch.js
…o change the selected hit. Reworked a bit of the global CSS so mouse hovers don't cause multiple highlights in the dropdown
cd2ae80
to
cd80979
Compare
@ojeytonwilliams, not overly picky at all. I don't have a whole lot of experience with React, so I appreciate you and @RandellDawson going through this. I'll take all the help and suggestions I can get! |
Okay, cool, I'm glad it's helpful! I have one general observation, though I don't think it should happen in this PR. It looks like there's quite a lot of direct manipulation of the DOM (assigning ids via lifecycle methods, querying for elements by class and so on). It might be a little easier to maintain if it's refactored into a more standard React style. A custom component with the id as an attribute for the former and passing around the elements as props for the latter . That sort of thing. As I said, I don't want to delay this PR, but I'd be happy to help with the refactor after it's landed. |
cd80979
to
9c3b842
Compare
@ojeytonwilliams, that sounds great. Any help with refactoring this to be more standard React would be greatly appreciated. |
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.
Remove unwanted changes to lock files
9c3b842
to
a7f34d6
Compare
d7cf2ed
to
cf86ef5
Compare
Went back to the earlier implementation of passing hits from |
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.
It's looking good now. The only thing that stuck out was that hitsLength
doesn't seem to be necessary. Can we just use hits.length
instead?
cf86ef5
to
1f3af10
Compare
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 👍
@scissorsneedfoodtoo it's looking great, nice work! @raisedadead I'm happy for this to be merged, if you are. |
Code looks good to me. We could use some tests, I will go ahead and merge this first and @scissorsneedfoodtoo you could add some tests. |
@ojeytonwilliams, thank you for reviewing this! I learned a lot along the way. @raisedadead, I'll start writing tests for the search bar ASAP. |
You can now focus on the search bar with 's' or '/', and use the up and down arrow keys to scroll through the hits. This also brings back the magnifying glass icon that, when clicked, either goes to the search page of the highlighted hit.
Closes #36693