From 3ec7527ba3bec80b88ca8fa1575f858eefe4a0aa Mon Sep 17 00:00:00 2001 From: Byron Anderson Date: Thu, 3 Mar 2016 15:10:08 -0700 Subject: [PATCH] Add option to allow tab not to be considered a select action --- src/Select.js | 4 +++- test/Select-test.js | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/Select.js b/src/Select.js index 94a47a0302..5c2ffb4e64 100644 --- a/src/Select.js +++ b/src/Select.js @@ -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 @@ -112,6 +113,7 @@ const Select = React.createClass({ scrollMenuIntoView: true, searchable: true, simpleValue: false, + tabSelectsValue: true, valueComponent: Value, valueKey: 'value', }; @@ -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(); diff --git a/test/Select-test.js b/test/Select-test.js index 4aa88ca67f..0f9933693e 100644 --- a/test/Select-test.js +++ b/test/Select-test.js @@ -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;