@atlaskit/drawer
Version:
A drawer is a panel that slides in from the left side of the screen.
37 lines (36 loc) • 1.18 kB
JavaScript
import React from 'react';
// eslint-disable-next-line @atlaskit/design-system/no-third-party-focus-traps -- existing usage from before this rule was added
import ReactFocusLock from 'react-focus-lock';
/**
* __Focus lock__
*
* Thin wrapper around react-focus-lock.
*/
const FocusLock = ({
isFocusLockEnabled = true,
autoFocusFirstElem = true,
shouldReturnFocus = true,
children
}) => {
const getFocusTarget = () => {
if (typeof shouldReturnFocus === 'boolean') {
return shouldReturnFocus;
}
return false;
};
const onDeactivation = () => {
if (typeof shouldReturnFocus !== 'boolean') {
window.setTimeout(() => {
var _shouldReturnFocus$cu;
shouldReturnFocus === null || shouldReturnFocus === void 0 ? void 0 : (_shouldReturnFocus$cu = shouldReturnFocus.current) === null || _shouldReturnFocus$cu === void 0 ? void 0 : _shouldReturnFocus$cu.focus();
}, 0);
}
};
return /*#__PURE__*/React.createElement(ReactFocusLock, {
disabled: !isFocusLockEnabled,
autoFocus: autoFocusFirstElem,
returnFocus: getFocusTarget(),
onDeactivation: onDeactivation
}, children);
};
export default FocusLock;