Skip to content

Commit

Permalink
fix: dialog focus trap
Browse files Browse the repository at this point in the history
  • Loading branch information
segunadebayo committed Dec 5, 2024
1 parent a958403 commit 12db1b1
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/machines/dialog/src/dialog.machine.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ariaHidden } from "@zag-js/aria-hidden"
import { createMachine } from "@zag-js/core"
import { trackDismissableElement } from "@zag-js/dismissable"
import { nextTick, raf } from "@zag-js/dom-query"
import { raf } from "@zag-js/dom-query"
import { preventBodyScroll } from "@zag-js/remove-scroll"
import { compact } from "@zag-js/utils"
import { createFocusTrap, type FocusTrap } from "focus-trap"
Expand Down Expand Up @@ -134,13 +134,14 @@ export function machine(userContext: UserDefinedContext) {
if (!ctx.trapFocus || !ctx.modal) return
let trap: FocusTrap

const cleanup = nextTick(() => {
const cleanup = raf(() => {
const contentEl = dom.getContentEl(ctx)
if (!contentEl) return
trap = createFocusTrap(contentEl, {
document: dom.getDoc(ctx),
escapeDeactivates: false,
preventScroll: true,
delayInitialFocus: false,
fallbackFocus: contentEl,
returnFocusOnDeactivate: !!ctx.restoreFocus,
allowOutsideClick: true,
Expand Down

0 comments on commit 12db1b1

Please sign in to comment.