From 6d8aa4516753e6236275ecca2557751e46d7eb6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Mich=C3=A1lek?= Date: Thu, 20 Feb 2025 06:00:47 +0100 Subject: [PATCH] fix(select): auto focus option in autoUpdateModel This makes sure that the first option gets focused after the select is open and also if the options are changes in cases where the options are being loaded and passed to the select at a later point. --- packages/primevue/src/select/Select.vue | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/primevue/src/select/Select.vue b/packages/primevue/src/select/Select.vue index ddebf8af3..3f0cb970c 100755 --- a/packages/primevue/src/select/Select.vue +++ b/packages/primevue/src/select/Select.vue @@ -686,7 +686,7 @@ export default { setTimeout(() => { this.autoFilterFocus && this.filter && focus(this.$refs.filterInput.$el); - this.focusedOptionIndex = this.focusedOptionIndex !== -1 ? this.focusedOptionIndex : this.autoOptionFocus ? this.findFirstFocusedOptionIndex() : this.editable ? -1 : this.findSelectedOptionIndex(); + this.autoUpdateModel(); }, 1); }, onOverlayAfterEnter() { @@ -900,8 +900,11 @@ export default { }); }, autoUpdateModel() { - if (this.selectOnFocus && this.autoOptionFocus && !this.$filled) { + if (this.autoOptionFocus) { this.focusedOptionIndex = this.findFirstFocusedOptionIndex(); + } + + if (this.selectOnFocus && this.autoOptionFocus && !this.$filled) { this.onOptionSelect(null, this.visibleOptions[this.focusedOptionIndex], false); } },