Skip to content

Commit

Permalink
fix(Listbox): check if a dom is still associated with the document (#…
Browse files Browse the repository at this point in the history
…1331)

* fix(Listbox): check if a dom is still associated with the document

* fix(Listbox): remove redundant code

* fix(Listbox): fix type

* fix(Listbox): focusout should be async
  • Loading branch information
sunnylost authored Oct 1, 2024
1 parent 18e5468 commit f76856a
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/radix-vue/src/Listbox/ListboxRoot.vue
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,12 @@ function onKeydownTypeAhead(event: KeyboardEvent) {
}
function onLeave(event: Event) {
previousElement.value = highlightedElement.value
const el = highlightedElement.value
if ((el as Node)?.isConnected) {
previousElement.value = el
}
highlightedElement.value = null
emits('leave', event)
}
Expand Down Expand Up @@ -326,8 +331,9 @@ provideListboxRootContext({
:dir="dir"
:data-disabled="disabled ? '' : undefined"
@pointerleave="onLeave"
@focusout="(event: FocusEvent) => {
@focusout="async (event: FocusEvent) => {
const target = (event.relatedTarget || event.target) as HTMLElement | null
await nextTick()
if (highlightedElement && !currentElement.contains(target)) {
onLeave(event)
}
Expand Down

0 comments on commit f76856a

Please sign in to comment.