aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components/currency-input.js
diff options
context:
space:
mode:
authorThomas <tmashuang@gmail.com>2018-03-22 03:25:41 +0800
committerThomas <tmashuang@gmail.com>2018-03-22 03:25:41 +0800
commitd646f377416ea6bfcd7682d21e011be5fa65cd3f (patch)
treedd5a1116920bc73738dcc1fefcc649927230a369 /ui/app/components/currency-input.js
parent6306c7b1901fa831e25ddd29607618122f805749 (diff)
parent072dd7ea2f7ce189b551b9fc8fd8e58aaaec4158 (diff)
downloadtangerine-wallet-browser-d646f377416ea6bfcd7682d21e011be5fa65cd3f.tar
tangerine-wallet-browser-d646f377416ea6bfcd7682d21e011be5fa65cd3f.tar.gz
tangerine-wallet-browser-d646f377416ea6bfcd7682d21e011be5fa65cd3f.tar.bz2
tangerine-wallet-browser-d646f377416ea6bfcd7682d21e011be5fa65cd3f.tar.lz
tangerine-wallet-browser-d646f377416ea6bfcd7682d21e011be5fa65cd3f.tar.xz
tangerine-wallet-browser-d646f377416ea6bfcd7682d21e011be5fa65cd3f.tar.zst
tangerine-wallet-browser-d646f377416ea6bfcd7682d21e011be5fa65cd3f.zip
Merge branch 'master' into selenium-e2e
Diffstat (limited to 'ui/app/components/currency-input.js')
-rw-r--r--ui/app/components/currency-input.js22
1 files changed, 16 insertions, 6 deletions
diff --git a/ui/app/components/currency-input.js b/ui/app/components/currency-input.js
index 6f7862e51..ece3eb43d 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)
}
@@ -85,18 +91,22 @@ CurrencyInput.prototype.render = function () {
placeholder,
readOnly,
inputRef,
+ type,
} = this.props
+ const { emptyState, focused } = this.state
const inputSizeMultiplier = readOnly ? 1 : 1.2
const valueToRender = this.getValueToRender()
-
return h('input', {
className,
- value: valueToRender,
- placeholder,
+ type,
+ 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,
})