diff --git a/bun.lockb b/bun.lockb index 30526693bc..b3e6522a87 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/packages/react/package.json b/packages/react/package.json index fc66c6ca3d..40c3e1b0a1 100644 --- a/packages/react/package.json +++ b/packages/react/package.json @@ -187,6 +187,7 @@ "@zag-js/dom-query": "0.81.0", "@zag-js/editable": "0.81.0", "@zag-js/file-upload": "0.81.0", + "@zag-js/focus-trap": "0.81.0", "@zag-js/file-utils": "0.81.0", "@zag-js/highlight-word": "0.81.0", "@zag-js/hover-card": "0.81.0", diff --git a/packages/react/src/components/focus-trap/examples/autofocus.tsx b/packages/react/src/components/focus-trap/examples/autofocus.tsx new file mode 100644 index 0000000000..b2e14fae78 --- /dev/null +++ b/packages/react/src/components/focus-trap/examples/autofocus.tsx @@ -0,0 +1,34 @@ +import { useRef, useState } from 'react' +import { FocusTrap } from '../focus-trap' + +export const Autofocus = () => { + const [trapped, setTrapped] = useState(false) + const toggle = () => setTrapped((c) => !c) + + const buttonRef = useRef(null) + const getButtonNode = () => { + const node = buttonRef.current + if (!node) throw new Error('Button not found') + return node + } + + return ( +
+ + {trapped && ( + +
+ + {/* biome-ignore lint/a11y/noAutofocus: */} + + +
+
+ )} +
+ ) +} diff --git a/packages/react/src/components/focus-trap/examples/basic.tsx b/packages/react/src/components/focus-trap/examples/basic.tsx new file mode 100644 index 0000000000..1a625d4724 --- /dev/null +++ b/packages/react/src/components/focus-trap/examples/basic.tsx @@ -0,0 +1,20 @@ +import { useState } from 'react' +import { FocusTrap } from '../focus-trap' + +export const Basic = () => { + const [trapped, setTrapped] = useState(false) + return ( + <> + + +
+ +