Skip to content

Commit

Permalink
FIX (clear search props): add clearOnBlur and clearOnSelect
Browse files Browse the repository at this point in the history
  • Loading branch information
sanusart committed Feb 26, 2019
1 parent 72755df commit edc348e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ and use as:
| values | array | [] | Selected values |
| options | array | [] | Available options, (option with key `disabled: true` will be disabled) |
| keepOpen | bool | false | If true, dropdown will always stay open (good for debugging) |
| autoFocus | bool | false | If true, and `searchable`, dropdown will auto focus |
| clearOnBlur | bool | true | If true, and `searchable`, search value will be cleared on blur |
| clearOnSelect | bool | true | If true, and `searchable`, search value will be cleared upon value select/de-select |
| name | string | null | If set, input type hidden would be added in the component with the value of the `name` prop as name and select's `values` as value |
| dropdownGap | number | 5 | Gap between select element and dropdown |
| multi | bool | false | If true - will act as multi-select, if false - only one option will be selected at the time |
Expand Down
4 changes: 3 additions & 1 deletion docs/src/pages/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ title: 'API'
| values | array | [] | Selected values |
| options | array | [] | Available options, (option with key `disabled: true` will be disabled) |
| keepOpen | bool | false | If true, dropdown will always stay open (good for debugging) |
| autoFocus | bool | false | If true, and `searchable`, dropdown will auto focus |
| autoFocus | bool | false | If true, and `searchable`, dropdown will auto focus |
| clearOnBlur | bool | true | If true, and `searchable`, search value will be cleared on blur |
| clearOnSelect | bool | true | If true, and `searchable`, search value will be cleared upon value select/de-select |
| name | string | null | If set, input type hidden would be added in the component with the value of the `name` prop as name and select's `values` as value |
| dropdownGap | number | 5 | Gap between select element and dropdown |
| multi | bool | false | If true - will act as multi-select, if false - only one option will be selected at the time |
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
"description": "Customizable dropdown select for react",
"main": "dist/react-dropdown-select.js",
"module": "src/index.js",
"files": [
"dist",
"src"
],
"scripts": {
"test": "jest --bail && npm run prepublishOnly && bundlesize",
"test:watch": "jest --bail --watch && npm run prepublishOnly && bundlesize",
Expand Down
13 changes: 9 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,9 @@ export class Select extends Component {

if (action === 'close' && this.state.dropdown) {
this.select.current.blur();
return this.setState({ dropdown: false, search: '' });

this.props.clearOnBlur && this.setState({ search: '' });
return this.setState({ dropdown: false });
}

if (action === 'open' && !this.state.dropdown) {
Expand Down Expand Up @@ -204,11 +206,12 @@ export class Select extends Component {
} else {
this.setState({
values: [item],
dropdown: false,
search: ''
dropdown: false
});
}

this.props.clearOnSelect && this.setState({ search: '' });

return true;
};

Expand Down Expand Up @@ -432,7 +435,7 @@ export class Select extends Component {
}

Select.defaultProps = {
addPlaceholder: "",
addPlaceholder: '',
placeholder: 'Select...',
values: [],
options: [],
Expand All @@ -456,6 +459,8 @@ Select.defaultProps = {
color: '#0074D9',
keepSelectedInList: true,
closeOnSelect: false,
clearOnBlur: true,
clearOnSelect: true,
dropdownPosition: 'bottom',
dropdownHeight: '300px',
autoFocus: false,
Expand Down

0 comments on commit edc348e

Please sign in to comment.