jobiqo-cl
Version:
[](https://circleci.com/gh/jobiqo/jobiqo-cl)
30 lines (25 loc) • 1.06 kB
JavaScript
import { FOCUS_AUTO } from '../constants.js';
import { toArray } from './array.js';
import tabbables from './tabbables.js';
var queryTabbables = tabbables.join(',');
var queryGuardTabbables = queryTabbables + ', [data-focus-guard]';
var getFocusables = function getFocusables(parents, withGuards) {
return parents.reduce(function (acc, parent) {
return acc.concat(
// add all tabbables inside
toArray(parent.querySelectorAll(withGuards ? queryGuardTabbables : queryTabbables)),
// add if node is tabble itself
parent.parentNode ? toArray(parent.parentNode.querySelectorAll(tabbables.join(','))).filter(function (node) {
return node === parent;
}) : []);
}, []);
};
var getParentAutofocusables = function getParentAutofocusables(parent) {
var parentFocus = parent.querySelectorAll('[' + FOCUS_AUTO + ']');
return toArray(parentFocus).map(function (node) {
return getFocusables([node]);
}).reduce(function (acc, nodes) {
return acc.concat(nodes);
}, []);
};
export { getFocusables, getParentAutofocusables };