@@ -17,6 +17,26 @@ beforeAll(() => {
17
17
getClientRects : {
18
18
get : ( ) => ( ) => [ 42 ] ,
19
19
} ,
20
+ offsetParent : {
21
+ get ( ) {
22
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
23
+ for ( let element = this ; element ; element = element . parentNode ) {
24
+ if ( element . style ?. display ?. toLowerCase ( ) === 'none' ) {
25
+ return null
26
+ }
27
+ }
28
+
29
+ if ( this . style ?. position ?. toLowerCase ( ) === 'fixed' ) {
30
+ return null
31
+ }
32
+
33
+ if ( this . tagName . toLowerCase ( ) in [ 'html' , 'body' ] ) {
34
+ return null
35
+ }
36
+
37
+ return this . parentNode
38
+ } ,
39
+ } ,
20
40
} )
21
41
} catch {
22
42
// ignore
@@ -40,7 +60,7 @@ it('Should initially focus the first element when activated', () => {
40
60
const controller = focusTrap ( trapContainer )
41
61
expect ( document . activeElement ) . toEqual ( firstButton )
42
62
43
- controller . abort ( )
63
+ controller ? .abort ( )
44
64
} )
45
65
46
66
it ( 'Should initially focus the initialFocus element when specified' , ( ) => {
@@ -57,7 +77,7 @@ it('Should initially focus the initialFocus element when specified', () => {
57
77
const controller = focusTrap ( trapContainer , secondButton )
58
78
expect ( document . activeElement ) . toEqual ( secondButton )
59
79
60
- controller . abort ( )
80
+ controller ? .abort ( )
61
81
} )
62
82
63
83
it ( 'Should prevent focus from exiting the trap, returns focus to first element' , async ( ) => {
@@ -86,7 +106,7 @@ it('Should prevent focus from exiting the trap, returns focus to first element',
86
106
await user . tab ( )
87
107
expect ( document . activeElement ) . toEqual ( firstButton )
88
108
89
- controller . abort ( )
109
+ controller ? .abort ( )
90
110
91
111
lastButton . focus ( )
92
112
await user . tab ( )
@@ -125,7 +145,7 @@ it('Should cycle focus from last element to first element and vice-versa', async
125
145
await user . tab ( { shift : true } )
126
146
expect ( document . activeElement ) . toEqual ( lastButton )
127
147
128
- controller . abort ( )
148
+ controller ? .abort ( )
129
149
} )
130
150
131
151
it ( 'Should should release the trap when the signal is aborted' , async ( ) => {
@@ -154,7 +174,7 @@ it('Should should release the trap when the signal is aborted', async () => {
154
174
await user . tab ( )
155
175
expect ( document . activeElement ) . toEqual ( firstButton )
156
176
157
- controller . abort ( )
177
+ controller ? .abort ( )
158
178
159
179
lastButton . focus ( )
160
180
await user . tab ( )
@@ -218,5 +238,5 @@ it('Should handle dynamic content', async () => {
218
238
await user . tab ( { shift : true } )
219
239
expect ( document . activeElement ) . toEqual ( secondButton )
220
240
221
- controller . abort ( )
241
+ controller ? .abort ( )
222
242
} )
0 commit comments