Skip to content

Commit ffde59c

Browse files
zernoniaclaude
andauthored
fix(Listbox): restore highlightOnHover behavior (#2558)
* fix(Listbox): restore highlightOnHover behavior broken by focusable guard The pointermove handler in ListboxItem incorrectly gated highlighting on `!focusable.value`, but focusable is always `true`, so highlightOnHover never triggered. Add an optional `focus` parameter to `changeHighlight` and pass `false` on hover to update the highlight without stealing DOM focus. Fixes #2556 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix(Listbox): guard collection.at(-1) against undefined Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix(Listbox): replace .at(-1) with index-based last element access Disable unicorn/prefer-at ESLint rule to avoid auto-revert. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix(Listbox): replace .at(-1) with index-based last element access Disable e18e/prefer-array-at ESLint rule to prevent auto-revert. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * chore: revert eslint prefer-at overrides, restore .at(-1) usage Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix(Listbox): read focusable.value inside changeHighlight instead of as default param Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix(Listbox): guard collection[0] against undefined for kbd.HOME Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent a987ad5 commit ffde59c

2 files changed

Lines changed: 10 additions & 8 deletions

File tree

packages/core/src/Listbox/ListboxItem.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ provideListboxItemContext({
9292
if (rootContext.highlightedElement.value === currentElement)
9393
return
9494
95-
if (rootContext.highlightOnHover.value && !rootContext.focusable.value)
96-
rootContext.changeHighlight(currentElement, false)
95+
if (rootContext.highlightOnHover.value)
96+
rootContext.changeHighlight(currentElement, false, false)
9797
}"
9898
>
9999
<slot />

packages/core/src/Listbox/ListboxRoot.vue

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ type ListboxRootContext<T> = {
2727
2828
onLeave: (event: Event) => void
2929
onEnter: (event: Event) => void
30-
changeHighlight: (el: HTMLElement, scrollIntoView?: boolean) => void
30+
changeHighlight: (el: HTMLElement, scrollIntoView?: boolean, focus?: boolean) => void
3131
onKeydownNavigation: (event: KeyboardEvent) => void
3232
onKeydownEnter: (event: KeyboardEvent) => void
3333
onKeydownTypeAhead: (event: KeyboardEvent) => void
@@ -157,12 +157,12 @@ function getCollectionItem() {
157157
return getItems().map(i => i.ref).filter(i => i.dataset.disabled !== '')
158158
}
159159
160-
function changeHighlight(el: HTMLElement, scrollIntoView = true) {
160+
function changeHighlight(el: HTMLElement, scrollIntoView = true, focus?: boolean) {
161161
if (!el)
162162
return
163163
164164
highlightedElement.value = el
165-
if (focusable.value)
165+
if (focus ?? focusable.value)
166166
highlightedElement.value.focus()
167167
if (scrollIntoView)
168168
highlightedElement.value.scrollIntoView({ block: 'nearest' })
@@ -211,7 +211,9 @@ function onKeydownTypeAhead(event: KeyboardEvent) {
211211
const values = collection.map(i => i.value)
212212
modelValue.value = [...values]
213213
event.preventDefault()
214-
changeHighlight(collection[collection.length - 1].ref)
214+
const lastItem = collection.at(-1)
215+
if (lastItem)
216+
changeHighlight(lastItem.ref)
215217
}
216218
else if (!isMetaKey) {
217219
const el = handleTypeaheadSearch(event.key, getItems())
@@ -309,9 +311,9 @@ function handleMultipleReplace(event: KeyboardEvent, targetEl: HTMLElement) {
309311
let lastValue = collection.find(i => i.ref === targetEl)?.value
310312
311313
if (event.key === kbd.END)
312-
lastValue = collection[collection.length - 1].value
314+
lastValue = collection.at(-1)?.value
313315
else if (event.key === kbd.HOME)
314-
lastValue = collection[0].value
316+
lastValue = collection[0]?.value
315317
316318
if (!lastValue || !firstValue.value)
317319
return

0 commit comments

Comments
 (0)