Skip to content

Commit 7159bd7

Browse files
committed
Accordions
1 parent e8f4059 commit 7159bd7

1 file changed

Lines changed: 24 additions & 33 deletions

File tree

site/src/assets/examples/cheatsheet/index.astro

Lines changed: 24 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -623,42 +623,33 @@ export const body_class = 'bg-body-tertiary'
623623
<div>
624624
<Example showMarkup={false} code={`
625625
<div class="accordion" id="accordionExample">
626-
<div class="accordion-item">
627-
<h4 class="accordion-header">
628-
<button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
629-
Accordion Item #1
630-
</button>
631-
</h4>
632-
<div id="collapseOne" class="accordion-collapse collapse show" data-bs-parent="#accordionExample">
633-
<div class="accordion-body">
634-
<strong>This is the first item's accordion body.</strong> It is hidden by default, until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance, as well as the showing and hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the <code>.accordion-body</code>, though the transition does limit overflow.
635-
</div>
626+
<details class="accordion-item" name="accordionExample" open>
627+
<summary class="accordion-header">
628+
Accordion Item #1
629+
<svg class="accordion-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"><path d="m2 5 6 6 6-6"/></svg>
630+
</summary>
631+
<div class="accordion-body">
632+
<strong>This is the first item's accordion body.</strong> It is shown by default because the <code>open</code> attribute is present. The native <code>&lt;details&gt;</code> element handles all the show/hide logic without any JavaScript. You can put any HTML content within the <code>.accordion-body</code>.
636633
</div>
637-
</div>
638-
<div class="accordion-item">
639-
<h4 class="accordion-header">
640-
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
641-
Accordion Item #2
642-
</button>
643-
</h4>
644-
<div id="collapseTwo" class="accordion-collapse collapse" data-bs-parent="#accordionExample">
645-
<div class="accordion-body">
646-
<strong>This is the second item's accordion body.</strong> It is hidden by default, until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance, as well as the showing and hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the <code>.accordion-body</code>, though the transition does limit overflow.
647-
</div>
634+
</details>
635+
<details class="accordion-item" name="accordionExample">
636+
<summary class="accordion-header">
637+
Accordion Item #2
638+
<svg class="accordion-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"><path d="m2 5 6 6 6-6"/></svg>
639+
</summary>
640+
<div class="accordion-body">
641+
<strong>This is the second item's accordion body.</strong> The <code>name</code> attribute groups this with other accordion items. When you open this item, any other open item in the same group will close automatically.
648642
</div>
649-
</div>
650-
<div class="accordion-item">
651-
<h4 class="accordion-header">
652-
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseThree" aria-expanded="false" aria-controls="collapseThree">
653-
Accordion Item #3
654-
</button>
655-
</h4>
656-
<div id="collapseThree" class="accordion-collapse collapse" data-bs-parent="#accordionExample">
657-
<div class="accordion-body">
658-
<strong>This is the third item's accordion body.</strong> It is hidden by default, until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance, as well as the showing and hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the <code>.accordion-body</code>, though the transition does limit overflow.
659-
</div>
643+
</details>
644+
<details class="accordion-item" name="accordionExample">
645+
<summary class="accordion-header">
646+
Accordion Item #3
647+
<svg class="accordion-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"><path d="m2 5 6 6 6-6"/></svg>
648+
</summary>
649+
<div class="accordion-body">
650+
<strong>This is the third item's accordion body.</strong> This exclusive accordion behavior is built into the browser—no Bootstrap JavaScript required. Just use matching <code>name</code> attributes on your <code>&lt;details&gt;</code> elements.
660651
</div>
661-
</div>
652+
</details>
662653
</div>
663654
`} />
664655
</div>

0 commit comments

Comments
 (0)