Collapse
Vue Bootstrap 5 Collapse component
Toggle the visibility of content across your project with a few classes and our JavaScript plugins.
Note: Read the API tab to find all available options and advanced customization
How it works
The collapse JavaScript plugin is used to show and hide content. Buttons or anchors are used
as triggers that are mapped to specific elements you toggle. Collapsing an element will
animate the height
from its current value to 0
. Given how CSS
handles animations, you cannot use padding
on a .collapse
element.
Instead, use the class as an independent wrapping element.
Basic example
Click the buttons below to show and hide another element via class changes:
We use MDBCollapse
component to create collapsible elements.
Horizontal
The collapse plugin also supports horizontal collapsing. Add the
horizontal
prop and set
width
on the
immediate child element. Feel free to write your own custom Sass, use inline styles, or use
our width utilities.
Please note that while the example below has a min-height
set to avoid
excessive repaints in our docs, this is not explicitly required.
Only the width
on the child element is required.
Multiple targets
Each collapsible element can target multiple collapsbible contents and each collapsbile content can be targeted by multiple collapsible elements.
Accessibility
Be sure to add aria-expanded
to the control element. This attribute explicitly
conveys the current state of the collapsible element tied to the control to screen readers and
similar assistive technologies. If the collapsible element is closed by default, the attribute
on the control element should have a value of aria-expanded="false"
. If you’ve
set the collapsible element to be open by default using the show
class, set
aria-expanded="true"
on the control instead. The plugin will automatically toggle
this attribute on the control based on whether or not the collapsible element has been opened
or closed (via JavaScript, or because the user triggered another control element also tied to
the same collapsible element). If the control element’s HTML element is not a button (e.g., an
<a>
or <div>
), the attribute
role="button"
should be added to the element.
Note that Bootstrap’s current implementation does not cover the various keyboard interactions described in the WAI-ARIA Authoring Practices 1.1 accordion pattern - you will need to include these yourself with custom JavaScript.
Collapse - API
Import
Properties
Property | Type | Default | Description | Example |
---|---|---|---|---|
tag |
String | "div" |
Defines tag element wrapping collapsible content. |
<MDBCollapse v-model="collapse">Collapsing
content</MDBCollapse>
|
collapseClass |
String | "" |
Adds custom class for collapsible content wrapper |
<MDBCollapse v-model="collapse"
collapseClass="customClass">Collapsing
content</MDBCollapse>
|
duration |
Number | 300 |
Sets time in milisecond for collapsing animation |
<MDBCollapse v-model="collapse"
:duration="400">Collapsing content</MDBCollapse>
|
horizontal |
Boolean | false |
Sets horizontal animation. |
<MDBCollapse v-model="collapse"
horizontal width="300px">Collapsing content</MDBCollapse>
|