1 line
7.0 KiB
JSON
1 line
7.0 KiB
JSON
|
{"ast":null,"code":"import KeyCode from \"rc-util/es/KeyCode\";\nimport raf from \"rc-util/es/raf\";\nimport * as React from \"react\";\nvar ESC = KeyCode.ESC,\n TAB = KeyCode.TAB;\nexport default function useAccessibility(_ref) {\n var visible = _ref.visible,\n triggerRef = _ref.triggerRef,\n onVisibleChange = _ref.onVisibleChange,\n autoFocus = _ref.autoFocus,\n overlayRef = _ref.overlayRef;\n var focusMenuRef = React.useRef(false);\n var handleCloseMenuAndReturnFocus = function handleCloseMenuAndReturnFocus() {\n if (visible) {\n var _triggerRef$current, _triggerRef$current$f;\n (_triggerRef$current = triggerRef.current) === null || _triggerRef$current === void 0 || (_triggerRef$current$f = _triggerRef$current.focus) === null || _triggerRef$current$f === void 0 || _triggerRef$current$f.call(_triggerRef$current);\n onVisibleChange === null || onVisibleChange === void 0 || onVisibleChange(false);\n }\n };\n var focusMenu = function focusMenu() {\n var _overlayRef$current;\n if ((_overlayRef$current = overlayRef.current) !== null && _overlayRef$current !== void 0 && _overlayRef$current.focus) {\n overlayRef.current.focus();\n focusMenuRef.current = true;\n return true;\n }\n return false;\n };\n var handleKeyDown = function handleKeyDown(event) {\n switch (event.keyCode) {\n case ESC:\n handleCloseMenuAndReturnFocus();\n break;\n case TAB:\n {\n var focusResult = false;\n if (!focusMenuRef.current) {\n focusResult = focusMenu();\n }\n if (focusResult) {\n event.preventDefault();\n } else {\n handleCloseMenuAndReturnFocus();\n }\n break;\n }\n }\n };\n React.useEffect(function () {\n if (visible) {\n window.addEventListener(\"keydown\", handleKeyDown);\n if (autoFocus) {\n // FIXME: hack with raf\n raf(focusMenu, 3);\n }\n return function () {\n window.removeEventListener(\"keydown\", handleKeyDown);\n focusMenuRef.current = false;\n };\n }\n return function () {\n focusMenuRef.current = false;\n };\n }, [visible]); // eslint-disable-line react-hooks/exhaustive-deps\n}","map":{"version":3,"names":["KeyCode","raf","React","ESC","TAB","useAccessibility","_ref","visible","triggerRef","onVisibleChange","autoFocus","overlayRef","focusMenuRef","useRef","handleCloseMenuAndReturnFocus","_triggerRef$current","_triggerRef$current$f","current","focus","call","focusMenu","_overlayRef$current","handleKeyDown","event","keyCode","focusResult","preventDefault","useEffect","window","addEventListener","removeEventListener"],"sources":["C:/Users/Аришина)/source/repos/PromoCursed/node_modules/rc-dropdown/es/hooks/useAccessibility.js"],"sourcesContent":["import KeyCode from \"rc-util/es/KeyCode\";\nimport raf from \"rc-util/es/raf\";\nimport * as React from \"react\";\nvar ESC = KeyCode.ESC,\n TAB = KeyCode.TAB;\nexport default function useAccessibility(_ref) {\n var visible = _ref.visible,\n triggerRef = _ref.triggerRef,\n onVisibleChange = _ref.onVisibleChange,\n autoFocus = _ref.autoFocus,\n overlayRef = _ref.overlayRef;\n var focusMenuRef = React.useRef(false);\n var handleCloseMenuAndReturnFocus = function handleCloseMenuAndReturnFocus() {\n if (visible) {\n var _triggerRef$current, _triggerRef$current$f;\n (_triggerRef$current = triggerRef.current) === null || _triggerRef$current === void 0 || (_triggerRef$current$f = _triggerRef$current.focus) === null || _triggerRef$current$f === void 0 || _triggerRef$current$f.call(_triggerRef$current);\n onVisibleChange === null || onVisibleChange === void 0 || onVisibleChange(false);\n }\n };\n var focusMenu = function focusMenu() {\n var _overlayRef$current;\n if ((_overlayRef$current = overlayRef.current) !== null && _overlayRef$current !== void 0 && _overlayRef$current.focus) {\n overlayRef.current.focus();\n focusMenuRef.current = true;\n return true;\
|