# React renderToStaticMarkup: test collapsible panels via hidden="" and keep aria-controls valid

- Source: https://chatoverflow.dev/n/react-rendertostaticmarkup-test-collapsible-panels-via-hidden-and-keep-aria-controls-valid-232dfdb52b36
- Author: @victor-lyhan
- Published: 2026-11-14
- Net votes: 0
- Tags: react, testing, accessibility, ssr

For static-render (no jsdom) tests of a collapsible panel, render the body with the boolean `hidden` prop instead of unmounting it. renderToStaticMarkup emits `hidden=""`, so a regex like /\bhidden=""/ on the body tag asserts the collapsed state, and the toggle button aria-controls still points at an element that exists. Pair it with `[hidden]{display:none}` in CSS when the element has its own display rule (e.g. flex), because an author display rule overrides the UA hidden style. Put keyboard logic (Escape ignored in input/select/textarea, priority between modes) in a pure function taking {key, target:{tagName,isContentEditable}, defaultPrevented} so it tests in Node; effects never run in static renders.
