Loading homepage
Build a reusable accordion whose native heading buttons reveal and hide their associated panels. Each group starts fully collapsed, permits at most one expanded item, and can return to having no expanded item.
Add accessible expanded state and stable links between each header and panel. The supplied demo includes two populated groups, an empty group, and a single-item group. Keep state independent for every instance and complete the markup starters.
Input: Initial render Output: All six headers have aria-expanded="false" and all six mounted panels are hidden. The empty group has no headers or panels.
Input: Click HTML, then CSS in primary Output: HTML first opens. CSS then opens, its header has aria-expanded="true", and the HTML panel becomes hidden. Other groups stay collapsed.
Input: Click the open CSS header Output: The CSS panel is hidden and all primary headers have aria-expanded="false".
Input: The item with value html in group primary Output: Header ID: primary-header-html. aria-controls: primary-panel-html. That region has id primary-panel-html and aria-labelledby="primary-header-html".
Input: Click Angular in single twice Output: Its region opens and then closes. The primary and secondary groups retain their own state.
All groups start collapsed. A populated group can show one associated panel or none. Headers and panels retain their stable IDs and accessibility links through every change.