File tree Expand file tree Collapse file tree 2 files changed +10
-4
lines changed Expand file tree Collapse file tree 2 files changed +10
-4
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,12 @@ interface FocusRingComponentProps extends FocusRingProps {
19
19
children : React . ReactElement < FocusableChildProps > ;
20
20
}
21
21
22
+ // ref: https://github.com/facebook/react/issues/14927
23
+ const useLayoutEffect =
24
+ typeof window !== "undefined" && window . document && window . document . createElement
25
+ ? React . useLayoutEffect
26
+ : React . useEffect ;
27
+
22
28
/**
23
29
* Augments the child component to be able to render a focus ring
24
30
*/
@@ -66,7 +72,7 @@ export default function FocusRing(props: FocusRingComponentProps) {
66
72
67
73
// Force the ring to update itself whenever this component re-renders
68
74
// to stay up-to-date with the active element's properties.
69
- React . useLayoutEffect ( ( ) => {
75
+ useLayoutEffect ( ( ) => {
70
76
if ( ! enabled ) return ;
71
77
ringContext . invalidate ( ) ;
72
78
} ) ;
@@ -94,7 +100,7 @@ export default function FocusRing(props: FocusRingComponentProps) {
94
100
95
101
// When using a remote focus ring (both `focusTarget` and `ringTarget` are
96
102
// set), use native DOM event listeners to track when focus happens.
97
- React . useLayoutEffect ( ( ) => {
103
+ useLayoutEffect ( ( ) => {
98
104
if ( focused != null ) return ;
99
105
100
106
const target = focusTarget ?. current ;
Original file line number Diff line number Diff line change @@ -78,7 +78,7 @@ export class FocusRingContextManager {
78
78
let current : Element | null = element ;
79
79
while ( current != null ) {
80
80
elements . push ( current ) ;
81
- styles . push ( window . getComputedStyle ( current ) ) ;
81
+ typeof window !== "undefined" && styles . push ( window . getComputedStyle ( current ) ) ;
82
82
current = current . parentElement ;
83
83
}
84
84
return { elements, styles } ;
@@ -168,7 +168,7 @@ export class FocusRingContextManager {
168
168
}
169
169
170
170
const GLOBAL_FOCUS_RING_CONTEXT = new FocusRingContextManager ( ) ;
171
- GLOBAL_FOCUS_RING_CONTEXT . setContainer ( document . body ) ;
171
+ typeof window !== "undefined" && GLOBAL_FOCUS_RING_CONTEXT . setContainer ( document . body ) ;
172
172
173
173
const FocusRingContext = React . createContext ( GLOBAL_FOCUS_RING_CONTEXT ) ;
174
174
You can’t perform that action at this time.
0 commit comments