@@ -232,4 +232,68 @@ describe('TooltipDialog', () => {
232232      expect ( onCloseSpy ) . toHaveBeenCalled ( ) ; 
233233    } ) ; 
234234  } ) ; 
235+ 
236+   describe ( 'keepMounted' ,  ( )  =>  { 
237+     it ( 'keeps dialog mounted in the DOM while visually hidden' ,  ( )  =>  { 
238+       const  {  queryByRole,  getByTestId }  =  render ( 
239+         < Example  keepMounted  backdropProps = { {  'data-test-id' : 'backdrop'  }  as  any }  /> 
240+       ) ; 
241+ 
242+       // Closed (hidden) state: still mounted but visually hidden and aria-hidden on backdrop 
243+       const  hiddenDialog  =  queryByRole ( 'dialog' ,  {  hidden : true  } ) ; 
244+ 
245+       expect ( hiddenDialog ) . not . toBeNull ( ) ; 
246+       expect ( getByTestId ( 'backdrop' ) ) . toHaveAttribute ( 'aria-hidden' ,  'true' ) ; 
247+       // Backdrop should have hideVisually styles applied (position: absolute, clip, etc.) 
248+       const  backdropStyles  =  window . getComputedStyle ( getByTestId ( 'backdrop' ) ) ; 
249+       expect ( backdropStyles . position ) . toBe ( 'absolute' ) ; 
250+       expect ( backdropStyles . width ) . toBe ( '1px' ) ; 
251+       expect ( backdropStyles . height ) . toBe ( '1px' ) ; 
252+     } ) ; 
253+ 
254+     it ( 'toggles visibility and manages focus correctly when reopened' ,  async  ( )  =>  { 
255+       const  {  getByText,  getByRole,  queryByRole,  getByTestId }  =  render ( 
256+         < Example  keepMounted  backdropProps = { {  'data-test-id' : 'backdrop'  }  as  any }  /> 
257+       ) ; 
258+ 
259+       const  trigger  =  getByText ( 'open' ) ; 
260+ 
261+       // Initially hidden but mounted 
262+       const  initiallyHiddenDialog  =  queryByRole ( 'dialog' ,  {  hidden : true  } ) ; 
263+       expect ( initiallyHiddenDialog ) . not . toBeNull ( ) ; 
264+       expect ( getByTestId ( 'backdrop' ) ) . toHaveAttribute ( 'aria-hidden' ,  'true' ) ; 
265+ 
266+       // Open 
267+       await  act ( async  ( )  =>  { 
268+         await  user . click ( trigger ) ; 
269+       } ) ; 
270+ 
271+       const  openDialog  =  getByRole ( 'dialog' ) ; 
272+       expect ( openDialog ) . toBeInTheDocument ( ) ; 
273+       expect ( getByTestId ( 'backdrop' ) ) . not . toHaveAttribute ( 'aria-hidden' ) ; 
274+       expect ( openDialog ) . toHaveFocus ( ) ; 
275+       // Backdrop should NOT have hideVisually styles when visible 
276+       const  visibleBackdropStyles  =  window . getComputedStyle ( getByTestId ( 'backdrop' ) ) ; 
277+       expect ( visibleBackdropStyles . position ) . toBe ( 'fixed' ) ; 
278+ 
279+       // Close (toggle button again) 
280+       await  act ( async  ( )  =>  { 
281+         await  user . click ( trigger ) ; 
282+       } ) ; 
283+ 
284+       // Dialog remains mounted but visually hidden again 
285+       const  hiddenAgainDialog  =  queryByRole ( 'dialog' ,  {  hidden : true  } ) ; 
286+       expect ( hiddenAgainDialog ) . not . toBeNull ( ) ; 
287+       await  waitFor ( ( )  =>  { 
288+         expect ( getByTestId ( 'backdrop' ) ) . toHaveAttribute ( 'aria-hidden' ,  'true' ) ; 
289+         // Backdrop should have hideVisually styles applied again 
290+         const  hiddenBackdropStyles  =  window . getComputedStyle ( getByTestId ( 'backdrop' ) ) ; 
291+         expect ( hiddenBackdropStyles . position ) . toBe ( 'absolute' ) ; 
292+         expect ( hiddenBackdropStyles . width ) . toBe ( '1px' ) ; 
293+         expect ( hiddenBackdropStyles . height ) . toBe ( '1px' ) ; 
294+       } ) ; 
295+       // Focus should return to trigger 
296+       expect ( trigger ) . toHaveFocus ( ) ; 
297+     } ) ; 
298+   } ) ; 
235299} ) ; 
0 commit comments