fix: input & textarea autofocus

pull/2539/head
tanjinzhou 2020-07-07 13:57:11 +08:00
parent 6cad9c3cc0
commit ad371c20b6
6 changed files with 26 additions and 21 deletions

@ -1 +1 @@
Subproject commit 44f59845e9fa34578b79066f22fb14526f4ee7a6 Subproject commit dbe3af5b20e6599a78a9a7fba7c13258b36646a7

View File

@ -1,5 +1,7 @@
# break change # break change
## global api
## Tag ## Tag
### CheckableTag ### CheckableTag

View File

@ -0,0 +1,6 @@
export default function syncWatch(fn) {
return {
handler: fn,
flush: 'sync',
};
}

View File

@ -5,6 +5,7 @@ import inputProps from './inputProps';
import { hasProp, getComponent, getOptionProps } from '../_util/props-util'; import { hasProp, getComponent, getOptionProps } from '../_util/props-util';
import { ConfigConsumerProps } from '../config-provider'; import { ConfigConsumerProps } from '../config-provider';
import ClearableLabeledInput from './ClearableLabeledInput'; import ClearableLabeledInput from './ClearableLabeledInput';
import syncWatch from '../_util/syncWatch';
function noop() {} function noop() {}
@ -68,15 +69,12 @@ export default {
}; };
}, },
watch: { watch: {
value(val) { value: syncWatch(function(val) {
this.stateValue = val; this.stateValue = val;
}, }),
}, },
mounted() { mounted() {
this.$nextTick(() => { this.$nextTick(() => {
if (this.autoFocus) {
this.focus();
}
this.clearPasswordValueAttribute(); this.clearPasswordValueAttribute();
}); });
}, },
@ -142,7 +140,6 @@ export default {
'size', 'size',
'inputType', 'inputType',
'className', 'className',
'autoFocus',
'inputPrefixCls', 'inputPrefixCls',
'loading', 'loading',
]); ]);
@ -164,6 +161,9 @@ export default {
if (inputProps.maxLength === undefined) { if (inputProps.maxLength === undefined) {
delete inputProps.maxLength; delete inputProps.maxLength;
} }
if (!inputProps.autoFocus) {
delete inputProps.autoFocus;
}
return <input {...inputProps} />; return <input {...inputProps} />;
}, },
clearPasswordValueAttribute() { clearPasswordValueAttribute() {

View File

@ -136,12 +136,15 @@ const ResizableTextArea = {
...otherProps, ...otherProps,
style, style,
class: cls, class: cls,
directives: [ // directives: [
{ // {
name: 'ant-input', // name: 'ant-input',
}, // },
], // ],
}; };
if (!textareaProps.autoFocus) {
delete textareaProps.autoFocus;
}
return ( return (
<ResizeObserver onResize={this.handleResize} disabled={!(autoSize || autosize)}> <ResizeObserver onResize={this.handleResize} disabled={!(autoSize || autosize)}>
<textarea {...textareaProps} ref={this.saveTextArea} /> <textarea {...textareaProps} ref={this.saveTextArea} />

View File

@ -6,6 +6,7 @@ import { hasProp, getOptionProps } from '../_util/props-util';
import { ConfigConsumerProps } from '../config-provider'; import { ConfigConsumerProps } from '../config-provider';
import { fixControlledValue, resolveOnChange } from './Input'; import { fixControlledValue, resolveOnChange } from './Input';
import PropTypes from '../_util/vue-types'; import PropTypes from '../_util/vue-types';
import syncWatch from '../_util/syncWatch';
const TextAreaProps = { const TextAreaProps = {
...inputProps, ...inputProps,
@ -32,16 +33,9 @@ export default {
}, },
computed: {}, computed: {},
watch: { watch: {
value(val) { value: syncWatch(function(val) {
this.stateValue = val; this.stateValue = val;
}, }),
},
mounted() {
this.$nextTick(() => {
if (this.autoFocus) {
this.focus();
}
});
}, },
methods: { methods: {
setValue(value, callback) { setValue(value, callback) {