From 3a3bf6f5907cc136ef549fd59df42cf36b5ca972 Mon Sep 17 00:00:00 2001 From: Yuri S Date: Tue, 19 Dec 2017 11:17:29 +0200 Subject: [PATCH 01/25] Fixed two warnings on running tests --- test/AsyncCreatable-test.js | 3 +-- test/Creatable-test.js | 6 ++---- test/Select-test.js | 2 ++ 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/test/AsyncCreatable-test.js b/test/AsyncCreatable-test.js index 514a40bd8e..c891f981f5 100644 --- a/test/AsyncCreatable-test.js +++ b/test/AsyncCreatable-test.js @@ -19,11 +19,10 @@ var sinon = require('sinon'); var Select = require('../src'); describe('AsyncCreatable', () => { - let creatableInstance, creatableNode, filterInputNode, loadOptions, renderer; + let creatableInstance, creatableNode, filterInputNode, loadOptions; beforeEach(() => { loadOptions = sinon.stub(); - renderer = TestUtils.createRenderer(); }); function createControl (props = {}) { diff --git a/test/Creatable-test.js b/test/Creatable-test.js index 5a58726e3a..488eb1f78f 100644 --- a/test/Creatable-test.js +++ b/test/Creatable-test.js @@ -19,9 +19,7 @@ var TestUtils = require('react-dom/test-utils'); var Select = require('../src'); describe('Creatable', () => { - let creatableInstance, creatableNode, filterInputNode, innerSelectInstance, renderer; - - beforeEach(() => renderer = TestUtils.createRenderer()); + let creatableInstance, creatableNode, filterInputNode, innerSelectInstance; const defaultOptions = [ { value: 'one', label: 'One' }, @@ -221,7 +219,7 @@ describe('Creatable', () => { expect(test(newOption('qux', 4)), 'to be', true); expect(test(newOption('Foo', 11)), 'to be', true); }); - + it('default: isOptionUnique function should always return true if given options are empty', () => { const options = []; diff --git a/test/Select-test.js b/test/Select-test.js index 3b00677e4d..5bee909129 100644 --- a/test/Select-test.js +++ b/test/Select-test.js @@ -4465,6 +4465,8 @@ describe('Select', () => { options: defaultOptions, }); expect(warn, 'was called once'); + + warn.restore(); }); }); describe('rtl', () => { From 15651643f6522c2792515a40d38ec3329d55aacd Mon Sep 17 00:00:00 2001 From: Yuri S Date: Tue, 19 Dec 2017 11:28:49 +0200 Subject: [PATCH 02/25] Fixed autofocus warnings --- test/Select-test.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/test/Select-test.js b/test/Select-test.js index 5bee909129..356b5fafeb 100644 --- a/test/Select-test.js +++ b/test/Select-test.js @@ -4435,31 +4435,37 @@ describe('Select', () => { autoFocus: true, options: defaultOptions, }); - var input = ReactDOM.findDOMNode(instance.input).querySelector('input'); + const input = ReactDOM.findDOMNode(instance.input).querySelector('input'); expect(input, 'to equal', document.activeElement); }); it('with autofocus as well, calls focus() only once', () => { + const warn = sinon.stub(console, 'warn'); wrapper = createControl({ autofocus: true, autoFocus: true, options: defaultOptions, }); - var focus = sinon.spy(instance, 'focus'); + const focus = sinon.spy(instance, 'focus'); instance.componentDidMount(); expect(focus, 'was called once'); + + warn.restore(); }); }); describe('with autofocus', () => { it('focuses the select input on mount', () => { + const warn = sinon.stub(console, 'warn'); wrapper = createControl({ autofocus: true, options: defaultOptions, }); - var input = ReactDOM.findDOMNode(instance.input).querySelector('input'); + const input = ReactDOM.findDOMNode(instance.input).querySelector('input'); expect(input, 'to equal', document.activeElement); + + warn.restore(); }); it('calls console.warn', () => { - var warn = sinon.spy(console, 'warn'); + const warn = sinon.stub(console, 'warn'); wrapper = createControl({ autofocus: true, options: defaultOptions, From eb622395917b9f3156af5cdb0da92a19086080a1 Mon Sep 17 00:00:00 2001 From: Yuri S Date: Wed, 20 Dec 2017 08:51:07 +0200 Subject: [PATCH 03/25] arrowRenderer changed to arrow function --- src/utils/defaultArrowRenderer.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/utils/defaultArrowRenderer.js b/src/utils/defaultArrowRenderer.js index 3fee9f0ec4..b72ae139ad 100644 --- a/src/utils/defaultArrowRenderer.js +++ b/src/utils/defaultArrowRenderer.js @@ -1,7 +1,7 @@ import React from 'react'; import PropTypes from 'prop-types'; -export default function arrowRenderer ({ onMouseDown }) { +const arrowRenderer = ({ onMouseDown }) => { return ( Date: Wed, 20 Dec 2017 08:53:33 +0200 Subject: [PATCH 04/25] clearRenderer changed to arrow function --- src/utils/defaultClearRenderer.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/utils/defaultClearRenderer.js b/src/utils/defaultClearRenderer.js index 3f25e85d7d..66885dcb88 100644 --- a/src/utils/defaultClearRenderer.js +++ b/src/utils/defaultClearRenderer.js @@ -1,6 +1,6 @@ import React from 'react'; -export default function clearRenderer () { +const clearRenderer = () => { return ( ); }; + +export default clearRenderer; From 5791fb97344819add6839961667607e784d6c5b3 Mon Sep 17 00:00:00 2001 From: Yuri S Date: Wed, 20 Dec 2017 08:57:49 +0200 Subject: [PATCH 05/25] Refactored defaultFilterOptions file --- src/utils/defaultFilterOptions.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/utils/defaultFilterOptions.js b/src/utils/defaultFilterOptions.js index 5ae9b72410..9d92331e8c 100644 --- a/src/utils/defaultFilterOptions.js +++ b/src/utils/defaultFilterOptions.js @@ -1,11 +1,11 @@ import stripDiacritics from './stripDiacritics'; import trim from './trim'; -function isValid(value) { +const isValid = value => { return typeof (value) !== 'undefined' && value !== null && value !== ''; -} +}; -function filterOptions (options, filterValue, excludeOptions, props) { +const filterOptions = (options, filterValue, excludeOptions, props) => { if (props.ignoreAccents) { filterValue = stripDiacritics(filterValue); } @@ -25,17 +25,17 @@ function filterOptions (options, filterValue, excludeOptions, props) { if (props.filterOption) return props.filterOption.call(this, option, filterValue); if (!filterValue) return true; - var value = option[props.valueKey]; - var label = option[props.labelKey]; - var hasValue = isValid(value); - var hasLabel = isValid(label); + const value = option[props.valueKey]; + const label = option[props.labelKey]; + const hasValue = isValid(value); + const hasLabel = isValid(label); if (!hasValue && !hasLabel) { return false; } - var valueTest = hasValue ? String(value) : null; - var labelTest = hasLabel ? String(label) : null; + let valueTest = hasValue ? String(value) : null; + let labelTest = hasLabel ? String(label) : null; if (props.ignoreAccents) { if (valueTest && props.matchProp !== 'label') valueTest = stripDiacritics(valueTest); @@ -55,6 +55,6 @@ function filterOptions (options, filterValue, excludeOptions, props) { (labelTest && props.matchProp !== 'value' && labelTest.indexOf(filterValue) >= 0) ); }); -} +}; export default filterOptions; From b35f8d055b45cc3b8a2d55b599b8d2acb4a2c4f7 Mon Sep 17 00:00:00 2001 From: Yuri S Date: Fri, 22 Dec 2017 01:58:36 +0200 Subject: [PATCH 06/25] Refactored defaultMenuRenderer file --- src/utils/defaultMenuRenderer.js | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/utils/defaultMenuRenderer.js b/src/utils/defaultMenuRenderer.js index 224a2376a5..d2fd6494ac 100644 --- a/src/utils/defaultMenuRenderer.js +++ b/src/utils/defaultMenuRenderer.js @@ -1,12 +1,12 @@ import classNames from 'classnames'; +import PropTypes from 'prop-types'; import React from 'react'; -function menuRenderer ({ +const menuRenderer = ({ focusedOption, focusOption, inputValue, instancePrefix, - labelKey, onFocus, onOptionRef, onSelect, @@ -18,11 +18,11 @@ function menuRenderer ({ selectValue, valueArray, valueKey, -}) { +}) => { let Option = optionComponent; return options.map((option, i) => { - let isSelected = valueArray && valueArray.some(x => x[valueKey] == option[valueKey]); + let isSelected = valueArray && valueArray.some(x => x[valueKey] === option[valueKey]); let isFocused = option === focusedOption; let optionClass = classNames(optionClassName, { 'Select-option': true, @@ -53,6 +53,24 @@ function menuRenderer ({ ); }); -} +}; + +menuRenderer.propTypes = { + focusOption: PropTypes.func, + focusedOption: PropTypes.object, + inputValue: PropTypes.string, + instancePrefix: PropTypes.string, + onFocus: PropTypes.func, + onOptionRef: PropTypes.func, + onSelect: PropTypes.func, + optionClassName: PropTypes.string, + optionComponent: PropTypes.func, + optionRenderer: PropTypes.func, + options: PropTypes.array, + removeValue: PropTypes.func, + selectValue: PropTypes.func, + valueArray: PropTypes.array, + valueKey: PropTypes.string, +}; export default menuRenderer; From 880a473430b5474a3768dbdbc5e7d56647083440 Mon Sep 17 00:00:00 2001 From: Yuri S Date: Fri, 22 Dec 2017 02:03:32 +0200 Subject: [PATCH 07/25] Refactored stripDiacritics file --- src/utils/stripDiacritics.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/utils/stripDiacritics.js b/src/utils/stripDiacritics.js index 478d26e6b9..d6456ddc91 100644 --- a/src/utils/stripDiacritics.js +++ b/src/utils/stripDiacritics.js @@ -1,4 +1,4 @@ -var map = [ +const map = [ { 'base':'A', 'letters':/[\u0041\u24B6\uFF21\u00C0\u00C1\u00C2\u1EA6\u1EA4\u1EAA\u1EA8\u00C3\u0100\u0102\u1EB0\u1EAE\u1EB4\u1EB2\u0226\u01E0\u00C4\u01DE\u1EA2\u00C5\u01FA\u01CD\u0200\u0202\u1EA0\u1EAC\u1EB6\u1E00\u0104\u023A\u2C6F]/g }, { 'base':'AA','letters':/[\uA732]/g }, { 'base':'AE','letters':/[\u00C6\u01FC\u01E2]/g }, @@ -85,9 +85,11 @@ var map = [ { 'base':'z', 'letters':/[\u007A\u24E9\uFF5A\u017A\u1E91\u017C\u017E\u1E93\u1E95\u01B6\u0225\u0240\u2C6C\uA763]/g }, ]; -export default function stripDiacritics (str) { - for (var i = 0; i < map.length; i++) { +const stripDiacritics = str => { + for (let i = 0; i < map.length; i++) { str = str.replace(map[i].letters, map[i].base); } return str; }; + +export default stripDiacritics; From f7a17a6053b50ed89652341a2b86a90c5d5f1ef0 Mon Sep 17 00:00:00 2001 From: Yuri S Date: Fri, 22 Dec 2017 02:06:24 +0200 Subject: [PATCH 08/25] Refactored trim file --- src/utils/trim.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/utils/trim.js b/src/utils/trim.js index 56aef05bd2..4f0172a419 100644 --- a/src/utils/trim.js +++ b/src/utils/trim.js @@ -1,3 +1,3 @@ -export default function trim(str) { - return str.replace(/^\s+|\s+$/g, ''); -} +const trim = str => str.replace(/^\s+|\s+$/g, ''); + +export default trim; From 4fa40cbb6f54860e28dc8e9f8615ba1beed85fc3 Mon Sep 17 00:00:00 2001 From: Yuri S Date: Fri, 22 Dec 2017 02:17:07 +0200 Subject: [PATCH 09/25] Refactored Async.js --- src/Async.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/Async.js b/src/Async.js index 8b7d8330d6..66810ee168 100644 --- a/src/Async.js +++ b/src/Async.js @@ -1,7 +1,9 @@ -import React, { Component } from 'react'; import PropTypes from 'prop-types'; +import React, { Component } from 'react'; import Select from './Select'; + import stripDiacritics from './utils/stripDiacritics'; + const propTypes = { autoload: PropTypes.bool.isRequired, // automatically call the `loadOptions` prop on-mount; defaults to true cache: PropTypes.any, // object to use to cache results; set to null/false to disable caching @@ -34,6 +36,8 @@ const propTypes = { const defaultCache = {}; +const defaultChildren = props => - ); -} From d205e64c6d7edb57274d56c154ca70abae0ab8b9 Mon Sep 17 00:00:00 2001 From: Yuri S Date: Fri, 22 Dec 2017 02:20:33 +0200 Subject: [PATCH 10/25] Refactored AsyncCreatable.js --- src/AsyncCreatable.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/AsyncCreatable.js b/src/AsyncCreatable.js index 55d064818c..cf3aa0ecae 100644 --- a/src/AsyncCreatable.js +++ b/src/AsyncCreatable.js @@ -1,8 +1,9 @@ -import React from 'react'; import PropTypes from 'prop-types'; -import Select from './Select'; +import React from 'react'; + import Async from './Async'; import Creatable from './Creatable'; +import Select from './Select'; class AsyncCreatableSelect extends React.Component { @@ -32,13 +33,9 @@ class AsyncCreatableSelect extends React.Component { ); } -}; +} -function defaultChildren (props) { - return ( - ; AsyncCreatableSelect.propTypes = { children: PropTypes.func.isRequired, // Child function responsible for creating the inner Select component; (props: Object): PropTypes.element From 69868a09842bdf468b07314ab170a20282b9cd5f Mon Sep 17 00:00:00 2001 From: Yuri S Date: Fri, 22 Dec 2017 03:01:34 +0200 Subject: [PATCH 11/25] Refactored Creatable.js --- src/Creatable.js | 38 ++++++++++++++------------------------ 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/src/Creatable.js b/src/Creatable.js index 43b26ab5aa..ec1fc44163 100644 --- a/src/Creatable.js +++ b/src/Creatable.js @@ -1,8 +1,9 @@ -import React from 'react'; import PropTypes from 'prop-types'; -import Select from './Select'; +import React from 'react'; + import defaultFilterOptions from './utils/defaultFilterOptions'; import defaultMenuRenderer from './utils/defaultMenuRenderer'; +import Select from './Select'; class CreatableSelect extends React.Component { constructor (props, context) { @@ -21,7 +22,6 @@ class CreatableSelect extends React.Component { newOptionCreator, onNewOptionClick, options = [], - shouldKeyDownEventCreateNewOption } = this.props; if (isValidNewOption({ label: this.inputValue })) { @@ -140,7 +140,7 @@ class CreatableSelect extends React.Component { } } - onOptionSelect (option, event) { + onOptionSelect (option) { if (option === this._createPlaceholderOption) { this.createNewOption(); } else { @@ -154,8 +154,6 @@ class CreatableSelect extends React.Component { render () { const { - newOptionCreator, - shouldKeyDownEventCreateNewOption, ref: refProp, ...restProps } = this.props; @@ -192,19 +190,15 @@ class CreatableSelect extends React.Component { return children(props); } -}; +} -function defaultChildren (props) { - return ( - ; -function isOptionUnique ({ option, options, labelKey, valueKey }) { +const isOptionUnique = ({ option, options, labelKey, valueKey }) => { if (!options || !options.length) { return true; } - + return options .filter((existingOption) => existingOption[labelKey] === option[labelKey] || @@ -213,23 +207,20 @@ function isOptionUnique ({ option, options, labelKey, valueKey }) { .length === 0; }; -function isValidNewOption ({ label }) { - return !!label; -}; +const isValidNewOption = ({ label }) => !!label; -function newOptionCreator ({ label, labelKey, valueKey }) { +const newOptionCreator = ({ label, labelKey, valueKey }) => { const option = {}; option[valueKey] = label; option[labelKey] = label; option.className = 'Select-create-option-placeholder'; + return option; }; -function promptTextCreator (label) { - return `Create option "${label}"`; -} +const promptTextCreator = label => `Create option "${label}"`; -function shouldKeyDownEventCreateNewOption ({ keyCode }) { +const shouldKeyDownEventCreateNewOption = ({ keyCode }) => { switch (keyCode) { case 9: // TAB case 13: // ENTER @@ -240,7 +231,7 @@ function shouldKeyDownEventCreateNewOption ({ keyCode }) { } }; - // Default prop methods +// Default prop methods CreatableSelect.isOptionUnique = isOptionUnique; CreatableSelect.isValidNewOption = isValidNewOption; CreatableSelect.newOptionCreator = newOptionCreator; @@ -305,5 +296,4 @@ CreatableSelect.propTypes = { shouldKeyDownEventCreateNewOption: PropTypes.func, }; - export default CreatableSelect; From d923fb6a0a4eb6ed15be3299239da141d0004cce Mon Sep 17 00:00:00 2001 From: Yuri S Date: Fri, 22 Dec 2017 03:08:11 +0200 Subject: [PATCH 12/25] Refactored Option.js --- src/Option.js | 45 ++++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/src/Option.js b/src/Option.js index 7a3de5da9a..4eb85818ad 100644 --- a/src/Option.js +++ b/src/Option.js @@ -1,6 +1,19 @@ -import React from 'react'; -import PropTypes from 'prop-types'; import classNames from 'classnames'; +import PropTypes from 'prop-types'; +import React from 'react'; + +const blockEvent = event => { + event.preventDefault(); + event.stopPropagation(); + if ((event.target.tagName !== 'A') || !('href' in event.target)) { + return; + } + if (event.target.target) { + window.open(event.target.href, event.target.target); + } else { + window.location.href = event.target.href; + } +}; class Option extends React.Component { @@ -16,20 +29,6 @@ class Option extends React.Component { this.onFocus = this.onFocus.bind(this); } - - blockEvent (event) { - event.preventDefault(); - event.stopPropagation(); - if ((event.target.tagName !== 'A') || !('href' in event.target)) { - return; - } - if (event.target.target) { - window.open(event.target.href, event.target.target); - } else { - window.location.href = event.target.href; - } - } - handleMouseDown (event) { event.preventDefault(); event.stopPropagation(); @@ -52,12 +51,12 @@ class Option extends React.Component { this.handleMouseDown(event); } - handleTouchMove (event) { + handleTouchMove () { // Set a flag that the view is being dragged this.dragging = true; } - handleTouchStart (event) { + handleTouchStart () { // Set a flag that the view is not being dragged this.dragging = false; } @@ -69,13 +68,13 @@ class Option extends React.Component { } render () { - var { option, instancePrefix, optionIndex } = this.props; - var className = classNames(this.props.className, option.className); + const { option, instancePrefix, optionIndex } = this.props; + const className = classNames(this.props.className, option.className); return option.disabled ? (
+ onMouseDown={blockEvent} + onClick={blockEvent}> {this.props.children}
) : ( @@ -95,7 +94,7 @@ class Option extends React.Component { ); } -}; +} Option.propTypes = { children: PropTypes.node, From 9185809c5d61700f33fee9be0edb3b08c6594603 Mon Sep 17 00:00:00 2001 From: Yuri S Date: Fri, 22 Dec 2017 03:11:15 +0200 Subject: [PATCH 13/25] Refactored Value.js --- src/Value.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/Value.js b/src/Value.js index e282fd18ca..d405e78dfc 100644 --- a/src/Value.js +++ b/src/Value.js @@ -1,6 +1,6 @@ -import React from 'react'; -import PropTypes from 'prop-types'; import classNames from 'classnames'; +import PropTypes from 'prop-types'; +import React from 'react'; class Value extends React.Component { @@ -43,12 +43,12 @@ class Value extends React.Component { this.onRemove(event); } - handleTouchMove (event) { + handleTouchMove () { // Set a flag that the view is being dragged this.dragging = true; } - handleTouchStart (event) { + handleTouchStart () { // Set a flag that the view is not being dragged this.dragging = false; } @@ -91,8 +91,7 @@ class Value extends React.Component { ); } -}; - +} Value.propTypes = { children: PropTypes.node, From 2823b8186a911e115f93ae24e05d7e3ed48b0783 Mon Sep 17 00:00:00 2001 From: Yuri S Date: Fri, 22 Dec 2017 03:22:50 +0200 Subject: [PATCH 14/25] Fixed console error --- examples/src/components/GithubUsers.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/src/components/GithubUsers.js b/examples/src/components/GithubUsers.js index f3a0887d40..00795927f9 100644 --- a/examples/src/components/GithubUsers.js +++ b/examples/src/components/GithubUsers.js @@ -13,7 +13,8 @@ const GithubUsers = createClass({ getInitialState () { return { backspaceRemoves: true, - multi: true + multi: true, + creatable: false, }; }, onChange (value) { From ba0f10c73f5f6704f3b40242e5ee8400b3b374d1 Mon Sep 17 00:00:00 2001 From: Yuri S Date: Fri, 22 Dec 2017 06:34:43 +0200 Subject: [PATCH 15/25] Fixed focused option --- src/Select.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Select.js b/src/Select.js index 06d519c7ec..7969bdd0c8 100644 --- a/src/Select.js +++ b/src/Select.js @@ -303,11 +303,13 @@ class Select extends React.Component { this.setState({ isOpen: toOpen, isPseudoFocused: false, + focusedOption: null, }); } else { // otherwise, focus the input and open the menu this._openAfterFocus = this.props.openOnClick; this.focus(); + this.setState({ focusedOption: null }); } } From 3a4fe2655719c855e5c10bbd94e9bb46c824df6a Mon Sep 17 00:00:00 2001 From: Yuri S Date: Fri, 22 Dec 2017 06:53:52 +0200 Subject: [PATCH 16/25] Fixed readme example --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a022326a9a..e645a74891 100644 --- a/README.md +++ b/README.md @@ -66,10 +66,13 @@ class App extends React.Component { console.log(`Selected: ${selectedOption.label}`); } render() { + const { selectedOption } = this.state; + const value = selectedOption && selectedOption.value; + return ( ); + }); it('should have retained inputValue after accepting selection with onSelectResetsInput=false', () => { // Render an instance of the component wrapper = createControlWithWrapper({ @@ -2146,6 +2164,7 @@ describe('Select', () => { onSelectResetsInput: false, onCloseResetsInput: false, onBlurResetsInput: false, + simpleValue: true, }); clickArrowToOpen(); @@ -2199,7 +2218,8 @@ describe('Select', () => { value: '', options: options, multi: true, - onSelectResetsInput: false + onSelectResetsInput: false, + simpleValue: true, }); clickArrowToOpen(); @@ -2216,6 +2236,7 @@ describe('Select', () => { value: '', options: options, multi: true, + simpleValue: true, }); clickArrowToOpen(); @@ -4521,4 +4542,17 @@ describe('Select', () => { }); }); }); + it('should clear the input value, if the value prop is cleared', () => { + wrapper = createControlWithWrapper({ + value: '', + options: options, + onSelectResetsInput: false, + onCloseResetsInput: false, + onBlurResetsInput: false, + simpleValue: true, + }); + typeSearchText('tw'); + setValueProp(''); + expect(instance.state.inputValue, 'to equal', ''); + }); }); From e6499a4775fbbf483d1785ab333f690144959e32 Mon Sep 17 00:00:00 2001 From: Charles Lee Date: Fri, 5 Jan 2018 10:22:54 +1100 Subject: [PATCH 24/25] added internal method for clearing state called setInputValue --- src/Select.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Select.js b/src/Select.js index 55baf023fd..3c40175f13 100644 --- a/src/Select.js +++ b/src/Select.js @@ -416,6 +416,18 @@ class Select extends React.Component { }); } + setInputValue(newValue) { + if (this.props.onInputChange) { + let nextState = this.props.onInputChange(newValue); + if (nextState != null && typeof nextState !== 'object') { + newValue = '' + nextState; + } + } + this.setState({ + inputValue: newValue + }); + } + handleInputValueChange(newValue) { if (this.props.onInputChange) { let nextState = this.props.onInputChange(newValue); From 1c20dc28abd846d7189e45f69c7ae1cb8c40b41b Mon Sep 17 00:00:00 2001 From: Charles Lee Date: Fri, 5 Jan 2018 10:24:54 +1100 Subject: [PATCH 25/25] added clearvalue functionality to State example --- examples/src/components/States.js | 9 ++++++++- test/Async-test.js | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/examples/src/components/States.js b/examples/src/components/States.js index 5286c6ee05..401b772b78 100644 --- a/examples/src/components/States.js +++ b/examples/src/components/States.js @@ -27,6 +27,9 @@ var StatesField = createClass({ rtl: false, }; }, + clearValue (e) { + this.select.setInputValue(''); + }, switchCountry (e) { var newCountry = e.target.value; this.setState({ @@ -54,7 +57,9 @@ var StatesField = createClass({

{this.props.label} (Source)