File tree Expand file tree Collapse file tree 1 file changed +6
-11
lines changed
packages/mui-utils/src/getActiveElement Expand file tree Collapse file tree 1 file changed +6
-11
lines changed Original file line number Diff line number Diff line change 55 * the shadow host element. This function recursively traverses shadow roots to find
66 * the actual focused element.
77 *
8- * @param root - The document or shadow root to start from. Defaults to document .
8+ * @param root - The document to query for the active element .
99 * @returns The actual focused element, or null if no element has focus.
1010 *
1111 * @example
1717 * // Starting from a specific document
1818 * const activeElement = getActiveElement(ownerDocument(element));
1919 */
20- export default function getActiveElement ( root : Document | ShadowRoot = document ) : Element | null {
21- const activeEl = root . activeElement ;
20+ export default function activeElement ( doc : Document ) : Element | null {
21+ let element = doc . activeElement ;
2222
23- if ( ! activeEl ) {
24- return null ;
23+ while ( element ?. shadowRoot ?. activeElement != null ) {
24+ element = element . shadowRoot . activeElement ;
2525 }
2626
27- // If the active element has a shadow root, recursively check inside it
28- if ( activeEl . shadowRoot && activeEl . shadowRoot . activeElement ) {
29- return getActiveElement ( activeEl . shadowRoot ) ;
30- }
31-
32- return activeEl ;
27+ return element ;
3328}
You can’t perform that action at this time.
0 commit comments