useOpenAndCloseFocus
A utility Hook that focuses an element when a component is first mounted and returns focus to another element when the component unmounts.
useOpenAndCloseFocus
is a utility Hook that manages focusing an element when a component is first mounted, and returns focus to an element on the page when that component unmounts.
If no ref is passed to initialFocusRef
, the hook focuses the first focusable element inside of the container.
Usage
useOpenAndCloseFocus settings
Name | Type | Default | Description |
---|---|---|---|
initialFocusRef | React.RefObject<HTMLElement> | Optional. The element to focus when the container is mounted on the page. | |
returnFocusRef | React.RefObject<HTMLElement> | Required. The element to focus when the container is unmounted. | |
containerRef | React.RefObject<HTMLElement> | Required. A ref for the containing element. |