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

Add optional selectOnTab prop #505

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Conversation

Tarpsvo
Copy link

@Tarpsvo Tarpsvo commented Feb 8, 2018

Added optional selectOnTab property that makes the tab key act identical to the enter key. This feature has been requested multiple times before (as seen in #164, #163, #34, #332 etc). This pull requests adds the named property as well as multiple tests.

@najisawas
Copy link

najisawas commented Apr 28, 2018

Hi. I'd like to review and help you land this. I was going to work on it until I noticed this diff :)

@@ -581,7 +583,12 @@ export default class Autosuggest extends Component {

break;

// Tab (must fall through to enter when conditions apply!)
case 9:
if (!this.props.selectOnTab) break;

Choose a reason for hiding this comment

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

IMO, I believe Tabbing is heavily used as an "autocomplete" feature. That being said I feel that tabbing should automatically select the first item in the suggestions list if none are highlighted. "Enter", however should continue to remain dependent on a highlighted suggestion

Choose a reason for hiding this comment

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

I don't. I would suggest that using the up/down arrow key to select then tab selects the item.

Choose a reason for hiding this comment

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

Hello guys,
I will migrate to this component at the moment, and I've tested the current version with screen readers. The long story made short, the suggestions are not read. I will most likely prepare a PR to improve it in that sense.

As of the keyboard requirements for accessibility, the UX rules normally are:
Keyboard Interaction

  • UP and DOWN: Cycles through auto-suggestions and input field.
  • ESC: Close the list with options
  • ENTER: Select the currently focused auto-suggestion and close the menu.
  • TAB: Select the currently focused auto-suggestion, close the menu, and move focus to the next focusable element.

I hope this helps to figure out the expected behaviour

<a name="selectOnTabProp"></a>
#### selectOnTab (optional)

Makes the tab key act identical to the enter key, allowing it to select the highlighted suggestion.

Choose a reason for hiding this comment

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

See other comment

@dangell7
Copy link

Is this still not resolved? Just FYI, outside of the coding world, EVERYONE uses tab before they use ENTER. Most data entry is done very fast and the need for tabbing is far more required than the need for enter.

@Tarpsvo
Copy link
Author

Tarpsvo commented Apr 19, 2019

Not resolved indeed. I've just been using my own fork in my projects. Works perfectly.

@aberezkin
Copy link
Collaborator

Hi! Thank you for the contribution.

You mentioned a couple of old PRs that were closed because it's not quite obvious what should be accessible behavior after pressing tab key. As @moroshko pointed out the default behavior in web is to focus next focusable element which is the way it works now in react-autosuggest. Also there are some interfaces that implement behavior equivalent to pressing down key. Chrome search bar for example.

So even if we make it optional it's not quite obvious that it should work like enter. So what is your motivation to make it behave like enter?

@Tarpsvo
Copy link
Author

Tarpsvo commented Mar 30, 2020

It just makes sense to me and was requested by the client and designer in the project I used react-autosuggest in. Judging by the popularity of this PR, it makes sense to others as well.

@aberezkin
Copy link
Collaborator

aberezkin commented Mar 30, 2020

What if someone’s client wants it to behave like down key?

I think we should make the behavior customizable. Not sure how to implement it properly for now. But I think we should look in this direction and research how it’s implemented in other similar libraries.

componentWillReceiveProps -> UNSAFE_componentWillReceiveProps
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants