Collapsible
An interactive component which expands/collapses a panel.
Props
Features
- 🎹 Keyboard navigation
Usage
<script lang="ts"> import { Collapsible } from "melt";
const collapsible = new Collapsible();</script>
<button {...collapsible.trigger}>Open/Close content</button>
{#if collapsible.open} <div {...collapsible.content}>Content</div>{/if}
<script lang="ts"> import { Collapsible } from "melt/components";</script>
<Collapsible> {#snippet children(collapsible)} <button {...collapsible.trigger}>Open/Close content</button>
{#if collapsible.open} <div {...collapsible.content}>Content</div> {/if} {/snippet}</Collapsible>
API Reference
Constructor Props
The props that are passed when calling
new Collapsible()
new Collapsible()
export type CollapsibleProps = { /** * Whether the collapsible is disabled which prevents it from being opened. */ disabled?: MaybeGetter<boolean | undefined>;
/** * Whether the collapsible is open. */ open?: MaybeGetter<boolean | undefined>;
/** * A callback called when the value of `open` changes. */ onOpenChange?: (value: boolean) => void;};
export type CollapsibleProps = { /** * Whether the collapsible is disabled which prevents it from being opened. */ disabled?: MaybeGetter<boolean | undefined>;
/** * Whether the collapsible is open. */ open?: MaybeGetter<boolean | undefined>;
/** * A callback called when the value of `open` changes. */ onOpenChange?: (value: boolean) => void;};
Properties
The properties returned from
new Collapsible()
new Collapsible()
-
disabled
booleanboolean -
open
booleanbooleanThe open state of the collapsible. -
trigger
{readonly disabled: booleanreadonly onclick: () => voidreadonly "data-state": stringreadonly "data-disabled": "" | undefinedreadonly "data-melt-collapsible-trigger": ""readonly id: stringreadonly "aria-expanded": booleanreadonly "aria-controls": string}{readonly disabled: booleanreadonly onclick: () => voidreadonly "data-state": stringreadonly "data-disabled": "" | undefinedreadonly "data-melt-collapsible-trigger": ""readonly id: stringreadonly "aria-expanded": booleanreadonly "aria-controls": string}The spread attributes for the trigger button. -
content
{readonly "data-state": stringreadonly "data-disabled": "" | undefinedreadonly "data-melt-collapsible-content": ""readonly id: string}{readonly "data-state": stringreadonly "data-disabled": "" | undefinedreadonly "data-melt-collapsible-content": ""readonly id: string}The spread attributes for the content element.