You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: content/guides/react/hooks/use-open-and-close-focus.mdx
+12-9
Original file line number
Diff line number
Diff line change
@@ -5,14 +5,16 @@ description: A utility Hook that focuses an element when a component is first mo
5
5
6
6
`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.
7
7
8
-
If no ref is passed to `initialFocusRef` , the hook focuses the first focusable element inside of the container.
8
+
If no ref is passed to `initialFocusRef`, the hook focuses the first focusable element inside of the container.
9
+
10
+
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.
| onEscapePress |`function`| required | Function to call when user presses the Escape key |
61
-
| onOutsideClick |`function`| required | Function to call when user clicks outside of the overlay |
62
-
| ignoreClickRefs |`React.RefObject<HTMLElement> []`| optional | Refs to click clicks on in the `onOutsideClick` function, useful for ignoring clicks on elements that trigger the overlay visibility. |
63
-
| initialFocusRef |`React.RefObject<HTMLElement>`| optional | Ref to focus when overlay is mounted. |
64
-
| returnFocusRef |`React.RefObject<HTMLElement>`| required | Ref to focus when overlay is unmounted. Important for accessibility. |
| onEscapePress |`function`| required | Function to call when user presses the Escape key |
62
+
| onOutsideClick |`function`| required | Function to call when user clicks outside of the overlay |
63
+
| ignoreClickRefs |`React.RefObject<HTMLElement> []`| optional | Refs to click clicks on in the `onOutsideClick` function, useful for ignoring clicks on elements that trigger the overlay visibility. |
64
+
| initialFocusRef |`React.RefObject<HTMLElement>`| optional | Ref to focus when overlay is mounted. |
65
+
| returnFocusRef |`React.RefObject<HTMLElement>`| required | Ref to focus when overlay is unmounted. Important for accessibility. |
66
+
| preventFocusOnOpen | `boolean` | optional | When true, prevents focus when overlay is mounted, even if `initialFocusRef` is present.
0 commit comments