Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.

Commit 1956027

Browse files
authored
Merge pull request #38 from plotly/x-behaviour
Fix `x` behaviour
2 parents 09d2e6f + f4d4d94 commit 1956027

File tree

5 files changed

+78
-9
lines changed

5 files changed

+78
-9
lines changed

CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22
All notable changes to this project will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44

5+
## [0.7.0] - 2017-07-20
6+
### Added
7+
- The `clearable` property to the `Dropdown`, which toggles on and off the "x" on the side of the dropdown that clears the current selection.
8+
- The `searchable` property to the `Dropdown`, which toggles on and off whether the `Dropdown` is searchable.
9+
10+
### Fixed
11+
- Clicking on the little `x` on the side of the Dropdown to clear the currently selected value didn't work. Now it does. If `multi=false`, then `null` (or Python's `None`) is set. If `multi=True`, then `[]` is set.
12+
513
## [0.6.0] - 2017-07-18
614
### Added
715
- The `Slider` and the `RangeSlider` component can update when the user finishes dragging the slider rather than just while they drag. The default behaviour has remained the same (updates while dragging) but you can toggle that the updates only get fired on "mouse up" by setting `updatemode` to `'mouseup'` (`'drag'` is the default).

dash_core_components/metadata.json

+32-2
Original file line numberDiff line numberDiff line change
@@ -139,19 +139,38 @@
139139
"required": false,
140140
"description": ""
141141
},
142+
"clearable": {
143+
"type": {
144+
"name": "bool"
145+
},
146+
"required": false,
147+
"description": "Whether or not the dropdown is \"clearable\", that is, whether or\nnot a small \"x\" appears on the right of the dropdown that removes\nthe selected value.",
148+
"defaultValue": {
149+
"value": "true",
150+
"computed": false
151+
}
152+
},
142153
"disabled": {
143154
"type": {
144155
"name": "bool"
145156
},
146157
"required": false,
147-
"description": "If true, the option is disabled"
158+
"description": "If true, the option is disabled",
159+
"defaultValue": {
160+
"value": "false",
161+
"computed": false
162+
}
148163
},
149164
"multi": {
150165
"type": {
151166
"name": "bool"
152167
},
153168
"required": false,
154-
"description": "If true, the user can select multiple values"
169+
"description": "If true, the user can select multiple values",
170+
"defaultValue": {
171+
"value": "false",
172+
"computed": false
173+
}
155174
},
156175
"options": {
157176
"type": {
@@ -184,6 +203,17 @@
184203
"required": false,
185204
"description": "The grey, default text shown when no option is selected"
186205
},
206+
"searchable": {
207+
"type": {
208+
"name": "bool"
209+
},
210+
"required": false,
211+
"description": "Whether to enable the searching feature or not",
212+
"defaultValue": {
213+
"value": "true",
214+
"computed": false
215+
}
216+
},
187217
"value": {
188218
"type": {
189219
"name": "union",

dash_core_components/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '0.6.0'
1+
__version__ = '0.7.0'

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "dash-core-components",
3-
"version": "0.6.0",
3+
"version": "0.7.0",
44
"description": "Core component suite for Dash",
55
"repository": {
66
"type": "git",

src/components/Dropdown.react.js

+36-5
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,23 @@ export default class Dropdown extends Component {
4040
value={selectedValue}
4141
onChange={selectedOption => {
4242
if (multi) {
43-
const values = R.pluck('value', selectedOption);
44-
this.setState({value: values});
45-
if (setProps) setProps({value: values});
43+
let value;
44+
if (R.isNil(selectedOption)) {
45+
value = []
46+
} else {
47+
value = R.pluck('value', selectedOption);
48+
}
49+
this.setState({value});
50+
if (setProps) setProps({value});
4651
} else {
47-
this.setState({value: selectedOption.value});
48-
if (setProps) setProps({value: selectedOption.value});
52+
let value;
53+
if (R.isNil(selectedOption)) {
54+
value = null
55+
} else {
56+
value = selectedOption.value;
57+
}
58+
this.setState({value});
59+
if (setProps) setProps({value});
4960
}
5061
if (fireEvent) fireEvent('change');
5162
}}
@@ -60,6 +71,14 @@ Dropdown.propTypes = {
6071
id: PropTypes.string,
6172

6273
className: PropTypes.string,
74+
75+
/**
76+
* Whether or not the dropdown is "clearable", that is, whether or
77+
* not a small "x" appears on the right of the dropdown that removes
78+
* the selected value.
79+
*/
80+
clearable: PropTypes.bool,
81+
6382
/**
6483
* If true, the option is disabled
6584
*/
@@ -83,6 +102,11 @@ Dropdown.propTypes = {
83102
*/
84103
placeholder: PropTypes.string,
85104

105+
/**
106+
* Whether to enable the searching feature or not
107+
*/
108+
searchable: PropTypes.bool,
109+
86110
/**
87111
* The value of the input. If `multi` is false (the default)
88112
* then value is just a string that corresponds to the values
@@ -103,3 +127,10 @@ Dropdown.propTypes = {
103127

104128
dashEvents: PropTypes.oneOf(['change'])
105129
};
130+
131+
Dropdown.defaultProps = {
132+
clearable: true,
133+
disabled: false,
134+
multi: false,
135+
searchable: true
136+
}

0 commit comments

Comments
 (0)