Skip to content

Collapse

The Collapse component is a disclosure widget that displ information only when toggled to the open state. The component is implemented based on the HTML <details> element and consists of two elements: a disclosure label (trigger) and a section of content whose visibility it controls. This component also implements the W3C ARIA APG Disclosure (Show/Hide) Pattern and also supports the W3C ARIA APG Accordion Pattern.

Examples

Base

A custom trigger can be passed in the trigger slot. When the controlled content is hidden, the trigger is often styled as a typical push button with a right-pointing arrow or triangle, to indicate that activating the trigger will display the hidden content. When the content is visible, the arrow or triangle usually points down.

Accessibility Note:

The trigger container is already an interactive element with the role="button" attribute. For accessibility reasons, prevent adding other interactive elements such as buttons to avoid nested-interactive accessibility problems.
html
<section>
    <o-collapse expanded>
        <template #trigger="{ open }">
            <h3 class="trigger">
                <o-icon :icon="open ? 'chevron-down' : 'chevron-right'" />
                {{ open ? "Close" : "Open" }} Collapse!
            </h3>
        </template>

        <div class="notification">
            <h4>Subtitle</h4>
            <p>
                Lorem ipsum dolor sit amet, consectetur adipiscing elit.
                <br />
                Nulla accumsan, metus ultrices eleifend gravida, nulla nunc
                varius lectus, nec rutrum justo nibh eu lectus.
                <br />
                Ut vulputate semper dui. Fusce erat odio, sollicitudin vel
                erat vel, interdum mattis neque.
            </p>
        </div>
    </o-collapse>
</section>
scss
.trigger {
    padding: 1rem;
    background-color: var(--vp-c-brand-2);
    color: white;
    box-shadow:
        0 2px 3px hsla(0, 0%, 4%, 0.1),
        0 0 0 1px hsla(0, 0%, 4%, 0.1);
    text-align: center;
}

Position

The collapse can be configured by the position property to open to top instead of bottom.

html
<section>
    <o-collapse expanded position="top">
        <template #trigger="{ open }">
            <p class="trigger">
                <o-icon :icon="open ? 'chevron-down' : 'chevron-right'" />
                {{ open ? "Close" : "Open" }} Collapse!
            </p>
        </template>

        <div class="notification">
            <p>
                Lorem ipsum dolor sit amet, consectetur adipiscing elit.
                <br />
                Nulla accumsan, metus ultrices eleifend gravida, nulla nunc
                varius lectus, nec rutrum justo nibh eu lectus.
                <br />
                Ut vulputate semper dui. Fusce erat odio, sollicitudin vel
                erat vel, interdum mattis neque.
            </p>
        </div>
    </o-collapse>
</section>
scss
.trigger {
    padding: 1rem;
    background-color: var(--vp-c-brand-3);
    color: white;
    box-shadow:
        0 2px 3px hsla(0, 0%, 4%, 0.1),
        0 0 0 1px hsla(0, 0%, 4%, 0.1);
    text-align: center;
}

Accordion

Using the name property multiple collapse components can be connected to create an accordion behaviour, with only one open at a time.

html
<section>
    <o-collapse
        v-for="(collapse, index) of collapses"
        :key="index"
        class="card"
        name="my-accordion"
        expanded
        :open="index === 0">
        <template #trigger="{ open }">
            <div class="card-header">
                <span class="card-header-title">
                    {{ collapse.title }}
                </span>

                <span class="card-header-icon">
                    <o-icon :icon="open ? 'caret-up' : 'caret-down'" />
                </span>
            </div>
        </template>

        <div class="card-content">
            <p class="content" v-html="collapse.text" />
        </div>
    </o-collapse>
</section>
javascript
import { ref } from "vue";

const collapses = ref([
    {
        title: "Open to read something intersting written for you!",
        text: `Lorem ipsum dolor sit amet, consectetur adipiscing elit. <br />
          Nulla accumsan, metus ultrices eleifend gravida, <br />
          nulla nunc varius lectus, nec rutrum justo nibh eu lectus. <br />
          Ut vulputate semper dui. Fusce erat odio, sollicitudin vel erat vel, interdum mattis neque.`,
    },
    {
        title: "What the different between Oruga and Buefy?",
        text: "Nulla accumsan, metus ultrices eleifend gravida, nulla nunc varius lectus, nec rutrum justo nibh eu lectus. <br />",
    },
    {
        title: "Nothing special, ignore it!",
        text: "Ut vulputate semper dui. Fusce erat odio, sollicitudin vel erat vel, interdum mattis neque.",
    },
]);
scss
.card {
    position: relative;
    background-color: #fff;
    box-shadow:
        0 2px 3px hsla(0, 0%, 4%, 0.1),
        0 0 0 1px hsla(0, 0%, 4%, 0.1);
}

.card-header {
    display: flex;
    align-items: center;
    box-shadow: 0 1px 2px hsla(0, 0%, 4%, 0.1);
}

.card-header-title {
    flex-grow: 1;
    font-weight: 700;
    padding: 0.75rem;
}

.card-header-icon {
    cursor: pointer;
    padding: 0.75rem;
}

.card-content {
    padding: 1.5rem;
}

Collapse Component

An easy disclosure widget to toggle content visability.

html
<o-collapse></o-collapse>

Props

Prop nameDescriptionTypeValuesDefault
contentIdId property of the content container - default is an uuidstring-useId()
expandedExpand the trigger to fullwidthboolean-false
labelSome label displayed in the summary element - unnecessary when trigger slot is usedstring-
nameSetting the same name to multiple collapse elements connects them together,
with only one open at a time.
This allows to easily create UI features such as accordions.
string-
openWhether collapse is open or not, use v-model:open to make it two-way bindingboolean-false
overrideOverride existing theme classes completelyboolean-
positionTrigger position"bottom" | "top"top, bottom
From config:
collapse: {
  position: "bottom"
}
triggerIdId property of the trigger container - default is an uuidstring-useId()

Events

Event namePropertiesDescription
update:openvalue boolean - updated open propopen prop two-way binding
openevent ToggleEvent - the native toggle eventon collapse opened
closeevent ToggleEvent - the native toggle eventon collapse closed

Slots

NameDescriptionBindings
triggerDefine the collapse trigger elementopen boolean - collapse open state
defaultContent to collapse

Class Inspector

Classes applied to the element:
Want to know how does the Class Inspector work?
Class propDescriptionPropsSuffixes
rootClass
Class of the root element.
positionClass
Class of the root element with position.
position
triggerClass
Class of the trigger element.
expandedClass
Class of the trigger element when expanded.
expanded
contentClass
Class of the content element.

Sass Variables

Current theme ➜ Oruga

SASS VariableDefault

See ➜ 📄 SCSS file

Current theme ➜ Bulma

The theme does not have any custom variables for this component.

Current theme ➜ Bootstrap

The theme does not have any custom variables for this component.

Released under the MIT License.