Skip to content

Commit

Permalink
Merge pull request JedWatson#816 from byronanderson/master
Browse files Browse the repository at this point in the history
Add option to allow tab not to be considered a select action
  • Loading branch information
JedWatson committed Apr 6, 2016
2 parents 2877726 + 3ec7527 commit 2fba503
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Select.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const Select = React.createClass({
simpleValue: React.PropTypes.bool, // pass the value to onChange as a simple value (legacy pre 1.0 mode), defaults to false
style: React.PropTypes.object, // optional style to apply to the control
tabIndex: React.PropTypes.string, // optional tab index of the control
tabSelectsValue: React.PropTypes.bool, // whether to treat tabbing out while focused to be value selection
value: React.PropTypes.any, // initial field value
valueComponent: React.PropTypes.func, // value component to render
valueKey: React.PropTypes.string, // path of the label value in option objects
Expand Down Expand Up @@ -120,6 +121,7 @@ const Select = React.createClass({
scrollMenuIntoView: true,
searchable: true,
simpleValue: false,
tabSelectsValue: true,
valueComponent: Value,
valueKey: 'value',
};
Expand Down Expand Up @@ -356,7 +358,7 @@ const Select = React.createClass({
}
return;
case 9: // tab
if (event.shiftKey || !this.state.isOpen) {
if (event.shiftKey || !this.state.isOpen || !this.props.tabSelectsValue) {
return;
}
this.selectFocusedOption();
Expand Down
19 changes: 19 additions & 0 deletions test/Select-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2719,6 +2719,25 @@ describe('Select', () => {
});
});

describe('with tabSelectsValue=false', () => {

beforeEach(() => {

instance = createControl({
options: defaultOptions,
tabSelectsValue: false
});
});

it('should not accept when tab is pressed', () => {

// Search 'h', should only show 'Three'
typeSearchText('h');
pressTabToAccept();
expect(onChange, 'was not called');
});
});

describe('valueRenderer', () => {

var valueRenderer;
Expand Down

0 comments on commit 2fba503

Please sign in to comment.