Skip to content

Commit 0660ee7

Browse files
committed
addded filter to getAllFocusables to filter out the ignored elements from array
1 parent ef8a078 commit 0660ee7

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

lib/lrud.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,16 @@ const getFocusables = (scope) => {
8989
* @param {HTMLElement} scope The element to search inside of
9090
* @return {HTMLElement[]} Array of valid focusables inside the scope
9191
*/
92-
const getAllFocusables = (scope) => [
93-
...toArray(scope.querySelectorAll(focusableContainerSelector)).filter(container => getFocusables(container)?.length > 0),
94-
...getFocusables(scope)
95-
];
92+
const getAllFocusables = (scope) => {
93+
const ignoredElements = toArray(scope.querySelectorAll(ignoreSelector));
94+
95+
return [
96+
...toArray(scope.querySelectorAll(focusableContainerSelector))
97+
.filter(node => !ignoredElements.some(ignored => ignored == node || ignored.contains(node)))
98+
.filter(container => getFocusables(container)?.length > 0),
99+
...getFocusables(scope)
100+
];
101+
};
96102

97103
/**
98104
* Build an array of ancestor containers

0 commit comments

Comments
 (0)