UNPKG

@awsui/components-react

Version:

On July 19th, 2022, we launched [Cloudscape Design System](https://cloudscape.design). Cloudscape is an evolution of AWS-UI. It consists of user interface guidelines, front-end components, design resources, and development tools for building intuitive, en

54 lines 1.98 kB
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 // Credits to // https://github.com/theKashey/focus-lock/blob/33f8b4bd9675d2605b15e2e4015b77fe35fbd6d0/src/utils/tabbables.ts const tabbables = [ 'button:enabled', 'select:enabled', 'textarea:enabled', 'input:enabled', 'a[href]', 'area[href]', 'summary', 'iframe', 'object', 'embed', 'audio[controls]', 'video[controls]', '[tabindex]', '[contenteditable]', '[autofocus]', ].join(','); /** Whether the element or any of its ancestors are not hidden. */ function isVisible(element) { if (!('checkVisibility' in element)) { // checkVisibility isn't defined in JSDOM. It's safer to assume everything is visible. return true; } // checkVisibility is only defined on element in Typescript 5+ // See https://github.com/puppeteer/puppeteer/issues/11059 return element.checkVisibility({ visibilityProperty: true }); } /** Whether the element can be focused. */ export function isFocusable(element) { return element.matches(tabbables) && isVisible(element); } /** Get all elements that can be focused, either programmatically or by the user. */ export function getAllFocusables(container) { return Array.from(container.querySelectorAll(tabbables)).filter(isVisible); } /** Get all focusable elements that can be reached with the keyboard. */ function getAllTabbables(container) { return getAllFocusables(container).filter((element) => element.tabIndex !== -1); } export function getFirstFocusable(container) { var _a; const tabbables = getAllTabbables(container); return (_a = tabbables[0]) !== null && _a !== void 0 ? _a : null; } export function getLastFocusable(container) { var _a; const tabbables = getAllTabbables(container); return (_a = tabbables[tabbables.length - 1]) !== null && _a !== void 0 ? _a : null; } //# sourceMappingURL=utils.js.map