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
<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>Order details
2 items · Ships in 2 days · Free delivery
import { Collapsible } from "@/components/vin/collapsible";
import { Text } from "@/components/vin/typography";
export function CollapsibleBasic() {
return (
<Collapsible trigger="Order details" style={{ width: "100%", maxWidth: 360 }}>
<Text variant="muted">2 items · Ships in 2 days · Free delivery</Text>
</Collapsible>
);
}The Vue version renders the same markup as the HTML tab, so it looks and works the same.
<script setup lang="ts">
import Collapsible from "@/components/vin/collapsible.vue";
import { Text } from "@/components/vin/typography.vue";
</script>
<template>
<Collapsible trigger="Order details" style="width: 100%; max-width: 360px">
<Text variant="muted">2 items · Ships in 2 days · Free delivery</Text>
</Collapsible>
</template>The Svelte version renders the same markup as the HTML tab, so it looks and works the same.
<script lang="ts">
import Collapsible from "$lib/components/vin/collapsible.svelte";
import Text from "$lib/components/vin/typography.svelte";
</script>
<Collapsible trigger="Order details" style="width: 100%; max-width: 360px">
<Text variant="muted">2 items · Ships in 2 days · Free delivery</Text>
</Collapsible>Advanced settings
Hide options most people don't need. It starts open here.
Advanced settings
<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>Advanced settings
import { Collapsible } from "@/components/vin/collapsible";
import { Field } from "@/components/vin/input";
import { Checkbox } from "@/components/vin/checkbox";
export function CollapsibleForm() {
return (
<Collapsible trigger="Advanced settings" defaultOpen style={{ width: "100%", maxWidth: 360 }} contentProps={{ style: { display: "grid", gap: 12 } }}>
<Field label="Timeout (seconds)" type="number" defaultValue="30" />
<Checkbox label="Retry failed requests" defaultChecked />
</Collapsible>
);
}The Vue version renders the same markup as the HTML tab, so it looks and works the same.
<script setup lang="ts">
import Checkbox from "@/components/vin/checkbox.vue";
import Collapsible from "@/components/vin/collapsible.vue";
import Field from "@/components/vin/input.vue";
</script>
<template>
<Collapsible trigger="Advanced settings" default-open style="width: 100%; max-width: 360px" :content-props="{ style: { display: 'grid', gap: '12px' } }">
<Field label="Timeout (seconds)" type="number" default-value="30" />
<Checkbox label="Retry failed requests" default-checked />
</Collapsible>
</template>The Svelte version renders the same markup as the HTML tab, so it looks and works the same.
<script lang="ts">
import Collapsible from "$lib/components/vin/collapsible.svelte";
import Field from "$lib/components/vin/input-field.svelte";
import Checkbox from "$lib/components/vin/checkbox.svelte";
</script>
<Collapsible trigger="Advanced settings" open style="width: 100%; max-width: 360px" contentProps={{ style: "display: grid; gap: 12px" }}>
<Field label="Timeout (seconds)" type="number" value="30" />
<Checkbox label="Retry failed requests" checked />
</Collapsible>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
<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>Who has access
Ada Lovelace and 3 others.
Show everyone
Alan Turing, Grace Hopper, Katherine Johnson
import { Card, CardHeader, CardTitle, CardDescription, CardBody } from "@/components/vin/card";
import { Collapsible } from "@/components/vin/collapsible";
import { Text } from "@/components/vin/typography";
export function CollapsibleCard() {
return (
<Card style={{ width: "100%", maxWidth: 360 }}>
<CardHeader>
<CardTitle>Who has access</CardTitle>
<CardDescription>Ada Lovelace and 3 others.</CardDescription>
</CardHeader>
<CardBody>
<Collapsible trigger="Show everyone">
<Text variant="muted">Alan Turing, Grace Hopper, Katherine Johnson</Text>
</Collapsible>
</CardBody>
</Card>
);
}The Vue version renders the same markup as the HTML tab, so it looks and works the same.
<script setup lang="ts">
import Card, { CardHeader, CardTitle, CardDescription, CardBody } from "@/components/vin/card.vue";
import Collapsible from "@/components/vin/collapsible.vue";
import { Text } from "@/components/vin/typography.vue";
</script>
<template>
<Card style="width: 100%; max-width: 360px">
<CardHeader>
<CardTitle>Who has access</CardTitle>
<CardDescription>Ada Lovelace and 3 others.</CardDescription>
</CardHeader>
<CardBody>
<Collapsible trigger="Show everyone">
<Text variant="muted">Alan Turing, Grace Hopper, Katherine Johnson</Text>
</Collapsible>
</CardBody>
</Card>
</template>The Svelte version renders the same markup as the HTML tab, so it looks and works the same.
<script lang="ts">
import Card from "$lib/components/vin/card.svelte";
import CardHeader from "$lib/components/vin/card-header.svelte";
import CardTitle from "$lib/components/vin/card-title.svelte";
import CardDescription from "$lib/components/vin/card-description.svelte";
import CardBody from "$lib/components/vin/card-body.svelte";
import Collapsible from "$lib/components/vin/collapsible.svelte";
import Text from "$lib/components/vin/typography.svelte";
</script>
<Card style="width: 100%; max-width: 360px">
<CardHeader>
<CardTitle>Who has access</CardTitle>
<CardDescription>Ada Lovelace and 3 others.</CardDescription>
</CardHeader>
<CardBody>
<Collapsible trigger="Show everyone">
<Text variant="muted">Alan Turing, Grace Hopper, Katherine Johnson</Text>
</Collapsible>
</CardBody>
</Card>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:
npx @vinish/ui add collapsibleimport { Collapsible } from "@/components/vin/collapsible";import Collapsible from "@/components/vin/collapsible.vue";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.
| Prop | Values | Default | In HTML |
|---|---|---|---|
triggerThe button text. | ReactNode | — | summary.vin-collapsible__trigger |
open / defaultOpenUse onOpenChange to hear about changes. | boolean | false | open attribute on <details> |
children | ReactNode | — | .vin-collapsible__content |
Parts
| React, Vue, Svelte | HTML 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.
Customize
Saved in this browser. Style and accent are in the header.