From 5398f24a9718ace4ce9267b9119adce7282e00e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AA=97=E4=BD=A0=E6=98=AF=E5=B0=8F=E7=8C=AB=E5=92=AA?= Date: Tue, 7 Jan 2020 11:42:31 +0800 Subject: [PATCH] refactor: improve digital input in tooltip demo (#20702) * refactor: improve digital input in tooltip demo * fix lint --- components/input/demo/tooltip.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/components/input/demo/tooltip.md b/components/input/demo/tooltip.md index 4fd28857e3..84ed2b09f6 100644 --- a/components/input/demo/tooltip.md +++ b/components/input/demo/tooltip.md @@ -35,7 +35,7 @@ function formatNumber(value) { class NumericInput extends React.Component { onChange = e => { const { value } = e.target; - const reg = /^-?(0|[1-9][0-9]*)(\.[0-9]*)?$/; + const reg = /^-?[0-9]*(\.[0-9]*)?$/; if ((!isNaN(value) && reg.test(value)) || value === '' || value === '-') { this.props.onChange(value); } @@ -44,9 +44,11 @@ class NumericInput extends React.Component { // '.' at the end or only '-' in the input box. onBlur = () => { const { value, onBlur, onChange } = this.props; + let valueTemp = value; if (value.charAt(value.length - 1) === '.' || value === '-') { - onChange(value.slice(0, -1)); + valueTemp = value.slice(0, -1); } + onChange(valueTemp.replace(/0*(\d+)/, '$1')); if (onBlur) { onBlur(); }