From a835f00ba6708838939e9ae8cb72b21cef2f6f24 Mon Sep 17 00:00:00 2001 From: ryanml Date: Tue, 6 Jul 2021 10:44:46 -0700 Subject: [PATCH] Fixing leading zero when amount input is focused (#11459) Fixes MetaMask/metamask-extension#11146 --- .../ui/unit-input/unit-input.component.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/ui/components/ui/unit-input/unit-input.component.js b/ui/components/ui/unit-input/unit-input.component.js index 78458cab6..8ea172ea7 100644 --- a/ui/components/ui/unit-input/unit-input.component.js +++ b/ui/components/ui/unit-input/unit-input.component.js @@ -45,6 +45,18 @@ export default class UnitInput extends PureComponent { this.unitInput.focus(); }; + handleInputFocus = ({ target: { value } }) => { + if (value === '0') { + this.setState({ value: '' }); + } + }; + + handleInputBlur = ({ target: { value } }) => { + if (value === '') { + this.setState({ value: '0' }); + } + }; + handleChange = (event) => { const { value: userInput } = event.target; let value = userInput; @@ -88,6 +100,8 @@ export default class UnitInput extends PureComponent { value={value} placeholder={placeholder} onChange={this.handleChange} + onBlur={this.handleInputBlur} + onFocus={this.handleInputFocus} style={{ width: this.getInputWidth(value) }} ref={(ref) => { this.unitInput = ref;