1 line
1.1 KiB
Plaintext
1 line
1.1 KiB
Plaintext
{"version":3,"sources":["../src/use-focus-effect.ts"],"sourcesContent":["import { hasFocusWithin, focus } from \"@chakra-ui/utils\"\nimport { useUpdateEffect } from \"./use-update-effect\"\n\nexport type UseFocusEffectOptions = {\n shouldFocus: boolean\n preventScroll?: boolean\n}\n/**\n * React hook to focus an element conditionally\n *\n * @param ref the ref of the element to focus\n * @param options focus management options\n */\nexport function useFocusEffect<T extends HTMLElement>(\n ref: React.RefObject<T>,\n options: UseFocusEffectOptions,\n) {\n const { shouldFocus, preventScroll } = options\n\n useUpdateEffect(() => {\n const node = ref.current\n\n if (!node || !shouldFocus) return\n\n if (!hasFocusWithin(node)) {\n focus(node, { preventScroll, nextTick: true })\n }\n }, [shouldFocus, ref, preventScroll])\n}\n"],"mappings":";;;;;;AAAA,SAAS,gBAAgB,aAAa;AAa/B,SAAS,eACd,KACA,SACA;AACA,QAAM,EAAE,aAAa,cAAc,IAAI;AAEvC,kBAAgB,MAAM;AACpB,UAAM,OAAO,IAAI;AAEjB,QAAI,CAAC,QAAQ,CAAC;AAAa;AAE3B,QAAI,CAAC,eAAe,IAAI,GAAG;AACzB,YAAM,MAAM,EAAE,eAAe,UAAU,KAAK,CAAC;AAAA,IAC/C;AAAA,EACF,GAAG,CAAC,aAAa,KAAK,aAAa,CAAC;AACtC;","names":[]} |