From 58456e7b85728f21d201383d0093f88b4f179598 Mon Sep 17 00:00:00 2001 From: paco Date: Thu, 27 Dec 2018 14:47:53 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix(taro-components):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=20Textarea=20=E7=BB=84=E4=BB=B6=E6=97=A0=E6=B3=95=E4=BC=A0?= =?UTF-8?q?=E9=80=92=20detail=20=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复 Textarea 组件 onChange 事件无法传递 detail 问题,兼容 onInput 事件 fix #1713 --- .../src/components/textarea/index.js | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/packages/taro-components/src/components/textarea/index.js b/packages/taro-components/src/components/textarea/index.js index e98fe2baba7c..ee21af269475 100644 --- a/packages/taro-components/src/components/textarea/index.js +++ b/packages/taro-components/src/components/textarea/index.js @@ -5,19 +5,16 @@ class Textarea extends Nerv.Component { super(...arguments) } - onChange (e) { - const { onChange, onInput } = this.props + onChange = (e) => { + const { onChange = '', onInput = '' } = this.props Object.defineProperty(e, 'detail', { enumerable: true, value: { value: e.target.value } }) - if (onChange) { - onChange && onChange(e) - } else { - onInput && onInput(e) - } + if (onChange) return onChange && onChange(e) + if (onInput) return onInput && onInput(e) } render () { @@ -26,7 +23,6 @@ class Textarea extends Nerv.Component { placeholder = '', disabled, maxLength = 140, - onChange, onFocus, onBlur, autoFocus = false @@ -39,6 +35,7 @@ class Textarea extends Nerv.Component { 'disabled', 'maxlength', 'onChange', + 'onInput', 'onFocus', 'onBlur', 'autofocus' @@ -48,7 +45,7 @@ class Textarea extends Nerv.Component { disabled={disabled} maxlength={maxLength} autofocus={autoFocus} - onChange={onChange} + onChange={this.onChange} onFocus={onFocus} onBlur={onBlur} /> From 3b978e0104bf50cd48e08a5e68dd74d08995f17b Mon Sep 17 00:00:00 2001 From: JinJinJin <709899428@qq.com> Date: Mon, 7 Jan 2019 18:54:54 +0800 Subject: [PATCH 2/2] Update index.js --- packages/taro-components/src/components/textarea/index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/taro-components/src/components/textarea/index.js b/packages/taro-components/src/components/textarea/index.js index ee21af269475..2d0da41312f9 100644 --- a/packages/taro-components/src/components/textarea/index.js +++ b/packages/taro-components/src/components/textarea/index.js @@ -3,9 +3,10 @@ import omit from 'omit.js' class Textarea extends Nerv.Component { constructor () { super(...arguments) + this.onChange = this.onChange.bind(this) } - onChange = (e) => { + onChange (e) { const { onChange = '', onInput = '' } = this.props Object.defineProperty(e, 'detail', { enumerable: true, @@ -22,7 +23,7 @@ class Textarea extends Nerv.Component { className = '', placeholder = '', disabled, - maxLength = 140, + maxlength = 140, onFocus, onBlur, autoFocus = false