UNPKG

@atlaskit/drawer

Version:

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

37 lines • 1.45 kB
import React from 'react'; import ReactFocusLock from 'react-focus-lock'; /** * __Focus lock__ * * Thin wrapper around react-focus-lock. */ var FocusLock = function FocusLock(_ref) { var _ref$isFocusLockEnabl = _ref.isFocusLockEnabled, isFocusLockEnabled = _ref$isFocusLockEnabl === void 0 ? true : _ref$isFocusLockEnabl, _ref$autoFocusFirstEl = _ref.autoFocusFirstElem, autoFocusFirstElem = _ref$autoFocusFirstEl === void 0 ? true : _ref$autoFocusFirstEl, _ref$shouldReturnFocu = _ref.shouldReturnFocus, shouldReturnFocus = _ref$shouldReturnFocu === void 0 ? true : _ref$shouldReturnFocu, children = _ref.children; var getFocusTarget = function getFocusTarget() { if (typeof shouldReturnFocus === 'boolean') { return shouldReturnFocus; } return false; }; var onDeactivation = function onDeactivation() { if (typeof shouldReturnFocus !== 'boolean') { window.setTimeout(function () { var _shouldReturnFocus$cu; shouldReturnFocus === null || shouldReturnFocus === void 0 || (_shouldReturnFocus$cu = shouldReturnFocus.current) === null || _shouldReturnFocus$cu === void 0 || _shouldReturnFocus$cu.focus(); }, 0); } }; return /*#__PURE__*/React.createElement(ReactFocusLock, { disabled: !isFocusLockEnabled, autoFocus: autoFocusFirstElem, returnFocus: getFocusTarget(), onDeactivation: onDeactivation }, children); }; export default FocusLock;