Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Details block: Exclusive accordions #56969

Open
Soean opened this issue Dec 12, 2023 · 1 comment · May be fixed by #56971
Open

Details block: Exclusive accordions #56969

Soean opened this issue Dec 12, 2023 · 1 comment · May be fixed by #56971
Assignees
Labels
[Block] Details Affects the Details Block - used to display content which can be shown/hidden [Status] In Progress Tracking issues with work in progress [Type] Enhancement A suggestion for improvement.

Comments

@Soean
Copy link
Member

Soean commented Dec 12, 2023

What problem does this address?

Safari 17.2 now supports the name attribute on the <details> element — which moves some commonly-used functionality from needing JavaScript to being baked into HTML. If you use the name attribute to give a series of details elements the same name, then only one in the series will be open at a time.

<details name="foobar" open>
  <summary>Item 1</summary>
  <p>Since this first item has an open attribute, it’s open by default.</p> 
</details>
<details name="foobar">
   <summary>Item 2</summary>
  <p>When you clicked this item, any other open item will automatically close.</p>
</details>
<details name="foobar">
   <summary>Item 3</summary>
  <p>Now, developers don’t have to write any JavaScript to get this behavior.</p> 
</details>

Any time a user clicks to open a second item, the first item automatically closes. This can make for a better user experience, although do make sure it’s right for your project. Think about users who might want or need to compare one item to another. Consider whether to not it will be annoying to have to tap over and over on each bit of content in order to read each one. This pattern can be frustrating when used inappropriately — even inaccessible.

Here’s an example to compare the difference. Try it in a browser with support.

https://codepen.io/jensimmons/pen/wvNPBZa

Source: https://webkit.org/blog/14787/webkit-features-in-safari-17-2/

What is your proposed solution?

Add a name attribute to the detials block and a text field to edit it.

@Soean Soean added [Type] Enhancement A suggestion for improvement. [Block] Details Affects the Details Block - used to display content which can be shown/hidden labels Dec 12, 2023
@Soean Soean self-assigned this Dec 12, 2023
@github-actions github-actions bot added the [Status] In Progress Tracking issues with work in progress label Dec 12, 2023
@thomas-price
Copy link

Chrome/Edge v120 and Opera v106 now support this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Details Affects the Details Block - used to display content which can be shown/hidden [Status] In Progress Tracking issues with work in progress [Type] Enhancement A suggestion for improvement.
2 participants