diff --git a/src/modules/Dropdown/Dropdown.js b/src/modules/Dropdown/Dropdown.js index d2116e0942..0c4c243631 100644 --- a/src/modules/Dropdown/Dropdown.js +++ b/src/modules/Dropdown/Dropdown.js @@ -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 diff --git a/test/specs/modules/Dropdown/Dropdown-test.js b/test/specs/modules/Dropdown/Dropdown-test.js index b589a3df79..83e6db42e4 100644 --- a/test/specs/modules/Dropdown/Dropdown-test.js +++ b/test/specs/modules/Dropdown/Dropdown-test.js @@ -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() + + const instance = wrapper.instance() + sandbox.spy(instance.ref, 'blur') + + dropdownMenuIsOpen() + wrapper.simulate('click') + dropdownMenuIsOpen() + }) + it('opens on focus', () => { wrapperMount()