Skip to content

Commit

Permalink
refactor(util/dom-query): handle invalid element input in `getAllFocu…
Browse files Browse the repository at this point in the history
…sable`

Add a check to ensure `getAllFocusable` returns an empty array when the input is not a valid HTMLElement.
  • Loading branch information
cheton committed Aug 13, 2024
1 parent 0bd9c04 commit f8dddc3
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/utils/src/dom-query.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ const focusableElementSelectors = [
const focusableElementSelector = focusableElementSelectors.join(',');

export const getAllFocusable = (element, keyboardOnly = false) => {
if (!element || !(element instanceof HTMLElement)) {
return [];
}

let focusableElements = Array.from(element.querySelectorAll(focusableElementSelector));

// Filter out elements with `display: none`
Expand Down

0 comments on commit f8dddc3

Please sign in to comment.