Primer React hooks

Usage and code-level documentation for Primer React's hooks.

useAnchoredPosition

Used to calculate the position of a "floating" element that is anchored to another element.

useFocusTrap

Used prevent focus from leaving a particular element.

useFocusZone

Used to designate a container where focus can be moved using keys other than Tab.

useOnEscapePress

A simple utility Hook that calls a user-provided function when the Escape key is pressed.

useOnOutsideClick

A utility Hook that calls a user-provided callback function when the user clicks outside of the provided container.

useOpenAndCloseFocus

A utility Hook that focuses an element when a component is first mounted and returns focus to another element when the component unmounts.

useOverlay

Provides all relevant Overlay behavior and provides a ref for the overlay's container.

useSafeTimeout

A utility Hook that allows safely calling setTimeout and clearTimeout within a component.