Proposal: Add a name attribute to the <details>
element, for
example, <details name="group-1">
. If multiple <details>
elements in
a page have the same value for their name attribute, then
expanding/opening/disclosing a <details>
element of that name will
collapse/close/undisclose all the other <details>
elements with a
matching name.
This is analogous to how a group of <input type="radio" name="group-1">
elements works. On the contemporary web, radio inputs can and are used
to implement pure HTML+CSS only-one accordions; however semantically they
are a hack.
Often one wants to express a list of <details>
/<summary>
with the
ability to disclose one element and undisclose the others automatically.
This addition of a name attribute to the <details>
element would
achieve that user experience in pure HTML while maintaining the intended
document semantics.
The attribute could alternately be called group or something else; name is used in this demonstration to match the radio input grouping attribute.
A minimal demonstration implemented in JavaScript is live at https://www.fitzsim.org/details-name-prototype.html.
An equivalent radio-input-based approach which works on the contemporary web is
available at
https://www.fitzsim.org/radio-accordion-example.html.
It shows that the HTML and CSS need to be full of hacks to achieve
the same effect as would a <details>
name attribute.