diff options
author | Thomas Huang <tmashuang@users.noreply.github.com> | 2018-03-20 00:20:04 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-20 00:20:04 +0800 |
commit | 424e98f6a896df6a848a92ef318464abc505d83d (patch) | |
tree | 4bb99f7ca9d6b924f50c7dcf575962faf185f3c8 /ui/app | |
parent | a1db40047c2a6fdbb8d2de2abacd0484e12e128d (diff) | |
parent | 62a95139e6cd9de66941ddb037ec682af568a30b (diff) | |
download | tangerine-wallet-browser-424e98f6a896df6a848a92ef318464abc505d83d.tar tangerine-wallet-browser-424e98f6a896df6a848a92ef318464abc505d83d.tar.gz tangerine-wallet-browser-424e98f6a896df6a848a92ef318464abc505d83d.tar.bz2 tangerine-wallet-browser-424e98f6a896df6a848a92ef318464abc505d83d.tar.lz tangerine-wallet-browser-424e98f6a896df6a848a92ef318464abc505d83d.tar.xz tangerine-wallet-browser-424e98f6a896df6a848a92ef318464abc505d83d.tar.zst tangerine-wallet-browser-424e98f6a896df6a848a92ef318464abc505d83d.zip |
Merge pull request #3594 from danjm/i3344-improve-currency-input
Currency input defaults to empty string
Diffstat (limited to 'ui/app')
-rw-r--r-- | ui/app/components/currency-input.js | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/ui/app/components/currency-input.js b/ui/app/components/currency-input.js index 6f7862e51..940238fa5 100644 --- a/ui/app/components/currency-input.js +++ b/ui/app/components/currency-input.js @@ -8,8 +8,12 @@ inherits(CurrencyInput, Component) function CurrencyInput (props) { Component.call(this) + const sanitizedValue = sanitizeValue(props.value) + this.state = { - value: sanitizeValue(props.value), + value: sanitizedValue, + emptyState: false, + focused: false, } } @@ -58,9 +62,11 @@ CurrencyInput.prototype.handleChange = function (newValue) { if (value === '0' && newValue[newValueLastIndex] === '0') { parsedValue = parsedValue.slice(0, newValueLastIndex) } - const sanitizedValue = sanitizeValue(parsedValue) - this.setState({ value: sanitizedValue }) + this.setState({ + value: sanitizedValue, + emptyState: newValue === '' && sanitizedValue === '0', + }) onInputChange(sanitizedValue) } @@ -86,17 +92,19 @@ CurrencyInput.prototype.render = function () { readOnly, inputRef, } = this.props + const { emptyState, focused } = this.state const inputSizeMultiplier = readOnly ? 1 : 1.2 const valueToRender = this.getValueToRender() - return h('input', { className, - value: valueToRender, - placeholder, + value: emptyState ? '' : valueToRender, + placeholder: focused ? '' : placeholder, size: valueToRender.length * inputSizeMultiplier, readOnly, + onFocus: () => this.setState({ focused: true, emptyState: valueToRender === '0' }), + onBlur: () => this.setState({ focused: false, emptyState: false }), onChange: e => this.handleChange(e.target.value), ref: inputRef, }) |