@yamada-ui/react
Version:
React UI components of the Yamada, by the Yamada, for the Yamada built with React and Emotion
44 lines (40 loc) • 1.81 kB
JavaScript
"use client";
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
const require_utils_index = require('../../utils/index.cjs');
let react = require("react");
react = require_rolldown_runtime.__toESM(react);
let react_jsx_runtime = require("react/jsx-runtime");
react_jsx_runtime = require_rolldown_runtime.__toESM(react_jsx_runtime);
let react_focus_lock = require("react-focus-lock");
react_focus_lock = require_rolldown_runtime.__toESM(react_focus_lock);
//#region src/components/focus-lock/focus-lock.tsx
const InternalFocusLock = (0, require_utils_index.utils_exports.interopDefault)(react_focus_lock.default);
/**
* `FocusLock` is a component that improves accessibility by restricting focus within elements such as modals and dialogs, and locking the focus within that range.
*
* @see https://yamada-ui.com/docs/components/focus-lock
*/
const FocusLock = ({ autoFocus, children, contentRef, disabled, finalFocusRef, initialFocusRef, lockFocusAcrossFrames, persistentFocus, restoreFocus }) => {
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(InternalFocusLock, {
autoFocus,
crossFrame: lockFocusAcrossFrames,
disabled,
persistentFocus,
returnFocus: restoreFocus && !finalFocusRef,
onActivation: (0, react.useCallback)(() => {
if (initialFocusRef?.current) initialFocusRef.current.focus();
else if (contentRef?.current) {
if ((0, require_utils_index.utils_exports.getFocusableElements)(contentRef.current).length === 0) requestAnimationFrame(() => {
contentRef.current?.focus();
});
}
}, [initialFocusRef, contentRef]),
onDeactivation: (0, react.useCallback)(() => {
finalFocusRef?.current?.focus();
}, [finalFocusRef]),
children
});
};
//#endregion
exports.FocusLock = FocusLock;
//# sourceMappingURL=focus-lock.cjs.map