From f24d12800f3b4cc3d1ad041ef4fc2dcd274f7077 Mon Sep 17 00:00:00 2001 From: Phil Myers Date: Tue, 27 Feb 2018 13:11:46 -0500 Subject: [PATCH 1/3] Add falsy key example to AutocompleteTest --- spec/components/autocomplete.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/spec/components/autocomplete.js b/spec/components/autocomplete.js index 09c825c0..4b39cebe 100644 --- a/spec/components/autocomplete.js +++ b/spec/components/autocomplete.js @@ -13,6 +13,21 @@ class AutocompleteTest extends React.Component { 'EN-en': 'United States of America', 'EN-nz': 'New Zealand', }, + simpleMonth: 0, + monthsObject: { + 0: 'January', + 1: 'February', + 2: 'March', + 3: 'April', + 4: 'May', + 5: 'June', + 6: 'July', + 7: 'August', + 8: 'September', + 9: 'October', + 10: 'November', + 11: 'December', + } }; handleFocus = (event) => { @@ -44,6 +59,10 @@ class AutocompleteTest extends React.Component { this.setState({ simpleShowAll: value }); }; + handleSimpleMonthChange = (value) => { + this.setState({ simpleMonth: parseInt(value, 10) }); + }; + render() { return (
@@ -89,6 +108,16 @@ class AutocompleteTest extends React.Component { source={this.state.countriesArray} value={this.state.simpleShowAll} /> + +
); } From 1dafc5676f5cb962a539c680ca988b9dfc1204b1 Mon Sep 17 00:00:00 2001 From: Phil Myers Date: Tue, 27 Feb 2018 13:19:57 -0500 Subject: [PATCH 2/3] Move Input#validPresent to utils#isValuePresent --- components/input/Input.js | 10 ++-------- components/utils/utils.js | 7 +++++++ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/components/input/Input.js b/components/input/Input.js index 0ff8e190..274385fc 100644 --- a/components/input/Input.js +++ b/components/input/Input.js @@ -2,6 +2,7 @@ import React from 'react'; import PropTypes from 'prop-types'; import classnames from 'classnames'; import { themr } from 'react-css-themr'; +import { isValuePresent } from '../utils/utils'; import { INPUT } from '../identifiers'; import InjectedFontIcon from '../font_icon/FontIcon'; @@ -159,13 +160,6 @@ const factory = (FontIcon) => { this.inputNode.focus(); } - valuePresent = value => ( - value !== null - && value !== undefined - && value !== '' - && !(typeof value === 'number' && isNaN(value)) - ) - render() { const { children, defaultValue, disabled, error, floating, hint, icon, name, label: labelText, maxLength, multiline, required, role, @@ -180,7 +174,7 @@ const factory = (FontIcon) => { [theme.withIcon]: icon, }, this.props.className); - const valuePresent = this.valuePresent(value) || this.valuePresent(defaultValue); + const valuePresent = isValuePresent(value) || isValuePresent(defaultValue); const inputElementProps = { ...others, diff --git a/components/utils/utils.js b/components/utils/utils.js index 38b05dd7..08b9e5cc 100644 --- a/components/utils/utils.js +++ b/components/utils/utils.js @@ -74,3 +74,10 @@ export const getAnimationModule = (animation, theme) => compose( transformKeys(removeNamespace(animation)), pickBy((v, k) => k.startsWith(animation)), )(theme); + +export const isValuePresent = value => ( + value !== null + && value !== undefined + && value !== '' + && !(typeof value === 'number' && isNaN(value)) +); From f79aaff297aae6a5f491ffad93f150a12924015b Mon Sep 17 00:00:00 2001 From: Phil Myers Date: Tue, 27 Feb 2018 13:23:55 -0500 Subject: [PATCH 3/3] Check whether the query key has a value rather than whether it's truthy --- components/autocomplete/Autocomplete.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/components/autocomplete/Autocomplete.js b/components/autocomplete/Autocomplete.js index 16354852..ab0ad309 100644 --- a/components/autocomplete/Autocomplete.js +++ b/components/autocomplete/Autocomplete.js @@ -4,6 +4,7 @@ import PropTypes from 'prop-types'; import ReactDOM from 'react-dom'; import classnames from 'classnames'; import { themr } from 'react-css-themr'; +import { isValuePresent } from '../utils/utils'; import { AUTOCOMPLETE } from '../identifiers.js'; import InjectChip from '../chip/Chip.js'; import InjectInput from '../input/Input.js'; @@ -184,7 +185,7 @@ const factory = (Chip, Input) => { query(key) { let query_value = ''; - if (!this.props.multiple && key) { + if (!this.props.multiple && isValuePresent(key)) { const source_value = this.source().get(`${key}`); query_value = source_value || key; }