Blueprint

Focus Lock

Lock focus to a particular element in the document

Import


import { FocusLock } from '@hover/blueprint';

Usage

Trap focus to a specific portion of the document. This is useful for modals, popovers, and other floating elements that appear above the page's content.


import FocusLock from '@hover/blueprint';
const JailForAFocus = ({ onClose }) => (
<FocusLock>
You can not leave this form
<button onClick={onClose} />
</FocusLock>
);

API

Note

This is Chakra's wrapper around the react-focus-lock library. See the @chakra-ui/focus-lock package and react-focus-lock documentation for more information.

OptionTypeDefaultDescription
initialFocusRefReact.RefObject<FocusableElement>-ref of the element to receive focus initially
finalFocusRefReact.RefObject<FocusableElement>-ref of the element to return focus to when FocusLock unmounts
contentRefReact.RefObject<HTMLElement>-The ref of the wrapper for which the focus-lock wraps
restoreFocusbooleanfalseIf true, focus will be restored to the element that triggered the FocusLock once it unmounts
childrenReact.ReactNode-The component to render
isDisabledbooleanfalseIf true, focus trapping will be disabled
autoFocusbooleanfalseIf true, the first focusable element within the children will auto-focused once FocusLock mounts
persistentFocusbooleanfalseIf true, disables text selections inside, and outside focus lock
lockFocusAcrossFramesbooleanfalseEnables aggressive focus capturing within iframes

Copyright © 2024 Hover Inc. All Rights Reserved.