mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Currency input defaults to empty string
This commit is contained in:
parent
e2f340b324
commit
a348b60735
@ -8,8 +8,12 @@ inherits(CurrencyInput, Component)
|
|||||||
function CurrencyInput (props) {
|
function CurrencyInput (props) {
|
||||||
Component.call(this)
|
Component.call(this)
|
||||||
|
|
||||||
|
const sanitizedValue = sanitizeValue(props.value)
|
||||||
|
|
||||||
this.state = {
|
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') {
|
if (value === '0' && newValue[newValueLastIndex] === '0') {
|
||||||
parsedValue = parsedValue.slice(0, newValueLastIndex)
|
parsedValue = parsedValue.slice(0, newValueLastIndex)
|
||||||
}
|
}
|
||||||
|
|
||||||
const sanitizedValue = sanitizeValue(parsedValue)
|
const sanitizedValue = sanitizeValue(parsedValue)
|
||||||
this.setState({ value: sanitizedValue })
|
this.setState({
|
||||||
|
value: sanitizedValue,
|
||||||
|
emptyState: newValue === '' && sanitizedValue === '0',
|
||||||
|
})
|
||||||
onInputChange(sanitizedValue)
|
onInputChange(sanitizedValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,17 +92,19 @@ CurrencyInput.prototype.render = function () {
|
|||||||
readOnly,
|
readOnly,
|
||||||
inputRef,
|
inputRef,
|
||||||
} = this.props
|
} = this.props
|
||||||
|
const { emptyState, focused } = this.state
|
||||||
|
|
||||||
const inputSizeMultiplier = readOnly ? 1 : 1.2
|
const inputSizeMultiplier = readOnly ? 1 : 1.2
|
||||||
|
|
||||||
const valueToRender = this.getValueToRender()
|
const valueToRender = this.getValueToRender()
|
||||||
|
|
||||||
return h('input', {
|
return h('input', {
|
||||||
className,
|
className,
|
||||||
value: valueToRender,
|
value: emptyState ? '' : valueToRender,
|
||||||
placeholder,
|
placeholder: focused ? '' : placeholder,
|
||||||
size: valueToRender.length * inputSizeMultiplier,
|
size: valueToRender.length * inputSizeMultiplier,
|
||||||
readOnly,
|
readOnly,
|
||||||
|
onFocus: () => this.setState({ focused: true, emptyState: valueToRender === '0' }),
|
||||||
|
onBlur: () => this.setState({ focused: false, emptyState: false }),
|
||||||
onChange: e => this.handleChange(e.target.value),
|
onChange: e => this.handleChange(e.target.value),
|
||||||
ref: inputRef,
|
ref: inputRef,
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user