useFocusManager
API
import useFocusManager from '@restart/hooks/useFocusManager'
useFocusManager
(opts: FocusManagerOptions) => FocusControlleruseFocusManager provides a way to track and manage focus as it moves around a container element. An
onChange
is fired when focus enters or leaves the element, but not when it moves around inside the element, similar topointerenter
andpointerleave
DOM events.const [focused, setFocusState] = useState(false)const { onBlur, onFocus } = useFocusManager({onChange: nextFocused => setFocusState(nextFocused)})return (<div tabIndex="-1" onFocus={onFocus} onBlur={onBlur}>{String(focused)}<input /><input /><button>A button</button></div>Parameters
opts
FocusManagerOptionsisDisabled
() => booleanWhen true, the event handlers will not report focus changes
didHandle
(focused: boolean, event: FocusEvent) => voidonChange
(focused: boolean, event: FocusEvent) => voidwillHandle
(focused: boolean, event: FocusEvent) => boolean | void
Return Value FocusController
a memoized FocusController containing event handlers