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

96 lines 3.59 kB
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 export function getClosestCell(element) { return element.closest('td,th'); } export function isElementDisabled(element) { if (element instanceof HTMLInputElement || element instanceof HTMLButtonElement) { return element.disabled; } return false; } /** * Returns true if the target element or one of its parents is a dialog or is marked with data-awsui-table-suppress-navigation attribute. * This is used to suppress navigation for interactive content without a need to use a custom suppression check. */ export function defaultIsSuppressed(target) { let current = target; while (current) { // Stop checking for parents upon reaching the cell element as the function only aims at the cell content. if (isTableCell(current)) { return false; } if (current.getAttribute('role') === 'dialog' || current.getAttribute('data-awsui-table-suppress-navigation') === 'true') { return true; } current = current.parentElement; } return false; } /** * Finds the closest row to the targetAriaRowIndex+delta in the direction of delta. */ export function findTableRowByAriaRowIndex(table, targetAriaRowIndex, delta) { var _a; let targetRow = null; const rowElements = Array.from(table.querySelectorAll('tr[aria-rowindex]')); if (delta < 0) { rowElements.reverse(); } for (const element of rowElements) { const rowIndex = parseInt((_a = element.getAttribute('aria-rowindex')) !== null && _a !== void 0 ? _a : ''); targetRow = element; if (rowIndex === targetAriaRowIndex) { break; } if (delta >= 0 && rowIndex > targetAriaRowIndex) { break; } if (delta < 0 && rowIndex < targetAriaRowIndex) { break; } } return targetRow; } /** * Finds the closest column to the targetAriaColIndex+delta in the direction of delta. */ export function findTableRowCellByAriaColIndex(tableRow, targetAriaColIndex, delta) { var _a; let targetCell = null; const cellElements = Array.from(tableRow.querySelectorAll('td[aria-colindex],th[aria-colindex]')); if (delta < 0) { cellElements.reverse(); } for (const element of cellElements) { const columnIndex = parseInt((_a = element.getAttribute('aria-colindex')) !== null && _a !== void 0 ? _a : ''); targetCell = element; if (columnIndex === targetAriaColIndex) { break; } if (delta >= 0 && columnIndex > targetAriaColIndex) { break; } if (delta < 0 && columnIndex < targetAriaColIndex) { break; } } return targetCell; } export function isTableCell(element) { return element.tagName === 'TD' || element.tagName === 'TH'; } export function focusNextElement(element) { if (element) { // Table cells are not focusable by default (tabIndex=undefined) so cell.focus() is ignored. // To force focusing we have to imperatively set tabIndex to -1. This tabIndex is then to be // overridden by the single tab stop context to be 0 or undefined. // We cannot make cells have tabIndex=-1 by default due to an associated bug with text selection, see: PR 2158. if (isTableCell(element) && element.tabIndex !== 0) { element.tabIndex = -1; } element.focus(); } } //# sourceMappingURL=utils.js.map