Skip to content

Commit 6f8aaf6

Browse files
committed
fix: combobox focus and aria-hidden
1 parent 1b8ca28 commit 6f8aaf6

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@zag-js/combobox": patch
3+
---
4+
5+
- Fix focus stealing in controlled open mode
6+
- Remove problematic `aria-hidden` behavior to allow interaction with other page elements

packages/machines/combobox/src/combobox.machine.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { ariaHidden } from "@zag-js/aria-hidden"
21
import { setup } from "@zag-js/core"
32
import { trackDismissableElement } from "@zag-js/dismissable"
43
import { clickIfLink, nextTick, observeAttributes, raf, scrollIntoView, setCaretToEnd } from "@zag-js/dom-query"
@@ -350,7 +349,7 @@ export const machine = createMachine({
350349
interacting: {
351350
tags: ["open", "focused"],
352351
entry: ["setInitialFocus"],
353-
effects: ["scrollToHighlightedItem", "trackDismissableLayer", "trackPlacement", "hideOtherElements"],
352+
effects: ["scrollToHighlightedItem", "trackDismissableLayer", "trackPlacement"],
354353
on: {
355354
"CONTROLLED.CLOSE": [
356355
{
@@ -526,7 +525,7 @@ export const machine = createMachine({
526525

527526
suggesting: {
528527
tags: ["open", "focused"],
529-
effects: ["trackDismissableLayer", "scrollToHighlightedItem", "trackPlacement", "hideOtherElements"],
528+
effects: ["trackDismissableLayer", "scrollToHighlightedItem", "trackPlacement"],
530529
entry: ["setInitialFocus"],
531530
on: {
532531
"CONTROLLED.CLOSE": [
@@ -696,7 +695,10 @@ export const machine = createMachine({
696695
if (isBoolean(openOnChange)) return openOnChange
697696
return !!openOnChange?.({ inputValue: context.get("inputValue") })
698697
},
699-
restoreFocus: ({ event }) => (event.restoreFocus == null ? true : !!event.restoreFocus),
698+
restoreFocus: ({ event }) => {
699+
const restoreFocus = event.restoreFocus ?? event.previousEvent?.restoreFocus
700+
return restoreFocus == null ? true : !!restoreFocus
701+
},
700702
isChangeEvent: ({ event }) => event.previousEvent?.type === "INPUT.CHANGE",
701703
autoFocus: ({ prop }) => !!prop("autoFocus"),
702704
isHighlightedItemRemoved: ({ prop, context }) => !prop("collection").has(context.get("highlightedValue")),
@@ -723,14 +725,6 @@ export const machine = createMachine({
723725
},
724726
})
725727
},
726-
hideOtherElements({ scope }) {
727-
return ariaHidden([
728-
dom.getInputEl(scope),
729-
dom.getContentEl(scope),
730-
dom.getTriggerEl(scope),
731-
dom.getClearTriggerEl(scope),
732-
])
733-
},
734728
trackPlacement({ context, prop, scope }) {
735729
const anchorEl = () => dom.getControlEl(scope) || dom.getTriggerEl(scope)
736730
const positionerEl = () => dom.getPositionerEl(scope)

0 commit comments

Comments
 (0)