From dc5dd6b94176b1600b721f27bbd0f9cb8c0dfa02 Mon Sep 17 00:00:00 2001 From: Nicolas Gotchac Date: Fri, 21 Oct 2016 17:01:06 +0200 Subject: [PATCH] Bumped Material UI version (fixing issues with AutoComplete) (#2790) Fixed issues with Searchable addresses --- js/package.json | 2 +- js/src/ui/Form/AddressSelect/addressSelect.js | 44 ++++++++++------- js/src/ui/Form/AutoComplete/autocomplete.js | 48 +++++++++++++++++-- js/src/ui/Form/InputAddress/inputAddress.js | 16 ++++++- 4 files changed, 87 insertions(+), 23 deletions(-) diff --git a/js/package.json b/js/package.json index 6d1eaac29..9bfcfb9be 100644 --- a/js/package.json +++ b/js/package.json @@ -116,7 +116,7 @@ "js-sha3": "^0.5.2", "lodash": "^4.11.1", "marked": "^0.3.6", - "material-ui": "^0.15.4", + "material-ui": "^0.16.1", "material-ui-chip-input": "^0.8.0", "moment": "^2.14.1", "react": "^15.2.1", diff --git a/js/src/ui/Form/AddressSelect/addressSelect.js b/js/src/ui/Form/AddressSelect/addressSelect.js index 197b4c5bf..3eae1aef8 100644 --- a/js/src/ui/Form/AddressSelect/addressSelect.js +++ b/js/src/ui/Form/AddressSelect/addressSelect.js @@ -37,13 +37,14 @@ export default class AddressSelect extends Component { } state = { - entries: {} + entries: {}, + value: '' } componentWillMount () { - const { accounts, contacts } = this.props; + const { accounts, contacts, value } = this.props; const entries = Object.assign({}, accounts || {}, contacts || {}); - this.setState({ entries }); + this.setState({ entries, value }); } componentWillReceiveProps (newProps) { @@ -55,34 +56,36 @@ export default class AddressSelect extends Component { render () { const { disabled, error, hint, label } = this.props; const { entries } = this.state; + const value = this.getSearchText(); return (
- { this.renderIdentityIcon() } + { this.renderIdentityIcon(value) }
); } - renderIdentityIcon () { - if (this.props.error) { + renderIdentityIcon (inputValue) { + const { error, value } = this.props; + + if (error || !inputValue) { return null; } - const { value } = this.props; - return ( { @@ -143,8 +150,11 @@ export default class AddressSelect extends Component { .some(text => text.toLowerCase().indexOf(lowCaseSearch) !== -1); } - onChange = (entry) => { - const address = entry ? entry.address : ''; + onChange = (entry, empty) => { + const address = entry && entry.address + ? entry.address + : (empty ? '' : this.state.value); + this.props.onChange(null, address); } } diff --git a/js/src/ui/Form/AutoComplete/autocomplete.js b/js/src/ui/Form/AutoComplete/autocomplete.js index c5d405eaa..353b4d73c 100644 --- a/js/src/ui/Form/AutoComplete/autocomplete.js +++ b/js/src/ui/Form/AutoComplete/autocomplete.js @@ -16,6 +16,7 @@ import React, { Component, PropTypes } from 'react'; import { MenuItem, AutoComplete as MUIAutoComplete } from 'material-ui'; +import { PopoverAnimationVertical } from 'material-ui/Popover'; export default class AutoComplete extends Component { static propTypes = { @@ -28,14 +29,22 @@ export default class AutoComplete extends Component { className: PropTypes.string, filter: PropTypes.func, renderItem: PropTypes.func, + entry: PropTypes.object, entries: PropTypes.oneOfType([ PropTypes.array, PropTypes.object ]) } + state = { + lastChangedValue: undefined, + entry: null, + open: false + } + render () { const { disabled, error, hint, label, value, className, filter } = this.props; + const { open } = this.state; return ( { - const { onChange, entries } = this.props; + if (idx === -1) { + return; + } + + const { entries } = this.props; + const entriesArray = (entries instanceof Array) ? entries : Object.values(entries); - const entry = (idx === -1) ? null : entriesArray[idx]; + const entry = entriesArray[idx]; - onChange(entry); + this.handleOnChange(entry); + this.setState({ entry, open: false }); + } + + onBlur = () => { + window.setTimeout(() => { + const { entry } = this.state; + + this.handleOnChange(entry); + }, 100); } onFocus = () => { - this.props.onChange(null); + const { entry } = this.props; + + this.setState({ entry, open: true }, () => { + this.handleOnChange(null, true); + }); + } + + handleOnChange = (value, empty) => { + const { lastChangedValue } = this.state; + + if (value !== lastChangedValue) { + this.setState({ lastChangedValue: value }); + this.props.onChange(value, empty); + } } } diff --git a/js/src/ui/Form/InputAddress/inputAddress.js b/js/src/ui/Form/InputAddress/inputAddress.js index c3e2bb4ab..2c99dd1d1 100644 --- a/js/src/ui/Form/InputAddress/inputAddress.js +++ b/js/src/ui/Form/InputAddress/inputAddress.js @@ -44,10 +44,24 @@ class InputAddress extends Component { componentWillMount () { const { value, text, accountsInfo, tokens } = this.props; + const account = accountsInfo[value] || tokens[value]; const hasAccount = account && !account.meta.deleted; const inputValue = text && hasAccount ? account.name : value; - const isEmpty = (inputValue.length === 0); + const isEmpty = (!inputValue || inputValue.length === 0); + + this.setState({ isEmpty }); + } + + componentWillReceiveProps (newProps) { + const { value, text } = newProps; + + if (value === this.props.value && text === this.props.text) { + return; + } + + const inputValue = text || value; + const isEmpty = (!inputValue || inputValue.length === 0); this.setState({ isEmpty }); }