/
githubmirror
/
material-ui
Обзор
Документация
Войти
/
githubmirror
/
material-ui
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
packages/mui-utils/src/getActiveElement/getActiveElement.ts
28 строк
971 B
sai chand
[tabs] Fix Arrow key navigation failing when component is rendered in shadow DOM (#47178)
10 ноя 2025, 15:35
Не верифицирован
10 ноя 2025, 15:35
15ff395
Код
Авторство
О чём код?
/** * Gets the actual active element, traversing through shadow roots if necessary. * * When an element inside a shadow root has focus, `document.activeElement` returns * the shadow host element. This function recursively traverses shadow roots to find * the actual focused element. * * @param root - The document or shadow root to start the search from. * @returns The actual focused element, or null if no element has focus. * * @example * // In a shadow DOM context * const activeElement = getActiveElement(document); * // Returns the actual focused element inside the shadow root * * @example * // Starting from a specific document * const activeElement = getActiveElement(ownerDocument(element)); */ export default function activeElement(doc: Document | ShadowRoot): Element | null { let element = doc.activeElement; while (element?.shadowRoot?.activeElement != null) { element = element.shadowRoot.activeElement; } return element; }