UNPKG

@veracity/vui

Version:

Veracity UI is a React component library crafted for use within Veracity applications and pages. Based on Styled Components and @xstyled.

35 lines (33 loc) 1.11 kB
import { useCallback } from "react"; import { jsx } from "react/jsx-runtime"; import ReactFocusLock from "react-focus-lock"; //#region src/focusLock/focusLock.tsx /** * Traps the focus within the provided content. * * Tabbing using the keyboard will only cycle through the children and won't leave the boundary of the FocusLock wrapper. */ const FocusLock = (props) => { const { autoFocus, children, crossFrame, finalFocusRef, initialFocusRef, isDisabled, persistentFocus, returnFocus: returnFocusProp } = props; const onActivation = useCallback(() => { initialFocusRef?.current?.focus(); }, [initialFocusRef]); const onDeactivation = useCallback(() => { finalFocusRef?.current?.focus(); }, [finalFocusRef]); return /* @__PURE__ */ jsx(ReactFocusLock, { autoFocus, crossFrame, disabled: isDisabled, onActivation, onDeactivation, persistentFocus, returnFocus: returnFocusProp && !finalFocusRef, children }); }; FocusLock.displayName = "FocusLock"; //#endregion export { FocusLock, FocusLock as default }; globalThis.__vuiVersion__ = "5.3.1" //# sourceMappingURL=focusLock.js.map