Skip to content

Commit

Permalink
removed the functionality for searchable select, added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gwyneplaine committed Nov 23, 2017
1 parent 8e69bc3 commit 79eefba
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/Select.js
Expand Up @@ -408,9 +408,10 @@ class Select extends React.Component {
}
break;
case 32: // space
if (!this.props.searchable) {
event.preventDefault();
if (this.props.searchable) {
return;
}
event.preventDefault();
if (!this.state.isOpen) {
this.focusNextOption();
return;
Expand Down
52 changes: 49 additions & 3 deletions test/Select-test.js
Expand Up @@ -63,7 +63,7 @@ describe('Select', () => {
return ReactDOM.findDOMNode(instance).querySelector('.Select-control');
};

var enterSingleCharacter = () =>{
var enterSingleCharacter = () => {
TestUtils.Simulate.keyDown(searchInputNode, { keyCode: 65, key: 'a' });
};

Expand Down Expand Up @@ -111,6 +111,10 @@ describe('Select', () => {
TestUtils.Simulate.keyDown(getSelectControl(instance), { keyCode: 36, key: 'Home' });
};

var pressSpaceBar = () => {
TestUtils.Simulate.keyDown(getSelectControl(instance), { keyCode: 32, key: 'Space' });
};

var typeSearchText = (text) => {
TestUtils.Simulate.change(searchInputNode, { target: { value: text } });
};
Expand Down Expand Up @@ -4274,6 +4278,48 @@ describe('Select', () => {
});
});
});


describe('spacebar functionality', () => {
describe('if not searchable', () => {
beforeEach(() => {
instance = createControl({
searchable: false,
simpleValue: true,
options: [
{ value: 'Two', label: 'Two' },
{ value: 'Three', label: 'Three' },
{ value: 'Twenty two', label: 'Twenty two' }
],
});
});
it('selects the focused option', () => {
clickArrowToOpen();
pressSpaceBar();
expect(onChange, 'was called with', 'Two');
});
});
describe('if searchable', () => {
beforeEach(() => {
instance = createControl({
searchable: true,
simpleValue: true,
options: [
{ value: 'Two', label: 'Two' },
{ value: 'Three', label: 'Three' },
{ value: 'Twenty two', label: 'Twenty two' }
],
});
});
it("doesn't select the focused option", () => {
typeSearchText('Twenty two'); // Matches label
pressSpaceBar();
expect(onChange, 'was not called');
// And the menu is still open
expect(ReactDOM.findDOMNode(instance), 'to contain no elements matching', DISPLAYED_SELECTION_SELECTOR);
expect(ReactDOM.findDOMNode(instance), 'queried for' , '.Select-option',
'to satisfy', [
expect.it('to have text', 'Twenty two')
]);
});
});
});
});

0 comments on commit 79eefba

Please sign in to comment.