Skip to content

Commit

Permalink
fix(Dropdown): do not close on click when search is empty (#1490)
Browse files Browse the repository at this point in the history
fix(Dropdown): do not close on click when search is empty
  • Loading branch information
Raj Chourasia authored and levithomason committed Mar 25, 2017
1 parent 9c2a29f commit 014596f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/modules/Dropdown/Dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -995,7 +995,22 @@ export default class Dropdown extends Component {
this.setState({ focus: hasFocus })
}

toggle = (e) => this.state.open ? this.close(e) : this.open(e)
toggle = (e) => {
if (!this.state.open) {
this.open(e)
return
}

const { search } = this.props
const options = this.getMenuOptions()

if (search && _.isEmpty(options)) {
e.preventDefault()
return
}

this.close(e)
}

// ----------------------------------------
// Render
Expand Down
11 changes: 11 additions & 0 deletions test/specs/modules/Dropdown/Dropdown-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,17 @@ describe('Dropdown', () => {
.should.have.been.calledOnce()
})

it('does not close on click when search is true and options are empty', () => {
wrapperMount(<Dropdown options={{}} search selection defaultOpen />)

const instance = wrapper.instance()
sandbox.spy(instance.ref, 'blur')

dropdownMenuIsOpen()
wrapper.simulate('click')
dropdownMenuIsOpen()
})

it('opens on focus', () => {
wrapperMount(<Dropdown options={options} />)

Expand Down

0 comments on commit 014596f

Please sign in to comment.