Skip to content

Commit 4ec2947

Browse files
island205Feng
authored andcommitted
input: fix textarea ref (ElemeFE#13803)
1 parent ec514f5 commit 4ec2947

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

packages/autocomplete/src/autocomplete.vue

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,10 @@
149149
},
150150
watch: {
151151
suggestionVisible(val) {
152-
this.broadcast('ElAutocompleteSuggestions', 'visible', [val, this.$refs.input.$refs.input.offsetWidth]);
152+
let $input = this.getInput();
153+
if ($input) {
154+
this.broadcast('ElAutocompleteSuggestions', 'visible', [val, $input.offsetWidth]);
155+
}
153156
}
154157
},
155158
methods: {
@@ -248,15 +251,19 @@
248251
suggestion.scrollTop -= highlightItem.scrollHeight;
249252
}
250253
this.highlightedIndex = index;
251-
this.$el.querySelector('.el-input__inner').setAttribute('aria-activedescendant', `${this.id}-item-${this.highlightedIndex}`);
254+
let $input = this.getInput();
255+
$input.setAttribute('aria-activedescendant', `${this.id}-item-${this.highlightedIndex}`);
256+
},
257+
getInput() {
258+
return this.$refs.input.getInput();
252259
}
253260
},
254261
mounted() {
255262
this.debouncedGetData = debounce(this.debounce, this.getData);
256263
this.$on('item-click', item => {
257264
this.select(item);
258265
});
259-
let $input = this.$el.querySelector('.el-input__inner');
266+
let $input = this.getInput();
260267
$input.setAttribute('role', 'textbox');
261268
$input.setAttribute('aria-autocomplete', 'list');
262269
$input.setAttribute('aria-controls', 'id');

packages/input/src/input.vue

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,10 @@
221221
222222
methods: {
223223
focus() {
224-
(this.$refs.input || this.$refs.textarea).focus();
224+
this.getInput().focus();
225225
},
226226
blur() {
227-
(this.$refs.input || this.$refs.textarea).blur();
227+
this.getInput().blur();
228228
},
229229
getMigratingConfig() {
230230
return {
@@ -245,7 +245,7 @@
245245
}
246246
},
247247
select() {
248-
(this.$refs.input || this.$refs.textarea).select();
248+
this.getInput().select();
249249
},
250250
resizeTextarea() {
251251
if (this.$isServer) return;
@@ -286,7 +286,10 @@
286286
287287
// set input's value, in case parent refuses the change
288288
// see: https://github.com/ElemeFE/element/issues/12850
289-
this.$nextTick(() => { this.$refs.input.value = this.value; });
289+
this.$nextTick(() => {
290+
let input = this.getInput();
291+
input.value = this.value;
292+
});
290293
},
291294
handleChange(event) {
292295
this.$emit('change', event.target.value);
@@ -322,6 +325,9 @@
322325
this.$emit('input', '');
323326
this.$emit('change', '');
324327
this.$emit('clear');
328+
},
329+
getInput() {
330+
return this.$refs.input || this.$refs.textarea;
325331
}
326332
},
327333

0 commit comments

Comments
 (0)