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

[MenuList] Add text keyboard focus navigation #15495

Merged
merged 7 commits into from
Apr 27, 2019

Conversation

ryancogswell
Copy link
Contributor

@ryancogswell ryancogswell commented Apr 26, 2019

Closes #8191
Dependent on #15484 before it will work properly.

There are two aspects in my implementation that I consider optional that could be removed if they aren't considered worth the additional code:

  1. The previousKeyMatched portion of the text criteria. The user-observable behavior is unchanged if this is removed. The purpose is to avoid cycling through all the menu items checking for a match when we already know a match isn't possible because the previously accumulated keys didn't match anything and now the user is adding another key to that unmatched sequence.
  2. The use of innerText when available (otherwise falls back to textContent). If innerText and textContent are different, innerText would be the better one to use; however innerText isn't supported by jsdom (thus the fallback to textContent). In practice, I wouldn't expect these to hardly ever be different in real-world menu item scenarios, so it would likely be fine to just always use textContent.

Neither of these two aspects adds much code, but they only add a very small amount of (mostly hypothetical) value.

I based the behavior on what I observed in Chrome on Windows for native select elements (a state list is a convenient case to test out the browser behavior). The 500ms threshold for reset of the key sequence is based on the 0.x implementation mentioned in @kgregory's comment and seems to at least be close to what browsers use, but I didn't go looking for a more official source for what the timing of the reset should be.

The gist of the behavior is:

  • Always search forward from the current focus point for text matches (wrapping if wrapping is not disabled)
  • A repeated character at the beginning of the key sequence (prior to a reset) always advances to the next element starting with that character regardless of whether there is a match for the full sequence (e.g. if you have "Arizona", "cat", "aaaah", "dog", and "Argentina", typing "aaaa" will cycle through "Arizona", "aaaah", "Argentina", and back to "Arizona" rather than stopping on "aaaah" which matches the full sequence)
  • Once a second distinct character exists within the sequence, then matching occurs on the full sequence
  • A pause of 500ms or more causes a reset in the key sequence used for matching

@mui-pr-bot
Copy link

mui-pr-bot commented Apr 26, 2019

@material-ui/core: parsed: +0.22% , gzip: +0.33%

Details of bundle changes.

Comparing: d1df9a8...bb2b2ba

bundle parsed diff gzip diff prev parsed current parsed prev gzip current gzip
@material-ui/core +0.22% 🔺 +0.33% 🔺 311,185 311,881 84,261 84,540
@material-ui/core/Paper 0.00% 0.00% 67,308 67,308 19,976 19,976
@material-ui/core/Paper.esm 0.00% 0.00% 60,669 60,669 18,903 18,903
@material-ui/core/Popper 0.00% 0.00% 31,115 31,115 10,793 10,793
@material-ui/core/Textarea 0.00% 0.00% 5,472 5,472 2,367 2,367
@material-ui/core/TrapFocus 0.00% 0.00% 3,731 3,731 1,565 1,565
@material-ui/core/styles/createMuiTheme 0.00% 0.00% 15,898 15,898 5,770 5,770
@material-ui/core/useMediaQuery 0.00% 0.00% 2,106 2,106 973 973
@material-ui/lab 0.00% 0.00% 140,720 140,720 42,642 42,642
@material-ui/styles 0.00% 0.00% 50,833 50,833 15,019 15,019
@material-ui/system 0.00% 0.00% 11,765 11,765 3,922 3,922
Button 0.00% 0.00% 85,622 85,622 25,618 25,618
Modal 0.00% 0.00% 79,337 79,337 23,972 23,972
colorManipulator 0.00% 0.00% 3,904 3,904 1,543 1,543
docs.landing 0.00% 0.00% 51,154 51,154 11,250 11,250
docs.main +0.11% 🔺 +0.14% 🔺 648,182 648,877 202,198 202,475
packages/material-ui/build/umd/material-ui.production.min.js +0.24% 🔺 +0.33% 🔺 292,227 292,921 82,171 82,446

Generated by 🚫 dangerJS against bb2b2ba

Copy link
Member

@oliviertassinari oliviertassinari left a comment

Choose a reason for hiding this comment

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

All good for me 😍

@oliviertassinari
Copy link
Member

oliviertassinari commented Apr 27, 2019

I'm merging, I would suspect Sebastian wants to review it too. Now, I believe it's already a great step forward. I'm confident any reported problem will be quickly solved in a continuing pull request. I think that we can focus our energy on #15484.

@ryancogswell It took us months, but we are almost at the end of the tunnel! The team is proud of your contributions on Material-UI.

@oliviertassinari oliviertassinari merged commit c143ac4 into mui:next Apr 27, 2019
@ryancogswell
Copy link
Contributor Author

The team is proud of your contributions on Material-UI.

@oliviertassinari Thanks! It’s been a very good experience. You’re very welcoming and encouraging toward contributors. I’ve learned a lot in the process — about React (especially the full details of refs), Material-UI, and JavaScript testing tools (I’m primarily a Java developer).

Our company’s application has a lot of great functionality, but we were losing sales due to “an outdated UI”. We chose Material-UI to help turn that around, and we have received really positive feedback from clients on the parts of our app that have been updated so far.

@ryancogswell ryancogswell deleted the menulist-textfocusnav branch May 3, 2019 22:48
ypahalajani pushed a commit to ypahalajani/material-ui that referenced this pull request Oct 1, 2021
…8704)

- Initial values of `repeating` and `previousKeyMatched` should be `false` instead of `true` because there are no comparisons initially.
- Also, when `handleKeyDown` is called for the first time, there is a comparison between `currTime` (which is always a number) and `criteria.lastTime` (which is initially `null`) causing the code inside `if` statement to exexute which might have been anticipated by the author in this [PR](mui#15495).
ypahalajani pushed a commit to ypahalajani/material-ui that referenced this pull request Oct 1, 2021
…8704)

- Initial values of `repeating` and `previousKeyMatched` should be `false` instead of `true` because there are no comparisons initially.
- Also, when `handleKeyDown` is called for the first time, there is a comparison between `currTime` (which is always a number) and `criteria.lastTime` (which is initially `null`) causing the code inside `if` statement to execute which might have not been anticipated by the author in this [PR](mui#15495).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Select menu does not fully implement keyboard controls
3 participants