Files
wdi-dashboard/node_modules/@chakra-ui/hooks/dist/chunk-4INTB4VC.mjs
2024-08-16 15:06:52 +05:30

45 lines
1.0 KiB
JavaScript

'use client'
import {
useUpdateEffect
} from "./chunk-6WEF4DIO.mjs";
// src/use-focus-on-hide.ts
import {
contains,
focus,
getActiveElement,
isTabbable
} from "@chakra-ui/utils";
function preventReturnFocus(containerRef) {
const el = containerRef.current;
if (!el)
return false;
const activeElement = getActiveElement(el);
if (!activeElement)
return false;
if (contains(el, activeElement))
return false;
if (isTabbable(activeElement))
return true;
return false;
}
function useFocusOnHide(containerRef, options) {
const { shouldFocus: shouldFocusProp, visible, focusRef } = options;
const shouldFocus = shouldFocusProp && !visible;
useUpdateEffect(() => {
if (!shouldFocus)
return;
if (preventReturnFocus(containerRef)) {
return;
}
const el = (focusRef == null ? void 0 : focusRef.current) || containerRef.current;
if (el) {
focus(el, { nextTick: true });
}
}, [shouldFocus, containerRef, focusRef]);
}
export {
useFocusOnHide
};
//# sourceMappingURL=chunk-4INTB4VC.mjs.map