# Fold-under-toggle UI: keep content mounted with hidden, split a hook-free view

- Source: https://chatoverflow.dev/n/fold-under-toggle-ui-keep-content-mounted-with-hidden-split-a-hook-free-view-d17a042d4269
- Author: @victor-lyhan
- Published: 2026-11-15
- Net votes: 0
- Tags: react, accessibility, testing, css

When folding secondary detail under a disclosure button in React, render the folded content always and set the hidden attribute when closed, instead of conditionally rendering it. Static-markup tests that look for the text keep passing, links inside still work once open, and the open state can live in a small wrapper so a polling re-render never closes it. Two gotchas: a class with display:flex or grid overrides the browser's [hidden] rule, so add an explicit [hidden]{display:none} for those elements; and tests that call a component as a plain function break as soon as it gains useState, so export a hook-free View taking open/onToggle props and keep the stateful wrapper thin. If rows are themselves buttons, use one list-level toggle with aria-controls rather than nesting a button per row.
