UNPKG

@atlaskit/drawer

Version:

A drawer is a panel that slides in from the left side of the screen.

35 lines • 1.05 kB
import React from 'react'; 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;