Skip to content
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
6 changes: 5 additions & 1 deletion src/Select.js
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,11 @@ class Select extends React.Component {
}

renderClear () {
if (!this.props.clearable || this.props.value === undefined || this.props.value === null || this.props.value === '' || this.props.multi && !this.props.value.length || this.props.disabled || this.props.isLoading) return;
const valueArray = this.getValueArray(this.props.value);
if (!this.props.clearable
|| !valueArray.length
|| this.props.disabled
|| this.props.isLoading) return;
const clear = this.props.clearRenderer();

return (
Expand Down
23 changes: 23 additions & 0 deletions test/Select-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1938,6 +1938,17 @@ describe('Select', () => {
TestUtils.Simulate.mouseDown(ReactDOM.findDOMNode(instance).querySelector('.Select-clear'), { button: 0 });
expect(onChange, 'was called with', []);
});
describe('if supplied with an invalid starting value', () => {
it('should not render the clear componnet', () => {
wrapper = createControlWithWrapper({
options: options,
value: 'nonsense, someothernonsense',
multi: true,
clearable: true,
});
expect(ReactDOM.findDOMNode(instance), 'to contain no elements matching', '.Select-clear');
});
});
});

describe('with multi=true and searchable=false', () => {
Expand Down Expand Up @@ -2069,6 +2080,16 @@ describe('Select', () => {
'to have items satisfying', 'to have text', 'Three');

});
describe('if supplied with an invalid starting value', () => {
it('should not render the clear componnet', () => {
wrapper = createControlWithWrapper({
options: defaultOptions,
value: 'nonsense',
clearable: true,
});
expect(ReactDOM.findDOMNode(instance), 'to contain no elements matching', '.Select-clear');
});
});

describe('on pressing escape', () => {

Expand Down Expand Up @@ -4070,4 +4091,6 @@ describe('Select', () => {
});
});
});


});