it('should remove the new option after closing on blur', () => { createControl(); typeSearchText('9'); TestUtils.Simulate.blur(filterInputNode); expect(creatableInstance.inputValue, 'to equal', ''); });
describe('with onBlurResetsInput=true', () => { beforeEach(() => { instance = createControl({ options: defaultOptions, onBlurResetsInput: true }); typeSearchText('test'); }); it('should clear the search input after calling onBlur', () => { TestUtils.Simulate.blur(searchInputNode); expect(ReactDOM.findDOMNode(instance).querySelector('input').value, 'to equal', ''); }); });
describe('.focus()', () => { beforeEach(() => { createControl({}); TestUtils.Simulate.blur(filterInputNode); }); it('focuses the search input', () => { expect(filterInputNode, 'not to equal', document.activeElement); creatableInstance.focus(); expect(filterInputNode, 'to equal', document.activeElement); }); });
describe('outside event', () => { beforeEach(() => { instance = createControl({ options: defaultOptions }); TestUtils.Simulate.mouseDown(getSelectControl(instance), { button: 0 }); expect(ReactDOM.findDOMNode(instance), 'queried for', '.Select-option', 'to have length', 4); }); it('click closes the menu', () => { TestUtils.Simulate.blur(searchInputNode); expect(ReactDOM.findDOMNode(instance), 'to contain no elements matching', '.Select-option'); }); it('touch closes the menu', () => { const evt = document.createEvent('Event'); evt.initEvent('touchstart', true, true); document.querySelector('body').dispatchEvent(evt); expect(ReactDOM.findDOMNode(instance), 'to contain no elements matching', '.Select-option'); }); });
}); TestUtils.Simulate.blur(searchInputNode); expect(onBlur, 'was called once'); });
beforeEach(() => { createControl({}); TestUtils.Simulate.blur(filterInputNode); });
describe('.focus()', () => { beforeEach(() => { createControl({}); TestUtils.Simulate.blur(filterInputNode); }); it('focuses the search input', () => { expect(filterInputNode, 'not to equal', document.activeElement); asyncInstance.focus(); expect(filterInputNode, 'to equal', document.activeElement); }); });
describe('with onBlurResetsInput=false', () => { beforeEach(() => { instance = createControl({ options: defaultOptions, onBlurResetsInput: false }); typeSearchText('test'); }); it('shouldn\'t clear the search input after calling onBlur', () => { TestUtils.Simulate.blur(searchInputNode); expect(ReactDOM.findDOMNode(instance).querySelector('input').value, 'to equal', 'test'); }); });