From ad371c20b6e2f874fef47369ffe60cb3751cd296 Mon Sep 17 00:00:00 2001 From: tanjinzhou <415800467@qq.com> Date: Tue, 7 Jul 2020 13:57:11 +0800 Subject: [PATCH] fix: input & textarea autofocus --- antdv-demo | 2 +- breakChange-2.x.md | 2 ++ components/_util/syncWatch.js | 6 ++++++ components/input/Input.jsx | 12 ++++++------ components/input/ResizableTextArea.jsx | 13 ++++++++----- components/input/TextArea.jsx | 12 +++--------- 6 files changed, 26 insertions(+), 21 deletions(-) create mode 100644 components/_util/syncWatch.js diff --git a/antdv-demo b/antdv-demo index 44f59845e..dbe3af5b2 160000 --- a/antdv-demo +++ b/antdv-demo @@ -1 +1 @@ -Subproject commit 44f59845e9fa34578b79066f22fb14526f4ee7a6 +Subproject commit dbe3af5b20e6599a78a9a7fba7c13258b36646a7 diff --git a/breakChange-2.x.md b/breakChange-2.x.md index fb1f95d85..07d352cbb 100644 --- a/breakChange-2.x.md +++ b/breakChange-2.x.md @@ -1,5 +1,7 @@ # break change +## global api + ## Tag ### CheckableTag diff --git a/components/_util/syncWatch.js b/components/_util/syncWatch.js new file mode 100644 index 000000000..aa2e25438 --- /dev/null +++ b/components/_util/syncWatch.js @@ -0,0 +1,6 @@ +export default function syncWatch(fn) { + return { + handler: fn, + flush: 'sync', + }; +} diff --git a/components/input/Input.jsx b/components/input/Input.jsx index 8777d27b7..4370d6994 100644 --- a/components/input/Input.jsx +++ b/components/input/Input.jsx @@ -5,6 +5,7 @@ import inputProps from './inputProps'; import { hasProp, getComponent, getOptionProps } from '../_util/props-util'; import { ConfigConsumerProps } from '../config-provider'; import ClearableLabeledInput from './ClearableLabeledInput'; +import syncWatch from '../_util/syncWatch'; function noop() {} @@ -68,15 +69,12 @@ export default { }; }, watch: { - value(val) { + value: syncWatch(function(val) { this.stateValue = val; - }, + }), }, mounted() { this.$nextTick(() => { - if (this.autoFocus) { - this.focus(); - } this.clearPasswordValueAttribute(); }); }, @@ -142,7 +140,6 @@ export default { 'size', 'inputType', 'className', - 'autoFocus', 'inputPrefixCls', 'loading', ]); @@ -164,6 +161,9 @@ export default { if (inputProps.maxLength === undefined) { delete inputProps.maxLength; } + if (!inputProps.autoFocus) { + delete inputProps.autoFocus; + } return ; }, clearPasswordValueAttribute() { diff --git a/components/input/ResizableTextArea.jsx b/components/input/ResizableTextArea.jsx index 58756ba2f..a1634a1eb 100644 --- a/components/input/ResizableTextArea.jsx +++ b/components/input/ResizableTextArea.jsx @@ -136,12 +136,15 @@ const ResizableTextArea = { ...otherProps, style, class: cls, - directives: [ - { - name: 'ant-input', - }, - ], + // directives: [ + // { + // name: 'ant-input', + // }, + // ], }; + if (!textareaProps.autoFocus) { + delete textareaProps.autoFocus; + } return (