Skip to content

Commit

Permalink
Merge pull request #2163 from JedWatson/fix/#2156
Browse files Browse the repository at this point in the history
removed the functionality for searchable select, added tests
  • Loading branch information
JedWatson committed Nov 23, 2017
2 parents e7a77da + 63d2e18 commit fedfc3b
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 33 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
80 changes: 49 additions & 31 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 @@ -4167,34 +4171,6 @@ describe('Select', () => {
});

});

it('updates the active descendant after a selection using space bar', () => {

return expect(wrapper,
'with event', 'keyDown', ARROW_DOWN, 'on', <div className="Select-control" />,
'with event', 'keyDown', KEY_SPACE, 'on', <div className="Select-control" />,
'queried for', <input role="combobox" />)
.then(input => {

// [ 'three', 'two', 'one' ] is now selected,
// therefore in-focus should be 'four'

const activeId = input.attributes['aria-activedescendant'].value;
expect(ReactDOM.findDOMNode(instance), 'queried for first', '#' + activeId, 'to have text', 'label four');
});

});

it('expands the drop down when the space bar is pressed', () => {

return expect(wrapper,
'with event', 'keyDown', KEY_SPACE, 'on', <div className="Select-control" />,
'queried for', <input role="combobox" />)
.then(input => {
expect(instance.state.focusedOption, 'to equal', { value: 'one', label: 'label one' });
});

});
});
});

Expand Down Expand Up @@ -4274,6 +4250,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 fedfc3b

Please sign in to comment.