Skip to content

Commit 897233e

Browse files
committed
fix(primitive): handle null cases in getDeepActiveElement function
1 parent acbfc87 commit 897233e

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

packages/core/primitive/src/primitive.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,17 @@ export function isFrame(element: Element): element is HTMLIFrameElement {
7878
* Utility to get the currently focused element even across Shadow DOM boundaries
7979
*/
8080
export function getDeepActiveElement(): Element | null {
81+
if (!canUseDOM) {
82+
return null;
83+
}
84+
8185
let activeElement = document.activeElement;
86+
if (!activeElement) {
87+
return null;
88+
}
8289

8390
// Traverse through shadow DOMs to find the deepest active element
84-
while (activeElement && activeElement.shadowRoot && activeElement.shadowRoot.activeElement) {
91+
while (activeElement.shadowRoot?.activeElement) {
8592
activeElement = activeElement.shadowRoot.activeElement;
8693
}
8794

0 commit comments

Comments
 (0)