Command palette

@yasinsensoy/web

Web · Components

Collapsible

A single collapsible section: "Advanced settings", "Show details", "Show more" on long text.

3 exports

Live example

Preview

Code

import { Collapsible } from "@yasinsensoy/web";

<Collapsible title="Advanced settings" description="Most users don't need to change these.">
  …
</Collapsible>

Events

  1. Events appear here when you interact with the preview.

With your own button

Import

import { Collapsible } from "@yasinsensoy/web";

Collapsible

componentClient component

A single collapsible section: "Advanced settings", "Show details", "Show more" on long text. For multiple sections use Accordion.

  • A built-in header (title, icon, description) or your own button (trigger).
  • The height animation is CSS only; instant with "reduced motion".
  • Closed content stays in the DOM and is hidden with hidden="until-found": when the browser's find in page (Ctrl+F) finds text inside, the section opens automatically.
  • "Show more" mode with collapsedHeight: no button for short content; on close the page scrolls to keep the button on screen.
Collapsible(props: CollapsibleProps): JSX.Element

Examples

<Collapsible title="Advanced settings" icon="settings">
  <SwitchField label="Debug mode" name="debug" />
</Collapsible>

<Collapsible trigger={<Button variant="link">Details</Button>}>…</Collapsible>

<Collapsible collapsedHeight={96}>{product.longDescription}</Collapsible>

Classes that can be given to the inner parts of Collapsible.

NameTypeDescription
trigger?stringBuilt-in header button.
content?stringArea wrapping the content.
toggle?string"Show more" button (with collapsedHeight).

Props of the Collapsible component.

Extends: Omit<ComponentProps<"div">, "title" | "children">

NameTypeDefaultDescription
children?ReactNodeContent that opens and closes.
title?ReactNodeText of the built-in header button. Not used when trigger is given.
description?ReactNodeSmall description below the title.
icon?IconPropIcon at the start of the title: a name or an element.
trigger?ReactElementYour own toggle button instead of the built-in header (e.g. <Button variant="ghost">). A click toggles it; aria-expanded and aria-controls are added automatically.
open?booleanOpen in controlled use?
defaultOpen?booleanfalseOpen initially in uncontrolled use?
onOpenChange?(open: boolean) => voidCalled with the new state when it opens or closes.
disabled?booleanCan't be toggled.
collapsedHeight?number"Show more" mode: while closed this much of the content (pixels) is visible, ending with a fading bottom edge; the button below opens all of it. If the content is shorter than this height the button never appears. For long descriptions, reviews and product details.
showMoreLabel?ReactNodethe {@link UIProvider} textText of the "Show more" button.
showLessLabel?ReactNodethe {@link UIProvider} textText of the "Show less" button.
classNames?CollapsibleClassNamesClasses added to the inner parts.
effect?EffectPropEffect or effects of the header row (or the "Show more" button) (e.g. "ripple", "border"). Defaults to UIProvider appearance.defaults.collapsible.effect. See BuiltinEffect.