1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

Fixing leading zero when amount input is focused (#11459)

Fixes MetaMask/metamask-extension#11146
This commit is contained in:
ryanml 2021-07-06 10:44:46 -07:00 committed by GitHub
parent 9e86d417f9
commit a835f00ba6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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;