Skip to content

Commit

Permalink
Merge pull request #133 from JeffreyMFarley/issue-132
Browse files Browse the repository at this point in the history
TAB key will retain its primary purpose
  • Loading branch information
JeffreyMFarley authored Jun 13, 2018
2 parents a027046 + 2c0b356 commit e9c1664
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 24 deletions.
12 changes: 0 additions & 12 deletions src/Typeahead/__tests__/Typeahead.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -323,18 +323,6 @@ describe('component::Typeahead', () => {
expect(target.state('selectedIndex')).toEqual(-1)
})

it('uses the text box value when there are no options', () => {
target.instance().setState({
selectedIndex: -1,
searchResults: []
})
fixture.which = keys.VK_TAB
input.simulate('keydown', fixture)

expect(props.onOptionSelected).toHaveBeenCalledWith('bar')
expect(target.state('phase')).toEqual('CHOSEN')
})

it('uses the text and not the highlighted option', () => {
target.instance().setState({
selectedIndex: 1,
Expand Down
14 changes: 2 additions & 12 deletions src/Typeahead/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export default class Typeahead extends React.Component {
'_renderError', '_renderEmpty', '_renderNoResults', '_renderResults',
'_renderTooManyResults', '_renderWaiting',
'_onBlur', '_onFocus', '_onKeyDown', '_onOptionsError',
'_openChooseIndex', '_openClear', '_openKeyCancel', '_openKeyEnter',
'_openClear', '_openKeyCancel', '_openKeyEnter',
'_selectOption', '_setOptions',
'_valueUpdated'
] )
Expand All @@ -101,7 +101,7 @@ export default class Typeahead extends React.Component {
this.keyMap[keys.VK_DOWN] = this._openNav.bind( this, 1 )
this.keyMap[keys.VK_ENTER] = this._openKeyEnter
this.keyMap[keys.VK_RETURN] = this._openKeyEnter
this.keyMap[keys.VK_TAB] = this._openChooseIndex
this.keyMap[keys.VK_TAB] = this._closedChooseIndex

// In open mode, just hide the fact that no typeahead results match
this.renderMap[NO_RESULTS] = this._renderEmpty
Expand Down Expand Up @@ -282,16 +282,6 @@ export default class Typeahead extends React.Component {
}
}

_openChooseIndex( event ) {
if ( this.state.searchResults.length === 0 ) {
event.preventDefault()
this.props.onOptionSelected( this.state.inputValue )
this.setState( { phase: CHOSEN } )
} else {
this._closedChooseIndex( event )
}
}

_openClear() {
this.setState( nextStateFromValue( '', this.props ) )
this.props.onOptionSelected( '' )
Expand Down

0 comments on commit e9c1664

Please sign in to comment.