useOpenAndCloseFocus
A utility hook that focuses an element when a component is first mounted and returns focus to another element when the component unmounts.
Examples
Default
Custom first focused element
If no ref is passed to initialFocusRef
, the hook focuses the first focusable element inside of the container.
If preventFocusOnOpen
prop is passed, then no focus will be applied when component mounts, even if initialFocusRef
prop is included. Only initial focus is prevented; focus will still be returned to returnFocusRef
when component unmounts.
Prevent focus in the container when it is opened
API
Loading data for useOpenAndCloseFocus...