19 lines
929 B
JavaScript
19 lines
929 B
JavaScript
import { FOCUS_AUTO } from '../constants';
|
|
import { toArray } from './array';
|
|
import { tabbables } from './tabbables';
|
|
var queryTabbables = tabbables.join(',');
|
|
var queryGuardTabbables = queryTabbables + ", [data-focus-guard]";
|
|
export var getFocusables = function (parents, withGuards) {
|
|
return parents.reduce(function (acc, parent) {
|
|
return acc.concat(toArray(parent.querySelectorAll(withGuards ? queryGuardTabbables : queryTabbables)), parent.parentNode
|
|
? toArray(parent.parentNode.querySelectorAll(queryTabbables)).filter(function (node) { return node === parent; })
|
|
: []);
|
|
}, []);
|
|
};
|
|
export var getParentAutofocusables = function (parent) {
|
|
var parentFocus = parent.querySelectorAll("[" + FOCUS_AUTO + "]");
|
|
return toArray(parentFocus)
|
|
.map(function (node) { return getFocusables([node]); })
|
|
.reduce(function (acc, nodes) { return acc.concat(nodes); }, []);
|
|
};
|