Input method focus add Selection content

This commit is contained in:
梁灏 2021-01-26 09:35:32 +08:00
parent cb82a97d88
commit 3fde9d0006

View file

@ -342,11 +342,24 @@
this.textareaStyles = calcTextareaHeight(this.$refs.textarea, minRows, maxRows); this.textareaStyles = calcTextareaHeight(this.$refs.textarea, minRows, maxRows);
}, },
focus () { focus (option) {
if (this.type === 'textarea') { const $el = this.type === 'textarea' ? this.$refs.textarea : this.$refs.input;
this.$refs.textarea.focus(); $el.focus(option);
} else { // Selection content
this.$refs.input.focus(); const { cursor } = option || {};
if (cursor) {
const len = $el.value.length;
switch (cursor) {
case 'start':
$el.setSelectionRange(0, 0);
break;
case 'end':
$el.setSelectionRange(len, len);
break;
default:
$el.setSelectionRange(0, len);
}
} }
}, },
blur () { blur () {