react-aria
Version:
Spectrum UI components in React
1 lines • 2.92 kB
Source Map (JSON)
{"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;AAaM,SAAS,0CAAY,OAAyB;IACnD,IAAI,CAAC,QAAQ,WAAW,EACtB;IAGF,6EAA6E;IAC7E,4EAA4E;IAC5E,2EAA2E;IAC3E,+EAA+E;IAC/E,uBAAuB;IACvB,MAAM,gBAAgB,CAAA,GAAA,0CAAe,EAAE;IACvC,IAAI,CAAA,GAAA,gDAAqB,QAAQ,WAAW;QAC1C,IAAI,qBAAqB,CAAA,GAAA,0CAAe,EAAE;QAC1C,CAAA,GAAA,4CAAiB,EAAE;YACjB,MAAM,gBAAgB,CAAA,GAAA,0CAAe,EAAE;YACvC,2GAA2G;YAC3G,IACE,AAAC,CAAA,kBAAkB,sBAAsB,kBAAkB,cAAc,IAAI,AAAD,KAC5E,QAAQ,WAAW,EAEnB,CAAA,GAAA,+CAAoB,EAAE;QAE1B;IACF,OACE,CAAA,GAAA,+CAAoB,EAAE;AAE1B","sources":["packages/react-aria/src/interactions/focusSafely.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the 'License');\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {FocusableElement} from '@react-types/shared';\nimport {focusWithoutScrolling} from '../utils/focusWithoutScrolling';\nimport {getActiveElement} from '../utils/shadowdom/DOMFunctions';\nimport {getInteractionModality} from './useFocusVisible';\nimport {getOwnerDocument} from '../utils/domHelpers';\nimport {runAfterTransition} from '../utils/runAfterTransition';\n\n/**\n * A utility function that focuses an element while avoiding undesired side effects such\n * as page scrolling and screen reader issues with CSS transitions.\n */\nexport function focusSafely(element: FocusableElement): void {\n if (!element.isConnected) {\n return;\n }\n\n // If the user is interacting with a virtual cursor, e.g. screen reader, then\n // wait until after any animated transitions that are currently occurring on\n // the page before shifting focus. This avoids issues with VoiceOver on iOS\n // causing the page to scroll when moving focus if the element is transitioning\n // from off the screen.\n const ownerDocument = getOwnerDocument(element);\n if (getInteractionModality() === 'virtual') {\n let lastFocusedElement = getActiveElement(ownerDocument);\n runAfterTransition(() => {\n const activeElement = getActiveElement(ownerDocument);\n // If focus did not move or focus was lost to the body, and the element is still in the document, focus it.\n if (\n (activeElement === lastFocusedElement || activeElement === ownerDocument.body) &&\n element.isConnected\n ) {\n focusWithoutScrolling(element);\n }\n });\n } else {\n focusWithoutScrolling(element);\n }\n}\n"],"names":[],"version":3,"file":"focusSafely.cjs.map"}