Skip to content

Commit

Permalink
fix(Dropdown): override onChange in DropdownSearchInput (#3123)
Browse files Browse the repository at this point in the history
fix(Dropdown): override onChange in DropdownSearchInput
  • Loading branch information
layershifter authored Sep 4, 2018
1 parent 1ae2781 commit ac7cd79
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/modules/Dropdown/Dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -1066,6 +1066,13 @@ export default class Dropdown extends Component {
return _.isNil(tabIndex) ? 0 : tabIndex
}

handleSearchInputOverrides = predefinedProps => ({
onChange: (e, inputProps) => {
_.invoke(predefinedProps, 'onChange', e, inputProps)
this.handleSearchChange(e, inputProps)
},
})

// ----------------------------------------
// Behavior
// ----------------------------------------
Expand Down Expand Up @@ -1195,11 +1202,11 @@ export default class Dropdown extends Component {
return DropdownSearchInput.create(searchInput, {
defaultProps: {
inputRef: this.handleSearchRef,
onChange: this.handleSearchChange,
style: { width: this.computeSearchInputWidth() },
tabIndex: this.computeSearchInputTabIndex(),
value: searchQuery,
},
overrideProps: this.handleSearchInputOverrides,
})
}

Expand Down
27 changes: 27 additions & 0 deletions test/specs/modules/Dropdown/Dropdown-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2029,6 +2029,33 @@ describe('Dropdown', () => {
})
})

describe('searchInput', () => {
it('overrides onChange handler', () => {
const onInputChange = sandbox.spy()
const onSearchChange = sandbox.spy()

wrapperShallow(
<Dropdown
onSearchChange={onSearchChange}
options={options}
search
searchInput={{ onChange: onInputChange }}
/>,
)

wrapper
.find(DropdownSearchInput)
.shallow()
.simulate('change', {
stopPropagation: _.noop,
target: { value: faker.hacker.noun() },
})

onInputChange.should.have.been.calledOnce()
onSearchChange.should.have.been.calledOnce()
})
})

describe('no results message', () => {
it('is shown when a search yields no results', () => {
const search = wrapperMount(<Dropdown options={options} selection search />).find(
Expand Down

0 comments on commit ac7cd79

Please sign in to comment.