diff --git a/packages/utils/src/dom-query.js b/packages/utils/src/dom-query.js index 8f2bf2e035..6d497587b5 100644 --- a/packages/utils/src/dom-query.js +++ b/packages/utils/src/dom-query.js @@ -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`