tsimport {useFocusTrap} from '@astryxdesign/core/hooks'
| Guidance | Practices |
|---|---|
| Do | Call focusFirst() when opening a dialog/modal to move focus into the trapped region. |
| Do | Provide an onEscape callback to close the dialog when Escape is pressed. |
| Don't | Use on non-modal content like tooltips or dropdowns; those need light-dismiss, not focus trapping. |
| Param | Type | Description |
|---|---|---|
optionsrequired | UseFocusTrapOptions | Configuration object for the focus trap. |
options.isActiverequired | boolean | Whether the focus trap is currently active. |
options.onEscape | () => void | Callback when Escape key is pressed inside the trapped container. |
| Field | Type | Description |
|---|---|---|
| containerRef | React.RefObject<HTMLElement | null> | Ref to attach to the container element that should trap focus. |
| focusFirst | () => void | Focuses the first focusable element inside the container. |