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

Fix #1394 #1395

Merged
merged 4 commits into from
May 17, 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
3 changes: 2 additions & 1 deletion src/Select.js
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,8 @@ const Select = React.createClass({
},

renderClear () {
if (!this.props.clearable || (!this.props.value || this.props.value === 0) || (this.props.multi && !this.props.value.length) || this.props.disabled || this.props.isLoading) return;

if (!this.props.clearable || this.props.value === undefined || this.props.value === null || this.props.multi && !this.props.value.length || this.props.disabled || this.props.isLoading) return;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One small tweak: You could write this.props.value == null instead of this.props.value === undefined || this.props.value === null.

> undefined == null
true

const clear = this.props.clearRenderer();

return (
Expand Down
10 changes: 10 additions & 0 deletions test/Select-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,11 @@ describe('Select', () => {
expect(onChange, 'was called with', 0);
});

it('displays the X button for 0 value', () => {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for also adding tests for this 😁

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're welcome 😉

wrapper.setPropsForChild({ value: 0 });
expect(ReactDOM.findDOMNode(instance).querySelector('.Select-clear'), 'not to equal', undefined);
});

describe('with multi=true', () => {

beforeEach(() => {
Expand Down Expand Up @@ -962,6 +967,11 @@ describe('Select', () => {
'to have text', 'No');
});

it('displays the X button for false value', () => {
wrapper.setPropsForChild({ value: false });
expect(ReactDOM.findDOMNode(instance).querySelector('.Select-clear'), 'not to equal', undefined);
});

describe('with multi=true', () => {

beforeEach(() => {
Expand Down