Skip to content
Entangle UI v0.13.0

useFocusTrap

useFocusTrap(__namedParameters): (event) => void

Defined in: src/hooks/useFocusTrap/useFocusTrap.ts:41

Trap focus within a container element. Tab and Shift+Tab cycle through the focusable descendants without escaping the container.

Returns a keyboard event handler to attach to the container’s onKeyDown.

UseFocusTrapOptions

(event) => void

const ref = useRef<HTMLDivElement>(null);
const handleKeyDown = useFocusTrap({ containerRef: ref, enabled: isOpen });
return <div ref={ref} onKeyDown={handleKeyDown}>...</div>;