Collapsible
A trigger that shows and hides a panel of content.
Usage
import { Component, ViewEncapsulation, signal } from '@angular/core';import { ScButton, ScCollapsible, ScCollapsiblePanel, ScCollapsibleTrigger, ScFrame,} from '@semantic-components/ui';import { SiChevronsUpDownIcon } from '@semantic-icons/lucide-icons';
/** A trigger that shows and hides a panel: the order and its details. */@Component({ selector: 'app-collapsible-usage-demo', imports: [ ScButton, ScCollapsible, ScCollapsiblePanel, ScCollapsibleTrigger, ScFrame, SiChevronsUpDownIcon, ], template: ` <div scCollapsible [(open)]="open" class="flex w-[350px] flex-col gap-2"> <div class="flex items-center justify-between gap-4 ps-4"> <h3 class="text-sm font-semibold">Order #4189</h3> <button scButton scCollapsibleTrigger variant="ghost" size="icon-sm"> <svg siChevronsUpDownIcon></svg> <span class="sr-only">Toggle details</span> </button> </div> <div scFrame class="flex items-center justify-between px-4 py-2 text-sm"> <span class="text-muted-foreground">Status</span> <span class="font-medium">Shipped</span> </div> <div scCollapsiblePanel class="-m-px flex flex-col gap-2 p-px"> <div scFrame class="px-4 py-2 text-sm"> <p class="font-medium">Shipping address</p> <p class="text-muted-foreground">100 Market St, San Francisco</p> </div> <div scFrame class="px-4 py-2 text-sm"> <p class="font-medium">Items</p> <p class="text-muted-foreground">2x Studio Headphones</p> </div> </div> </div> `, host: { class: 'flex w-full justify-center' }, encapsulation: ViewEncapsulation.None,})export class CollapsibleUsageDemo { private readonly open = signal(false);}Anatomy
Base UI's Collapsible: a root holding open, a trigger on your button, a panel with its content written inside.
import { ScCollapsible, ScCollapsiblePanel, ScCollapsibleTrigger } from '@semantic-components/ui';<div scCollapsible [(open)]="…"> <button scButton scCollapsibleTrigger>…</button> <div scCollapsiblePanel>…</div></div>Accessibility
- The disclosure pattern: a native button, aria-expanded, and aria-controls naming its panel; Space and Enter toggle it.
- Name an icon trigger with sr-only text; its name stays the same as it opens and closes.
- Closed, its panel is hidden from everyone; with hiddenUntilFound, find-in-page still finds its text and opens it.
Examples
Basic
import { Component, ViewEncapsulation } from '@angular/core';import { ScButton, ScCard, ScCardBody, ScCollapsible, ScCollapsiblePanel, ScCollapsibleTrigger,} from '@semantic-components/ui';import { SiChevronDownIcon } from '@semantic-icons/lucide-icons';Settings
import { Component, ViewEncapsulation, signal } from '@angular/core';import { ScButton, ScCard, ScCardBody, ScCardDescription, ScCardHeader, ScCardTitle, ScCollapsible, ScCollapsiblePanel,File tree
import { NgTemplateOutlet } from '@angular/common';import { Component, ViewEncapsulation } from '@angular/core';import { RouterLink } from '@angular/router';import { ScButton, ScCard, ScCardBody, ScCardHeader, ScCardTitle, ScCollapsible,Hidden until found
Standard shipping takes 3–5 business days. Search this page for "business days": the panel opens.
import { Component, ViewEncapsulation } from '@angular/core';import { ScButton, ScCollapsible, ScCollapsiblePanel, ScCollapsibleTrigger,} from '@semantic-components/ui';import { SiChevronDownIcon } from '@semantic-icons/lucide-icons';
/** hiddenUntilFound: closed, still searched by the browser's find-in-page (Ctrl+F); a match opens it. */Disabled
Not shown: disabled.
import { Component, ViewEncapsulation } from '@angular/core';import { ScButton, ScCollapsible, ScCollapsiblePanel, ScCollapsibleTrigger,} from '@semantic-components/ui';import { SiChevronDownIcon } from '@semantic-icons/lucide-icons';
/** disabled: its trigger does nothing. */Open by default
Version 2 adds dark mode and a faster search.
Open: true
import { Component, ViewEncapsulation, signal } from '@angular/core';import { ScButton, ScCollapsible, ScCollapsiblePanel, ScCollapsibleTrigger,} from '@semantic-components/ui';import { SiChevronDownIcon } from '@semantic-icons/lucide-icons';
/** [(open)] starting true: shown until its trigger closes it. */Trigger elsewhere
Orders
Showing all 24 orders.
- Status: any
- Date: last 30 days
- Total: any
import { Component, ViewEncapsulation } from '@angular/core';import { ScButton, ScCollapsible, ScCollapsiblePanel, ScCollapsibleTrigger, ScFrame,} from '@semantic-components/ui';
/**RTL
الطلب #4189
الحالةتم الشحن
عنوان الشحن
100 Market St, San Francisco
العناصر
2x سماعات الاستوديو
import { Dir } from '@angular/cdk/bidi';import { Component, LOCALE_ID, ViewEncapsulation, signal } from '@angular/core';import { ScButton, ScCollapsible, ScCollapsiblePanel, ScCollapsibleTrigger, ScFrame,} from '@semantic-components/ui';import { SiChevronsUpDownIcon } from '@semantic-icons/lucide-icons';API reference
Each part takes class, merged over its own (cn: a later class wins).
| Part | Selector | Description |
|---|---|---|
ScCollapsible | [scCollapsible] | The disclosure: open (two-way), disabled; data-open / data-closed. |
ScCollapsibleTrigger | button[scCollapsibleTrigger] | Shows and hides the panel: aria-expanded, aria-controls, data-panel-open. Behaviour only: its look is yours (scButton). |
ScCollapsiblePanel | div[scCollapsiblePanel] | Its content written inside. Closed, hidden, its height animating; hiddenUntilFound: still searched by find-in-page, a match opens it. |