Skip to content
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

Conversation

scissorsneedfoodtoo
Copy link
Contributor

@scissorsneedfoodtoo scissorsneedfoodtoo commented Sep 12, 2019

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

@scissorsneedfoodtoo scissorsneedfoodtoo requested a review from a team September 12, 2019 08:35
@gitpod-io
Copy link

gitpod-io bot commented Sep 12, 2019

@raisedadead raisedadead added platform: learn UI side of the client application that needs familiarity with React, Gatsby etc. release: next/beta labels Sep 12, 2019
@scissorsneedfoodtoo
Copy link
Contributor Author

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.

@scissorsneedfoodtoo scissorsneedfoodtoo force-pushed the feat/more-accessible-search-bar branch 3 times, most recently from 0dcfc35 to 823d25e Compare September 13, 2019 12:35
Copy link
Member

@raisedadead raisedadead left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @scissorsneedfoodtoo

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?

@scissorsneedfoodtoo
Copy link
Contributor Author

@raisedadead, yes, that sounds good to me. Right now focusing on the search bar is handled by Algolia's <SearchBox> component, but everything else is a bit hacked together. I'll look into a library to handle the up and down arrows and possibly focusing the search bar.

@scissorsneedfoodtoo scissorsneedfoodtoo added status: PR in works Work in Progress (WIP) Issues. and removed status: PR in works Work in Progress (WIP) Issues. labels Sep 17, 2019
@raisedadead raisedadead added this to In progress in Next Sep 19, 2019
@scissorsneedfoodtoo scissorsneedfoodtoo added the status: waiting review To be applied to PR's that are ready for QA, especially when additional review is pending. label Sep 20, 2019
@raisedadead raisedadead requested a review from a team September 24, 2019 16:56
@ojeytonwilliams ojeytonwilliams self-assigned this Sep 26, 2019
Copy link
Contributor

@ojeytonwilliams ojeytonwilliams left a 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:
SearchError
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.

client/src/components/search/searchBar/SearchBar.js Outdated Show resolved Hide resolved
client/src/components/search/searchBar/SearchBar.js Outdated Show resolved Hide resolved
client/src/components/layouts/global.css Outdated Show resolved Hide resolved
client/src/components/search/searchBar/SearchHits.js Outdated Show resolved Hide resolved
@scissorsneedfoodtoo
Copy link
Contributor Author

@ojeytonwilliams, thank you for your detailed review. I'll go through and implement your suggestions as soon as possible.

@scissorsneedfoodtoo scissorsneedfoodtoo added the status: PR in works Work in Progress (WIP) Issues. label Sep 27, 2019
@scissorsneedfoodtoo scissorsneedfoodtoo force-pushed the feat/more-accessible-search-bar branch 2 times, most recently from ff1100a to cd2ae80 Compare September 27, 2019 12:06
Copy link
Contributor

@ojeytonwilliams ojeytonwilliams left a 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.

client/src/components/search/searchBar/SearchBar.js Outdated Show resolved Hide resolved
client/src/components/search/searchBar/SearchBar.js Outdated Show resolved Hide resolved
client/src/components/search/searchBar/SearchHits.js Outdated Show resolved Hide resolved
client/src/components/search/searchBar/SearchHits.js Outdated Show resolved Hide resolved
client/src/components/search/searchBar/SearchHits.js Outdated Show resolved Hide resolved
client/src/components/search/searchBar/SearchSuggestion.js Outdated Show resolved Hide resolved
client/src/components/search/searchBar/searchbar.css Outdated Show resolved Hide resolved
@scissorsneedfoodtoo
Copy link
Contributor Author

@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!

@ojeytonwilliams
Copy link
Contributor

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.

@scissorsneedfoodtoo
Copy link
Contributor Author

@ojeytonwilliams, that sounds great. Any help with refactoring this to be more standard React would be greatly appreciated.

package.json Outdated Show resolved Hide resolved
Copy link
Member

@raisedadead raisedadead left a 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

@raisedadead raisedadead changed the title feat: More accessible search bar feat: accessible search bar Sep 30, 2019
@scissorsneedfoodtoo scissorsneedfoodtoo force-pushed the feat/more-accessible-search-bar branch 2 times, most recently from d7cf2ed to cf86ef5 Compare October 1, 2019 04:56
@scissorsneedfoodtoo
Copy link
Contributor Author

Went back to the earlier implementation of passing hits from SearchHits.js to SearchBar.js so it's not querying the DOM from lifecycle methods. Shouldn't throw errors now that the handleHits function is inside the useEffect hook.

@raisedadead raisedadead removed the status: waiting review To be applied to PR's that are ready for QA, especially when additional review is pending. label Oct 1, 2019
@scissorsneedfoodtoo scissorsneedfoodtoo added status: waiting review To be applied to PR's that are ready for QA, especially when additional review is pending. and removed status: PR in works Work in Progress (WIP) Issues. labels Oct 1, 2019
Copy link
Contributor

@ojeytonwilliams ojeytonwilliams left a 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?

client/src/components/search/searchBar/SearchBar.js Outdated Show resolved Hide resolved
client/src/components/search/searchBar/SearchBar.js Outdated Show resolved Hide resolved
client/src/components/search/searchBar/SearchBar.js Outdated Show resolved Hide resolved
client/src/components/search/searchBar/SearchBar.js Outdated Show resolved Hide resolved
client/src/components/search/searchBar/SearchBar.js Outdated Show resolved Hide resolved
client/src/components/search/searchBar/SearchBar.js Outdated Show resolved Hide resolved
client/src/components/search/searchBar/SearchBar.js Outdated Show resolved Hide resolved
Copy link
Contributor

@ojeytonwilliams ojeytonwilliams left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@ojeytonwilliams
Copy link
Contributor

@scissorsneedfoodtoo it's looking great, nice work!

@raisedadead I'm happy for this to be merged, if you are.

@raisedadead
Copy link
Member

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.

@raisedadead raisedadead merged commit 07c552b into freeCodeCamp:master Oct 1, 2019
Next automation moved this from In progress to Done Oct 1, 2019
@scissorsneedfoodtoo
Copy link
Contributor Author

scissorsneedfoodtoo commented Oct 1, 2019

@ojeytonwilliams, thank you for reviewing this! I learned a lot along the way.

@raisedadead, I'll start writing tests for the search bar ASAP.

@scissorsneedfoodtoo scissorsneedfoodtoo deleted the feat/more-accessible-search-bar branch October 1, 2019 23:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform: learn UI side of the client application that needs familiarity with React, Gatsby etc. status: waiting review To be applied to PR's that are ready for QA, especially when additional review is pending.
Projects
No open projects
Next
  
Done
Development

Successfully merging this pull request may close these issues.

Make new search bar more accessible
5 participants