@@ -283,7 +283,7 @@ describe("Components / Accordion", () => {
283283 const firstContent = content ( ) [ 0 ] ;
284284
285285 expect ( firstContent ) . not . toHaveStyle ( "transition: max-height 400ms ease-out" ) ;
286- expect ( firstContent ) . not . toHaveAttribute ( "aria-hidden" , "false" ) ;
286+ expect ( firstContent ) . not . toHaveAttribute ( "aria-hidden" ) ;
287287 } ) ;
288288
289289 it ( "should use the default `animationDuration` when `animate` is enabled and `animationDuration` is not provided" , ( ) => {
@@ -294,6 +294,46 @@ describe("Components / Accordion", () => {
294294 expect ( firstContent ) . toHaveStyle ( "transition: max-height 300ms ease-out" ) ;
295295 expect ( firstContent ) . toHaveAttribute ( "aria-hidden" , "false" ) ;
296296 } ) ;
297+
298+ it ( "should set inert on closed animated content to suppress focus" , ( ) => {
299+ render ( < TestAccordion animate collapseAll /> ) ;
300+
301+ const firstContent = content ( ) [ 0 ] ;
302+
303+ expect ( firstContent ) . toHaveAttribute ( "aria-hidden" , "true" ) ;
304+ expect ( firstContent ) . toHaveAttribute ( "inert" ) ;
305+ } ) ;
306+
307+ it ( "should set inert when closed and remove when open; focusable descendants reachable when open" , async ( ) => {
308+ const user = userEvent . setup ( ) ;
309+ render (
310+ < Accordion animate >
311+ < AccordionPanel >
312+ < AccordionTitle > First</ AccordionTitle >
313+ < AccordionContent >
314+ < a href = "#link" > Link inside</ a >
315+ </ AccordionContent >
316+ </ AccordionPanel >
317+ < AccordionPanel >
318+ < AccordionTitle > Second</ AccordionTitle >
319+ < AccordionContent >
320+ < p > Content</ p >
321+ </ AccordionContent >
322+ </ AccordionPanel >
323+ </ Accordion > ,
324+ ) ;
325+
326+ const link = screen . getByText ( "Link inside" ) ;
327+ const firstTitle = screen . getByRole ( "button" , { name : "First" } ) ;
328+
329+ await user . click ( screen . getByRole ( "button" , { name : "Second" } ) ) ;
330+ expect ( content ( ) [ 0 ] ) . toHaveAttribute ( "inert" ) ;
331+
332+ await user . click ( firstTitle ) ;
333+ expect ( content ( ) [ 0 ] ) . not . toHaveAttribute ( "inert" ) ;
334+ await user . tab ( ) ;
335+ expect ( link ) . toHaveFocus ( ) ;
336+ } ) ;
297337 } ) ;
298338} ) ;
299339
0 commit comments