aboutsummaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorDan <danjm.com@gmail.com>2018-03-20 03:10:48 +0800
committerDan <danjm.com@gmail.com>2018-03-20 03:10:48 +0800
commit4d1793b0ec364277765a8c8ec6026da904d51055 (patch)
tree26946d7b4e4f3e50fcde3f67224cc3c0c20c9c2c /ui
parent09260f9c5e0b2c460a214f00b87c8fafe0470419 (diff)
parent424e98f6a896df6a848a92ef318464abc505d83d (diff)
downloadtangerine-wallet-browser-4d1793b0ec364277765a8c8ec6026da904d51055.tar
tangerine-wallet-browser-4d1793b0ec364277765a8c8ec6026da904d51055.tar.gz
tangerine-wallet-browser-4d1793b0ec364277765a8c8ec6026da904d51055.tar.bz2
tangerine-wallet-browser-4d1793b0ec364277765a8c8ec6026da904d51055.tar.lz
tangerine-wallet-browser-4d1793b0ec364277765a8c8ec6026da904d51055.tar.xz
tangerine-wallet-browser-4d1793b0ec364277765a8c8ec6026da904d51055.tar.zst
tangerine-wallet-browser-4d1793b0ec364277765a8c8ec6026da904d51055.zip
Merge branch 'master' into i18n-translator-redux
Diffstat (limited to 'ui')
-rw-r--r--ui/app/components/currency-input.js20
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,
})