Skip to content
VinUIComponentsCollapsible

Collapsible

One section that shows or hides, behind a small button. Same markup and props in every style: switch the style in the header to see it change.

Basic

Closed until someone asks for more.

Order details

2 items · Ships in 2 days · Free delivery

collapsible-basic.html
<details class="vin-collapsible" style="width: 100%; max-width: 360px">
  <summary class="vin-collapsible__trigger">Order details</summary>
  <div class="vin-collapsible__content">
    <p class="vin-muted">2 items · Ships in 2 days · Free delivery</p>
  </div>
</details>

Advanced settings

Hide options most people don't need. It starts open here.

Advanced settings
collapsible-form.html
<details class="vin-collapsible" style="width: 100%; max-width: 360px" open>
  <summary class="vin-collapsible__trigger">Advanced settings</summary>
  <div class="vin-collapsible__content" style="display: grid; gap: 12px">
    <div class="vin-field">
      <label class="vin-label" for="col-timeout">Timeout (seconds)</label>
      <input id="col-timeout" class="vin-input" type="number" value="30">
    </div>
    <div class="vin-choice">
      <input id="col-retry" class="vin-checkbox" type="checkbox" checked>
      <div class="vin-choice__body">
        <label class="vin-choice__label" for="col-retry">Retry failed requests</label>
      </div>
    </div>
  </div>
</details>

In a card

A short list with the rest tucked away.

Who has access

Ada Lovelace and 3 others.

Show everyone

Alan Turing, Grace Hopper, Katherine Johnson

collapsible-card.html
<div class="vin-card" style="width: 100%; max-width: 360px">
  <div class="vin-card__header">
    <h3 class="vin-card__title">Who has access</h3>
    <p class="vin-card__desc">Ada Lovelace and 3 others.</p>
  </div>
  <div class="vin-card__body">
    <details class="vin-collapsible">
      <summary class="vin-collapsible__trigger">Show everyone</summary>
      <div class="vin-collapsible__content">
        <p class="vin-muted">Alan Turing, Grace Hopper, Katherine Johnson</p>
      </div>
    </details>
  </div>
</div>

Installation

React, Vue and Svelte: add the component to your project with the CLI. It reads your framework from vin.json and also copies any component this one needs. Then import it:

Terminal
npx @vinish/ui add collapsible
React
import { Collapsible } from "@/components/vin/collapsible";
Vue
import Collapsible from "@/components/vin/collapsible.vue";
Svelte
import Collapsible from "$lib/components/vin/collapsible.svelte";

The import paths assume the default folders: @/components/vin (React and Vue, with the usual @ → src alias) and $lib/components/vin (SvelteKit). Use your own if you chose another folder in init. How the Vue and Svelte versions pass values and content is in Frameworks.

Plain HTML: the classes come with the style's stylesheet. It needs no JavaScript.

API

From spec/collapsible.json, which every framework version is tested against.

PropValuesDefaultIn HTML
trigger
The button text.
ReactNode—summary.vin-collapsible__trigger
open / defaultOpen
Use onOpenChange to hear about changes.
booleanfalseopen attribute on <details>
childrenReactNode—.vin-collapsible__content

Parts

React, Vue, SvelteHTML classes
<Collapsible>.vin-collapsible.vin-collapsible__trigger.vin-collapsible__content

Accessibility

  • A native <details>: the trigger is a button that says "expanded" or "collapsed".
  • Write the trigger so it makes sense either way ("Advanced settings", not "Show more" that never changes).
  • Content inside is found by find-in-page, which opens it.