Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

removed the functionality for searchable select, added tests #2163

Merged
merged 2 commits into from
Nov 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/Select.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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')
]);
});
});
});
});