From d28905f6b876d18cba5969fc5be79a3d287cb7ad Mon Sep 17 00:00:00 2001 From: chriddyp Date: Thu, 20 Jul 2017 22:58:01 -0400 Subject: [PATCH 1/5] Fix clearing `x` behaviour --- src/components/Dropdown.react.js | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/components/Dropdown.react.js b/src/components/Dropdown.react.js index 4923cd84b..02c7a12dd 100644 --- a/src/components/Dropdown.react.js +++ b/src/components/Dropdown.react.js @@ -40,12 +40,23 @@ export default class Dropdown extends Component { value={selectedValue} onChange={selectedOption => { if (multi) { - const values = R.pluck('value', selectedOption); - this.setState({value: values}); - if (setProps) setProps({value: values}); + let value; + if (R.isNil(selectedOption)) { + value = [] + } else { + value = R.pluck('value', selectedOption); + } + this.setState({value}); + if (setProps) setProps({value}); } else { - this.setState({value: selectedOption.value}); - if (setProps) setProps({value: selectedOption.value}); + let value; + if (R.isNil(selectedOption)) { + value = null + } else { + value = selectedOption.value; + } + this.setState({value}); + if (setProps) setProps({value}); } if (fireEvent) fireEvent('change'); }} From d33e11f9de893ae16988641e636b2a8475f575d7 Mon Sep 17 00:00:00 2001 From: chriddyp Date: Thu, 20 Jul 2017 22:58:26 -0400 Subject: [PATCH 2/5] Add `clearable` and `searchable` properties --- src/components/Dropdown.react.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/components/Dropdown.react.js b/src/components/Dropdown.react.js index 02c7a12dd..156bff82b 100644 --- a/src/components/Dropdown.react.js +++ b/src/components/Dropdown.react.js @@ -71,6 +71,14 @@ Dropdown.propTypes = { id: PropTypes.string, className: PropTypes.string, + + /** + * Whether or not the dropdown is "clearable", that is, whether or + * not a small "x" appears on the right of the dropdown that removes + * the selected value. + */ + clearable: PropTypes.bool, + /** * If true, the option is disabled */ @@ -94,6 +102,11 @@ Dropdown.propTypes = { */ placeholder: PropTypes.string, + /** + * Whether to enable the searching feature or not + */ + searchable: PropTypes.bool, + /** * The value of the input. If `multi` is false (the default) * then value is just a string that corresponds to the values From 843dad339775854df546cc1d08b821bc5fe95265 Mon Sep 17 00:00:00 2001 From: chriddyp Date: Thu, 20 Jul 2017 22:58:33 -0400 Subject: [PATCH 3/5] document default properties --- src/components/Dropdown.react.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/components/Dropdown.react.js b/src/components/Dropdown.react.js index 156bff82b..2d906afc8 100644 --- a/src/components/Dropdown.react.js +++ b/src/components/Dropdown.react.js @@ -127,3 +127,10 @@ Dropdown.propTypes = { dashEvents: PropTypes.oneOf(['change']) }; + +Dropdown.defaultProps = { + clearable: true, + disabled: false, + multi: false, + searchable: true +} From b00a468a6bcd325083df3ea581a394807b4a9f78 Mon Sep 17 00:00:00 2001 From: chriddyp Date: Thu, 20 Jul 2017 22:58:54 -0400 Subject: [PATCH 4/5] generate new metadata --- dash_core_components/metadata.json | 34 ++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/dash_core_components/metadata.json b/dash_core_components/metadata.json index 418d230f5..b8a6f4c69 100644 --- a/dash_core_components/metadata.json +++ b/dash_core_components/metadata.json @@ -139,19 +139,38 @@ "required": false, "description": "" }, + "clearable": { + "type": { + "name": "bool" + }, + "required": false, + "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.", + "defaultValue": { + "value": "true", + "computed": false + } + }, "disabled": { "type": { "name": "bool" }, "required": false, - "description": "If true, the option is disabled" + "description": "If true, the option is disabled", + "defaultValue": { + "value": "false", + "computed": false + } }, "multi": { "type": { "name": "bool" }, "required": false, - "description": "If true, the user can select multiple values" + "description": "If true, the user can select multiple values", + "defaultValue": { + "value": "false", + "computed": false + } }, "options": { "type": { @@ -184,6 +203,17 @@ "required": false, "description": "The grey, default text shown when no option is selected" }, + "searchable": { + "type": { + "name": "bool" + }, + "required": false, + "description": "Whether to enable the searching feature or not", + "defaultValue": { + "value": "true", + "computed": false + } + }, "value": { "type": { "name": "union", From f4d4d9479b94c856a82d85a2c2ae3cff52f1b023 Mon Sep 17 00:00:00 2001 From: chriddyp Date: Thu, 20 Jul 2017 23:00:10 -0400 Subject: [PATCH 5/5] v0.7.0 --- CHANGELOG.md | 8 ++++++++ dash_core_components/version.py | 2 +- package.json | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8efe9b913..7535790b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +## [0.7.0] - 2017-07-20 +### Added +- The `clearable` property to the `Dropdown`, which toggles on and off the "x" on the side of the dropdown that clears the current selection. +- The `searchable` property to the `Dropdown`, which toggles on and off whether the `Dropdown` is searchable. + +### Fixed +- 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. + ## [0.6.0] - 2017-07-18 ### Added - 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). diff --git a/dash_core_components/version.py b/dash_core_components/version.py index ef7eb44d9..a71c5c7f1 100644 --- a/dash_core_components/version.py +++ b/dash_core_components/version.py @@ -1 +1 @@ -__version__ = '0.6.0' +__version__ = '0.7.0' diff --git a/package.json b/package.json index e69f878fa..401d31534 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dash-core-components", - "version": "0.6.0", + "version": "0.7.0", "description": "Core component suite for Dash", "repository": { "type": "git",