UNPKG

@kwiz/fluentui

Version:
17 lines 742 B
import { useEffect } from "react"; import { useRefWithState } from "./hooks"; /** better auto-focus that actually works. use the ref on the element you wish to focus. * focus set initially, and then again on a timeout - default is 200ms timeout. send 0 to skip the timeout */ export function useAutoFocusEX({ timeout } = { timeout: 200 }) { const focusableRef = useRefWithState(); useEffect(() => { if (focusableRef.ref.current) { focusableRef.ref.current.focus(); if (timeout > 0) window.setTimeout(() => focusableRef.ref.current.focus(), timeout); } }, [focusableRef.value, timeout]); return { set: focusableRef.set }; } //# sourceMappingURL=use-auto-focus-ex.js.map