From c827afe112317f95190ed84410b0f14306cb3e5a Mon Sep 17 00:00:00 2001 From: jimczj Date: Fri, 28 Dec 2018 16:05:57 +0800 Subject: [PATCH] =?UTF-8?q?fix(input):=20fix=20#165=20editabled=20?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E5=88=87=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/input/index.js | 34 +++++++++++++++++++++++++++++---- src/style/components/input.scss | 19 ++++++++++++++++++ 2 files changed, 49 insertions(+), 4 deletions(-) diff --git a/src/components/input/index.js b/src/components/input/index.js index dd1b696cc..d4e28abb4 100644 --- a/src/components/input/index.js +++ b/src/components/input/index.js @@ -4,6 +4,8 @@ import PropTypes from 'prop-types' import classNames from 'classnames' import AtComponent from '../../common/component' +const ENV = Taro.getEnv() + function getInputProps (props) { const actualProps = { type: props.type, @@ -20,6 +22,11 @@ function getInputProps (props) { case 'password': actualProps.password = true break + case 'digit': + if (ENV === Taro.ENV_TYPE.WEB) { + actualProps.type = 'number' + } + break default: break } @@ -31,7 +38,17 @@ function getInputProps (props) { export default class AtInput extends AtComponent { onInput (e) { - this.props.onChange(e.target.value, ...arguments) + let value = e.target.value + const { type, maxLength } = getInputProps(this.props) + if ( + ENV === Taro.ENV_TYPE.WEB + && type === 'number' + && value + && maxLength <= value.length + ) { + value = value.substring(0, maxLength) + } + return this.props.onChange(value, ...arguments) } onFocus (e) { @@ -106,12 +123,22 @@ export default class AtInput extends AtComponent { 'at-input--disabled': disabled }) } - onClick={this.onClick.bind(this)} > + + {title && ( )} -