|
| 1 | +# Accordion |
| 2 | + |
| 3 | +Build vertically collapsing accordions in combination with `<b-collapse>` component. |
| 4 | + |
| 5 | +## How it works |
| 6 | + |
| 7 | +The `<b-accordion-item>` uses the `<b-collapse>` component internally to make it collapsible. To render an accordion that’s expanded, add the `visible` property on the `<b-accordion-item>` component. |
| 8 | + |
| 9 | +::: tip |
| 10 | +The animation effect of this component is dependent on the prefers-reduced-motion media query. See the [reduced motion section of our accessibility documentation](https://getbootstrap.com/docs/5.0/getting-started/accessibility/#reduced-motion). |
| 11 | +::: |
| 12 | + |
| 13 | +## Example |
| 14 | + |
| 15 | +Click the accordions below to expand/collapse the accordion content. |
| 16 | + |
| 17 | +<ClientOnly> |
| 18 | + <b-card class="text-dark"> |
| 19 | + <b-accordion> |
| 20 | + <b-accordion-item title="Accordion Item #1" visible> |
| 21 | + <strong>This is the first item's accordion body.</strong> It is shown 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. |
| 22 | + </b-accordion-item> |
| 23 | + <b-accordion-item title="Accordion Item #2"> |
| 24 | + <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. |
| 25 | + </b-accordion-item> |
| 26 | + <b-accordion-item title="Accordion Item #3"> |
| 27 | + <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. |
| 28 | + </b-accordion-item> |
| 29 | + </b-accordion> |
| 30 | + </b-card> |
| 31 | +</ClientOnly> |
| 32 | + |
| 33 | +```html |
| 34 | +<b-accordion> |
| 35 | + <b-accordion-item title="Accordion Item #1" visible> |
| 36 | + <strong>This is the first item's accordion body.</strong> It is shown by default, until the |
| 37 | + collapse plugin adds the appropriate classes that we use to style each element. These classes |
| 38 | + control the overall appearance, as well as the showing and hiding via CSS transitions. You can |
| 39 | + modify any of this with custom CSS or overriding our default variables. It's also worth noting |
| 40 | + that just about any HTML can go within the <code>.accordion-body</code>, though the transition |
| 41 | + does limit overflow. |
| 42 | + </b-accordion-item> |
| 43 | + <b-accordion-item title="Accordion Item #2"> |
| 44 | + <strong>This is the second item's accordion body.</strong> It is hidden by default, until the |
| 45 | + collapse plugin adds the appropriate classes that we use to style each element. These classes |
| 46 | + control the overall appearance, as well as the showing and hiding via CSS transitions. You can |
| 47 | + modify any of this with custom CSS or overriding our default variables. It's also worth noting |
| 48 | + that just about any HTML can go within the <code>.accordion-body</code>, though the transition |
| 49 | + does limit overflow. |
| 50 | + </b-accordion-item> |
| 51 | + <b-accordion-item title="Accordion Item #3"> |
| 52 | + <strong>This is the third item's accordion body.</strong> It is hidden by default, until the |
| 53 | + collapse plugin adds the appropriate classes that we use to style each element. These classes |
| 54 | + control the overall appearance, as well as the showing and hiding via CSS transitions. You can |
| 55 | + modify any of this with custom CSS or overriding our default variables. It's also worth noting |
| 56 | + that just about any HTML can go within the <code>.accordion-body</code>, though the transition |
| 57 | + does limit overflow. |
| 58 | + </b-accordion-item> |
| 59 | +</b-accordion> |
| 60 | +``` |
| 61 | + |
| 62 | +### Flush |
| 63 | + |
| 64 | +Add `flush` property to remove the default background-color, some borders, and some rounded corners to render accordions edge-to-edge with their parent container. |
| 65 | + |
| 66 | +<ClientOnly> |
| 67 | + <b-card class="text-dark bg-light"> |
| 68 | + <b-accordion flush> |
| 69 | + <b-accordion-item title="Accordion Item #1"> |
| 70 | + Placeholder content for this accordion, which is intended to demonstrate the <code>flush</code> property. This is the first item's accordion body. |
| 71 | + </b-accordion-item> |
| 72 | + <b-accordion-item title="Accordion Item #2"> |
| 73 | + Placeholder content for this accordion, which is intended to demonstrate the <code>flush</code> property. This is the second item's accordion body. Let's imagine this being filled with some actual content. |
| 74 | + </b-accordion-item> |
| 75 | + <b-accordion-item title="Accordion Item #3"> |
| 76 | + Placeholder content for this accordion, which is intended to demonstrate the <code>flush</code> property. This is the third item's accordion body. Nothing more exciting happening here in terms of content, but just filling up the space to make it look, at least at first glance, a bit more representative of how this would look in a real-world application. |
| 77 | + </b-accordion-item> |
| 78 | + </b-accordion> |
| 79 | + </b-card> |
| 80 | +</ClientOnly> |
| 81 | + |
| 82 | +```html |
| 83 | +<b-accordion flush> |
| 84 | + <b-accordion-item title="Accordion Item #1"> |
| 85 | + Placeholder content for this accordion, which is intended to demonstrate the |
| 86 | + <code>flush</code> property. This is the first item's accordion body. |
| 87 | + </b-accordion-item> |
| 88 | + <b-accordion-item title="Accordion Item #2"> |
| 89 | + Placeholder content for this accordion, which is intended to demonstrate the |
| 90 | + <code>flush</code> property. This is the second item's accordion body. Let's imagine this being |
| 91 | + filled with some actual content. |
| 92 | + </b-accordion-item> |
| 93 | + <b-accordion-item title="Accordion Item #3"> |
| 94 | + Placeholder content for this accordion, which is intended to demonstrate the |
| 95 | + <code>flush</code> property. This is the third item's accordion body. Nothing more exciting |
| 96 | + happening here in terms of content, but just filling up the space to make it look, at least at |
| 97 | + first glance, a bit more representative of how this would look in a real-world application. |
| 98 | + </b-accordion-item> |
| 99 | +</b-accordion> |
| 100 | +``` |
| 101 | + |
| 102 | +### Always open |
| 103 | + |
| 104 | +Add `free` property to make accordion items stay open when another item is opened. |
| 105 | + |
| 106 | +<ClientOnly> |
| 107 | + <b-card class="text-dark"> |
| 108 | + <b-accordion free> |
| 109 | + <b-accordion-item title="Accordion Item #1"> |
| 110 | + <strong>This is the first item's accordion body.</strong> It is shown 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>default</code> slot, though the transition does limit overflow. |
| 111 | + </b-accordion-item> |
| 112 | + <b-accordion-item title="Accordion Item #2"> |
| 113 | + <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>default</code> slot, though the transition does limit overflow. |
| 114 | + </b-accordion-item> |
| 115 | + <b-accordion-item title="Accordion Item #3"> |
| 116 | + <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>default</code> slot, though the transition does limit overflow. |
| 117 | + </b-accordion-item> |
| 118 | + </b-accordion> |
| 119 | + </b-card> |
| 120 | +</ClientOnly> |
| 121 | + |
| 122 | +```html |
| 123 | +<b-accordion free> |
| 124 | + <b-accordion-item title="Accordion Item #1"> |
| 125 | + <strong>This is the first item's accordion body.</strong> It is shown by default, until the |
| 126 | + collapse plugin adds the appropriate classes that we use to style each element. These classes |
| 127 | + control the overall appearance, as well as the showing and hiding via CSS transitions. You can |
| 128 | + modify any of this with custom CSS or overriding our default variables. It's also worth noting |
| 129 | + that just about any HTML can go within the <code>default</code> slot, though the transition does |
| 130 | + limit overflow. |
| 131 | + </b-accordion-item> |
| 132 | + <b-accordion-item title="Accordion Item #2"> |
| 133 | + <strong>This is the second item's accordion body.</strong> It is hidden by default, until the |
| 134 | + collapse plugin adds the appropriate classes that we use to style each element. These classes |
| 135 | + control the overall appearance, as well as the showing and hiding via CSS transitions. You can |
| 136 | + modify any of this with custom CSS or overriding our default variables. It's also worth noting |
| 137 | + that just about any HTML can go within the <code>default</code> slot, though the transition does |
| 138 | + limit overflow. |
| 139 | + </b-accordion-item> |
| 140 | + <b-accordion-item title="Accordion Item #3"> |
| 141 | + <strong>This is the third item's accordion body.</strong> It is hidden by default, until the |
| 142 | + collapse plugin adds the appropriate classes that we use to style each element. These classes |
| 143 | + control the overall appearance, as well as the showing and hiding via CSS transitions. You can |
| 144 | + modify any of this with custom CSS or overriding our default variables. It's also worth noting |
| 145 | + that just about any HTML can go within the <code>default</code> slot, though the transition does |
| 146 | + limit overflow. |
| 147 | + </b-accordion-item> |
| 148 | +</b-accordion> |
| 149 | +``` |
| 150 | + |
| 151 | +<ClientOnly> |
| 152 | + <ComponentReference></ComponentReference> |
| 153 | +</ClientOnly> |
0 commit comments