Skip to content

Commit

Permalink
Add option to allow tab not to be considered a select action
Browse files Browse the repository at this point in the history
  • Loading branch information
byronanderson committed Mar 3, 2016
1 parent de462f5 commit 3ec7527
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 @@ -74,6 +74,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 @@ -112,6 +113,7 @@ const Select = React.createClass({
scrollMenuIntoView: true,
searchable: true,
simpleValue: false,
tabSelectsValue: true,
valueComponent: Value,
valueKey: 'value',
};
Expand Down Expand Up @@ -334,7 +336,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 @@ -2696,6 +2696,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 3ec7527

Please sign in to comment.