Skip to content
This repository was archived by the owner on Jul 19, 2019. It is now read-only.

[added] Allow Tab to select option #186

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

Conversation

Daniel15
Copy link
Member

Adds the ability to press Tab to select the currently highlighted option. This is consistent with most other autocompletion components (see https://jedwatson.github.io/react-select/, http://react-autosuggest.js.org/, https://harvesthq.github.io/chosen/, https://jqueryui.com/autocomplete/, http://easyautocomplete.com/, etc). I've added a prop to enable this, and have enabled it by default. This is mainly so it can be disabled just in case there's any issues.

Also adds a new selectionMethod argument to onSelect that specifies the method used to select the option. This will be one of click (if the item was selected with the mouse), Enter, or Tab. This allows the user to handle tab differently to enter.

Closes #182

@@ -10,6 +10,7 @@ let Autocomplete = React.createClass({
value: React.PropTypes.any,
onChange: React.PropTypes.func,
onSelect: React.PropTypes.func,
selectOnTab: React.PropTypes.bool.isRequired,
Copy link
Member Author

Choose a reason for hiding this comment

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

Best practice is to mark props as isRequired if they have a default, as they'll never not be set.

Copy link

Choose a reason for hiding this comment

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

Is this backwards compatible?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, as it defaults to false on line 42.

@@ -164,42 +166,56 @@ let Autocomplete = React.createClass({
},

Enter (event) {
if (this.state.isOpen === false) {
Copy link
Member Author

Choose a reason for hiding this comment

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

This code was moved to a new method handleKeyboardSelection below.

@oxynad
Copy link

oxynad commented Mar 14, 2017

When will this be added to the package?

@dzenzes
Copy link

dzenzes commented Mar 22, 2017

Any updates on this?

@eivindw
Copy link

eivindw commented Mar 30, 2017

I'd love to have this added :)

@stevensona
Copy link

stevensona commented Aug 31, 2017

@CMTegner @Daniel15 Can't wait to get my hands on this feature. 😏

@Daniel15
Copy link
Member Author

Daniel15 commented Aug 31, 2017

If you want to get this before it's merged, you can use my fork:

"react-autocomplete": "Daniel15/react-autocomplete#fb812e2dd01b7b30be4da6380912cf5ffa24a9f8",

I've been using this on a live site since November 2016 and haven't had any issues with it.

@CMTegner Any chance of getting this in? I'm happy to rebase it.

@mellis481
Copy link

This, what I would call, vital piece of functionality needs to be merged. This PR is over 2 years old. Is this library in maintenance mode??? I hope not with 40k+ downloads a week.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants