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

v2 Menus: Implement typeahead focus #1834

Merged
merged 13 commits into from
Feb 21, 2022
Merged

Conversation

siddharthkp
Copy link
Member

@siddharthkp siddharthkp commented Feb 3, 2022



Looking for feedback on:

  1. Is this correct behavior - Typeahead does not activate automatically when you open with mouse click. But, if you press the arrow keys after opening with mouse, typeahead becomes activated.
  2. Is the typeahead timeout 1000ms appropriate? The timeout is necessary so that you can type a longer string to match options. At the same, if you have found the matching element quickly before the timeout runs wouldn't select the option, making it feel unresponsive. See storybook setup to play around with it.

Screenshots:

Before:
Pressing alphabet keys does nothing

After:

Pressing alphabet keys changes focus the matching element


100% test coverage yo!

image

@changeset-bot
Copy link

changeset-bot bot commented Feb 3, 2022

🦋 Changeset detected

Latest commit: 4ff95ac

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@primer/react Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions
Copy link
Contributor

github-actions bot commented Feb 3, 2022

size-limit report 📦

Path Size
dist/browser.esm.js 62.62 KB (0%)
dist/browser.umd.js 63.01 KB (0%)

@siddharthkp siddharthkp marked this pull request as ready for review February 3, 2022 15:45
@siddharthkp siddharthkp requested a review from a team February 3, 2022 15:45
@siddharthkp siddharthkp changed the title Menu: Implement typeahead Menus: Implement typeahead Feb 3, 2022
@siddharthkp siddharthkp changed the title Menus: Implement typeahead v2 Menus: Implement typeahead Feb 3, 2022
@siddharthkp siddharthkp changed the title v2 Menus: Implement typeahead v2 Menus: Implement typeahead focus Feb 3, 2022
const {containerRef, openWithFocus} = useMenuInitialFocus(open, onOpen)
const containerRef = React.createRef<HTMLDivElement>()
const {openWithFocus} = useMenuInitialFocus(open, onOpen, containerRef)
useTypeaheadFocus(open, containerRef)
Copy link
Member Author

Choose a reason for hiding this comment

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

Note 1: Changed both of these hooks to accept a ref if it's passed (or create a new one if it's not passed)

Note 2: Did not combine these into one hook called useMenuFocus, we might want to re-use typeahead logic in NavigationTree 🤷

@siddharthkp siddharthkp requested review from alliethu and removed request for alliethu February 4, 2022 12:32
@siddharthkp siddharthkp added this to the FY22 - Q3 milestone Feb 4, 2022
@colebemis
Copy link
Contributor

Is this correct behavior - Typeahead does not activate automatically when you open with mouse click. But, if you press the arrow keys after opening with mouse, typeahead becomes activated.

I'm also curious about this ☝️ cc @alliethu

It seems a little strange that typeahead doesn't work when activated with a mouse, but I don't have a strong opinion.

Copy link
Contributor

@colebemis colebemis left a comment

Choose a reason for hiding this comment

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

Nice work @siddharthkp! Looks good to me 👍 I would like an answer to #1834 (comment) from someone with more accessibility experience before we merge this, but feel free to merge if this is urgent.

Side note, this would be fun to implement as a state machine!

@siddharthkp
Copy link
Member Author

This is an interesting update which would change the behavior here as well :) primer/behaviors#52

Will wait for behaviors release before moving forward on this PR

@siddharthkp
Copy link
Member Author

siddharthkp commented Feb 21, 2022

Update: After #1877 (which is also merged in this branch), typeahead is active even when you open the menu with mouse click ✌️

@siddharthkp siddharthkp removed the request for review from alliethu February 21, 2022 16:02
@siddharthkp siddharthkp enabled auto-merge (squash) February 21, 2022 16:10
@siddharthkp siddharthkp merged commit 2abd7b7 into main Feb 21, 2022
@siddharthkp siddharthkp deleted the siddharth/menu-focus-first-letter branch February 21, 2022 16:15
@primer-css primer-css mentioned this pull request Feb 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants