@primer/react
Version:
An implementation of GitHub's Primer Design System using React
56 lines (52 loc) • 1.72 kB
JavaScript
var reactCompilerRuntime = require('react-compiler-runtime');
var React = require('react');
var utils = require('@primer/behaviors/utils');
function useOpenAndCloseFocus(t0) {
const $ = reactCompilerRuntime.c(10);
const {
initialFocusRef,
returnFocusRef,
containerRef,
preventFocusOnOpen
} = t0;
let t1;
if ($[0] !== containerRef || $[1] !== initialFocusRef || $[2] !== preventFocusOnOpen || $[3] !== returnFocusRef.current) {
t1 = () => {
if (!preventFocusOnOpen) {
if (initialFocusRef && initialFocusRef.current) {
initialFocusRef.current.focus();
} else {
if (containerRef.current) {
const firstItem = utils.iterateFocusableElements(containerRef.current).next().value;
firstItem === null || firstItem === void 0 ? void 0 : firstItem.focus();
}
}
}
const returnFocusRefCurrent = returnFocusRef.current;
return function () {
returnFocusRefCurrent === null || returnFocusRefCurrent === void 0 ? void 0 : returnFocusRefCurrent.focus();
};
};
$[0] = containerRef;
$[1] = initialFocusRef;
$[2] = preventFocusOnOpen;
$[3] = returnFocusRef.current;
$[4] = t1;
} else {
t1 = $[4];
}
let t2;
if ($[5] !== containerRef || $[6] !== initialFocusRef || $[7] !== preventFocusOnOpen || $[8] !== returnFocusRef) {
t2 = [initialFocusRef, returnFocusRef, containerRef, preventFocusOnOpen];
$[5] = containerRef;
$[6] = initialFocusRef;
$[7] = preventFocusOnOpen;
$[8] = returnFocusRef;
$[9] = t2;
} else {
t2 = $[9];
}
React.useEffect(t1, t2);
}
exports.useOpenAndCloseFocus = useOpenAndCloseFocus;
;