Skip to content
iv-ui v0.3.0

Collapsible

since 0.2.0

A single section that expands to reveal content.

import { Collapsible } from '@elluzion/iv-ui';

Basic

A titled section that starts closed.

Source· svelte Show Hide
<script lang="ts">
	import { Collapsible } from '@elluzion/iv-ui';
</script>

<Collapsible title="Request headers">
	<pre class="code">accept: application/json
x-request-id: 8f2c1a</pre>
</Collapsible>

<style>
	.code {
		margin: 0;
		font-family: var(--iv_font-mono);
		font-size: var(--iv_text-sm);
		color: var(--iv_foreground-dim);
	}
</style>
  • Use for one-off disclosure; use Accordion when sections form a set.
  • open is bindable; defaultOpen sets the uncontrolled initial state.
  • trigger replaces the default title and chevron content.

Controlled

Bind open and drive it from outside the component.

Source· svelte Show Hide
<script lang="ts">
	import { Button, Collapsible } from '@elluzion/iv-ui';

	let open = $state(false);
</script>

<div class="stack">
	<Collapsible title="Advanced options" bind:open>
		<p>Timeout, retry budget, and the cache policy for this route.</p>
	</Collapsible>
	<div class="row">
		<Button size="sm" variant="outline" onclick={() => (open = true)}>Open</Button>
		<Button size="sm" variant="ghost" onclick={() => (open = false)}>Close</Button>
	</div>
</div>

<style>
	.stack {
		display: flex;
		flex-direction: column;
		gap: var(--iv_spacing-md);
	}

	.row {
		display: flex;
		gap: var(--iv_spacing-sm);
	}
</style>

Custom trigger

The trigger snippet replaces the title with custom content.

Open the command palette with the shortcut shown above.

Source· svelte Show Hide
<script lang="ts">
	import { IconTerminal2 } from '@tabler/icons-svelte';
	import { Collapsible, Shortcut } from '@elluzion/iv-ui';
</script>

<Collapsible defaultOpen>
	{#snippet trigger()}
		<span class="trigger">
			<IconTerminal2 size={14} />
			Console
			<Shortcut keys={['⌘', 'K']} />
		</span>
	{/snippet}
	<p>Open the command palette with the shortcut shown above.</p>
</Collapsible>

<style>
	.trigger {
		display: inline-flex;
		align-items: center;
		gap: var(--iv_spacing-sm);
	}
</style>
import { Collapsible } from '@elluzion/iv-ui';

Props

5 props · 1 events · 2 snippets
PropTypeDefaultDescription
title string''Trigger text.
open bindableboolean—Open state. Bind with bind:open.
defaultOpen booleanfalseOpen on first render when uncontrolled.
disabled booleanfalseDisables interaction and applies the disabled treatment.
className string''Extra classes merged onto the root element.

class, id, style, aria-*, and data-* are forwarded through rest props.

Events

EventHandler typeDescription
onchange(e: CustomEvent<{ open: boolean }>) => voidCalled with { open } after the panel toggles.

The legacy on:name form is accepted for every event.

Snippets

SnippetTypeDescription
triggerSnippetCustom trigger content.
childrenSnippetContent rendered inside the component.
KeysAction
TabMoves focus to the trigger.
Enter / SpaceOpens or closes the section.
  • The trigger is a native button with aria-expanded and aria-controls.
  • The panel uses role="region" and is labelled by the trigger.
  • Animation is skipped when reduced motion is requested.
Class hooks
.iv-chevron.iv-collapsible.iv-open.iv-panel.iv-trigger.iv-trigger-label
iv-ui
↑ ↓ navigate ↵ open esc close minisearch · 482 records