UNPKG

@aurelia-mdc-web/base

Version:

Base classes for Aurelia Material Components Web

36 lines 2.04 kB
import { __read, __spreadArray } from "tslib"; export function nextElement(element, reverse) { /*check if an element is defined or use activeElement*/ var activeElem = element instanceof HTMLElement ? element : document.activeElement; if (!activeElem) { return; } var queryString = [ 'a:not([disabled]):not([tabindex="-1"])', 'button:not([disabled]):not([tabindex="-1"])', 'input:not([disabled]):not([tabindex="-1"]):not(.mdc-text-field__input)', '.mdc-text-field', 'select:not([disabled]):not([tabindex="-1"])', '[tabindex]:not([disabled]):not([tabindex="-1"])' /* add custom queries here */ ].join(','), queryResult = Array.from(document.querySelectorAll(queryString)).filter(function (elem) { /*check for visibility while always include the current activeElement*/ return elem.offsetWidth > 0 || elem.offsetHeight > 0 || elem === activeElem; }), indexedList = queryResult.slice().filter(function (elem) { /* filter out all indexes not greater than 0 */ return elem.tabIndex == 0 || elem.tabIndex == -1 ? false : true; }).sort(function (a, b) { /* sort the array by index from smallest to largest */ return a.tabIndex != 0 && b.tabIndex != 0 ? (a.tabIndex < b.tabIndex ? -1 : b.tabIndex < a.tabIndex ? 1 : 0) : a.tabIndex != 0 ? -1 : b.tabIndex != 0 ? 1 : 0; }), focusable = __spreadArray(__spreadArray([], __read(indexedList), false), __read(queryResult.filter(function (elem) { /* filter out all indexes above 0 */ return elem.tabIndex == 0 || elem.tabIndex == -1 ? true : false; })), false); /* if reverse is true return the previous focusable element if reverse is false return the next focusable element */ return reverse ? (focusable[focusable.indexOf(activeElem) - 1] || focusable[focusable.length - 1]) : (focusable[focusable.indexOf(activeElem) + 1] || focusable[0]); } //# sourceMappingURL=next-element.js.map