@@ -169,6 +169,62 @@ describe('modal', () => {
169
169
unmount ( ) ;
170
170
expect ( document . documentElement . style . position ) . toBe ( '' ) ;
171
171
} ) ;
172
+
173
+ it ( 'should unblock scroll when multiple modals are opened and then closed' , async ( ) => {
174
+ const { rerender, getAllByTestId, queryByText } = render (
175
+ < React . Fragment >
176
+ < Modal open onClose = { ( ) => null } >
177
+ < div > first modal</ div >
178
+ </ Modal >
179
+ < Modal open onClose = { ( ) => null } >
180
+ < div > second modal</ div >
181
+ </ Modal >
182
+ </ React . Fragment >
183
+ ) ;
184
+ expect ( document . documentElement . style . position ) . toBe ( 'fixed' ) ;
185
+
186
+ // We close one modal, the scroll should be locked
187
+ rerender (
188
+ < React . Fragment >
189
+ < Modal open onClose = { ( ) => null } >
190
+ < div > first modal</ div >
191
+ </ Modal >
192
+ < Modal open = { false } onClose = { ( ) => null } >
193
+ < div > second modal</ div >
194
+ </ Modal >
195
+ </ React . Fragment >
196
+ ) ;
197
+
198
+ fireEvent . animationEnd ( getAllByTestId ( 'overlay' ) [ 1 ] ) ;
199
+ await waitFor (
200
+ ( ) => {
201
+ expect ( queryByText ( / s e c o n d m o d a l / ) ) . not . toBeInTheDocument ( ) ;
202
+ } ,
203
+ { timeout : 10 }
204
+ ) ;
205
+ expect ( document . documentElement . style . position ) . toBe ( 'fixed' ) ;
206
+
207
+ // We close the second modal, the scroll should be unlocked
208
+ rerender (
209
+ < React . Fragment >
210
+ < Modal open = { false } onClose = { ( ) => null } >
211
+ < div > first modal</ div >
212
+ </ Modal >
213
+ < Modal open = { false } onClose = { ( ) => null } >
214
+ < div > second modal</ div >
215
+ </ Modal >
216
+ </ React . Fragment >
217
+ ) ;
218
+
219
+ fireEvent . animationEnd ( getAllByTestId ( 'overlay' ) [ 0 ] ) ;
220
+ await waitFor (
221
+ ( ) => {
222
+ expect ( queryByText ( / f i r s t m o d a l / ) ) . not . toBeInTheDocument ( ) ;
223
+ } ,
224
+ { timeout : 10 }
225
+ ) ;
226
+ expect ( document . documentElement . style . position ) . toBe ( '' ) ;
227
+ } ) ;
172
228
} ) ;
173
229
174
230
describe ( 'closeIcon' , ( ) => {
0 commit comments