Skip to content

Custom button element to open/close grouped <details> elements intuitively.

License

Notifications You must be signed in to change notification settings

deepspaceaxolotl/open-all-details

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

Open All Details

Custom button element to open/close grouped <details> elements intuitively. [Demo (TBA)]

OpenAll.astro is an Astro component that inserts a custom element containing an unstyled button that will open (or close) all <details> elements specified by the selector prop. The script takes into account whether the <details> elements started out opened or closed since the button was last pressed and will know to open/close them all if they're all in the opposite state. The button has the class .open-all and a label specified by the title prop (open/close by default, which can be changed in the component file). Additional classes can be passed using the classes prop.

Example Usage (Astro page)

---
import OpenAll from '../components/OpenAll.astro'
---
<section class="fruit">
  <h2>
    Fruit
    <OpenAll selector=".fruit details" title="expand/collapse all" classes="fruit-button" />
  </h2>

  <details>
    <summary>Berries</summary>
    Blueberry, Raspberry, Strawberry
  </details>

  <details>
    <summary>Citruses</summary>
    Lemon, Grape, Orange
  </details>
</section>

Resulting button:

<open-all data-selector=".fruit details">
  <button class="open-all fruit-button" type="button">expand/collapse all</button>
</open-all>

About

Custom button element to open/close grouped <details> elements intuitively.

Resources

License

Stars

Watchers

Forks

Languages