Accordion

An interactive set of panels that hide and reveal sections.

Preview
Code

Basic Example

<script>
	import { Accordion, AccordionButton, AccordionContent, AccordionHeading, AccordionItem } from 'lithesome';

	const items = [
		{ title: 'First item', content: 'First item content', value: 'first' },
		{ title: 'Second item', content: 'Second item content', value: 'second' },
		{ title: 'Third item', content: 'Third item content', value: 'third' }
	];
</script>

<Accordion>
	{#each items as { title, content, value }}
		<AccordionItem {value}>
			<AccordionHeading>
				<AccordionButton>{title}</AccordionButton>
			</AccordionHeading>
			<AccordionContent>{content}</AccordionContent>
		</AccordionItem>
	{/each}
</Accordion>

API Reference

<Accordion />

PropertyTypeDescription
value string | string[]

The current value of the accordion.

onChange (val: string | string[]) => void

Fires whenever the `value` prop is changed.

ref E

The reference to the underlying element.

children Snippet<[ S extends Record<string, any> ? S : never ]>

The default snippet to render.

custom Snippet<[ S extends Record<string, any> ? { props: P; state: S; } : { props: P; } ]>

Snippet to be used when wanting a custom implementation. This will tell Lithesome not the render the default element and any state along with it.

StateTypeDescription
valuestring | string[]The value of the selected item(s).

<AccordionItem />

PropertyTypeDescription
value string

The value of the item.

disabled boolean

Disables the item, stop events from firing and skips over via keyboard navigation.

ref E

The reference to the underlying element.

children Snippet<[ S extends Record<string, any> ? S : never ]>

The default snippet to render.

custom Snippet<[ S extends Record<string, any> ? { props: P; state: S; } : { props: P; } ]>

Snippet to be used when wanting a custom implementation. This will tell Lithesome not the render the default element and any state along with it.

StateTypeDescription
activebooleanTrue if the item is active.
disabledbooleanTrue the item is disabled.

<AccordionHeading />

PropertyTypeDescription
level 1 | 2 | 3 | 4 | 5 | 6

ref E

The reference to the underlying element.

children Snippet<[ S extends Record<string, any> ? S : never ]>

The default snippet to render.

custom Snippet<[ S extends Record<string, any> ? { props: P; state: S; } : { props: P; } ]>

Snippet to be used when wanting a custom implementation. This will tell Lithesome not the render the default element and any state along with it.

StateTypeDescription
activebooleanTrue if the item is active.

<AccordionButton />

PropertyTypeDescription
ref E

The reference to the underlying element.

children Snippet<[ S extends Record<string, any> ? S : never ]>

The default snippet to render.

custom Snippet<[ S extends Record<string, any> ? { props: P; state: S; } : { props: P; } ]>

Snippet to be used when wanting a custom implementation. This will tell Lithesome not the render the default element and any state along with it.

StateTypeDescription
activebooleanTrue if the item is active.
disabledbooleanTrue the item is disabled.

<AccordionContent />

PropertyTypeDescription
ref E

The reference to the underlying element.

children Snippet<[ S extends Record<string, any> ? S : never ]>

The default snippet to render.

custom Snippet<[ S extends Record<string, any> ? { props: P; state: S; } : { props: P; } ]>

Snippet to be used when wanting a custom implementation. This will tell Lithesome not the render the default element and any state along with it.

StateTypeDescription
activebooleanTrue if the item is active.