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

Disable forced focus after remove via prop #1354

Closed
wants to merge 4 commits into from
Closed
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ function onInputKeyDown(event) {
autosize | bool | true | If enabled, the input will expand as the length of its value increases
backspaceRemoves | bool | true | whether pressing backspace removes the last item when there is no input value
backspaceToRemoveMessage | string | 'Press backspace to remove {last label}' | prompt shown in input when at least one option in a multiselect is shown, set to '' to clear
blurOnRemove | bool | true | whether the control should lose focus after removing a value
cache | bool | true | enables the options cache for `asyncOptions` (default: `true`)
className | string | undefined | className for the outer element
clearable | bool | true | should it be possible to reset value
Expand Down
7 changes: 6 additions & 1 deletion src/Select.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const Select = React.createClass({
autosize: React.PropTypes.bool, // whether to enable autosizing or not
backspaceRemoves: React.PropTypes.bool, // whether backspace removes an item if there is no text input
backspaceToRemoveMessage: React.PropTypes.string, // Message to use for screenreaders to press backspace to remove the current item - {label} is replaced with the item label
blurOnRemove: React.PropTypes.bool, // whether the control should lose focus after removing a value
className: React.PropTypes.string, // className for the outer element
clearAllText: stringOrNode, // title for the "clear" control when multi: true
clearValueText: stringOrNode, // title for the "clear" control
Expand Down Expand Up @@ -642,7 +643,11 @@ const Select = React.createClass({
removeValue (value) {
var valueArray = this.getValueArray(this.props.value);
this.setValue(valueArray.filter(i => i !== value));
this.focus();
if(this.props.blurOnRemove) {
this.blurInput();
}else {
this.focus();
}
},

clearValue (event) {
Expand Down
20 changes: 20 additions & 0 deletions test/Select-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1826,6 +1826,26 @@ describe('Select', () => {
</span>);
});

it('focuses the control after removing a value', () => {

setValueProp(['four','three']);
onChange.reset(); // Ignore previous onChange calls
pressDelete();
expect(onChange, 'was called with', [{ label: 'Four', value: 'four' }]);
});

it('blurs the control after removing a value when blurOnRemove=true', () => {

// Enable blurOnRemove
wrapper.setPropsForChild({
blurOnRemove: true,
value: ['four', 'three']
});
onChange.reset(); // Ignore previous onChange calls
pressDelete();
expect(onChange, 'was called with', [{ label: 'Four', value: 'four' }]);
});

it('removes an item when clicking on the X', () => {

setValueProp(['four', 'three', 'two']);
Expand Down