"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.FocusLock = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const react_focus_lock_1 = __importDefault(require("react-focus-lock"));
/**
 * 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 = (0, react_1.useCallback)(() => {
        var _a;
        (_a = initialFocusRef === null || initialFocusRef === void 0 ? void 0 : initialFocusRef.current) === null || _a === void 0 ? void 0 : _a.focus();
    }, [initialFocusRef]);
    const onDeactivation = (0, react_1.useCallback)(() => {
        var _a;
        (_a = finalFocusRef === null || finalFocusRef === void 0 ? void 0 : finalFocusRef.current) === null || _a === void 0 ? void 0 : _a.focus();
    }, [finalFocusRef]);
    const returnFocus = returnFocusProp && !finalFocusRef;
    return ((0, jsx_runtime_1.jsx)(react_focus_lock_1.default, { autoFocus: autoFocus, crossFrame: crossFrame, disabled: isDisabled, onActivation: onActivation, onDeactivation: onDeactivation, persistentFocus: persistentFocus, returnFocus: returnFocus, children: children }));
};
exports.FocusLock = FocusLock;
exports.FocusLock.displayName = 'FocusLock';
exports.default = exports.FocusLock;
//# sourceMappingURL=focusLock.js.map