Hoppa till innehåll

CheckboxGroup

CheckboxGroup

PropTypeDescription
idstringUnique identifier for the component.
Default: generateId()
namestringName attribute for the checkbox group.
optionsArray<string> Array<{ label, value }>Array of options for the checkbox group.
legendstringFieldset legend.
descriptionstringDescription text displayed below the legend.
legendVisuallyHiddenbooleanIf the legend should be hidden visually.
Default: false
disabledboolean Array<string>If the field is disabled. Can disable all options or specific ones.
Default: false
showbooleanShow or hide the component without re-rendering.
Default: true
valueArray<string>Bound value for the checkbox group.
Default: undefined
<script>
import { Panel, CheckboxGroup } from '@soleil-se/config-svelte';
</script>
<Panel heading="Inställningar">
<CheckboxGroup
name="checkboxGroup1"
legend="Checkboxgrupp 1"
options={['Värde 1', 'Värde 2', 'Värde 3']}
/>
<CheckboxGroup
name="checkboxGroup2"
legend="Checkboxgrupp 2"
description="A helpful description for the checkbox group"
options={[
{ label: 'Värde 1', value: 'value1'},
{ label: 'Värde 2', value: 'value2'},
{ label: 'Värde 3', value: 'value3'},
]}
/>
</Panel>
Advanced
<script>
import { Panel, CheckboxGroup } from '@soleil-se/config-svelte';
import { onSave } from '@soleil-se/config-svelte/utils';
const { values } = $props();
values = {
checkboxGroup1: [],
checkboxGroup2: [],
...values
};
onSave(() => values);
</script>
<Panel heading="Inställningar">
<CheckboxGroup
bind:value={values.checkboxGroup1}
legend="Checkboxgrupp 1"
options={['Värde 1', 'Värde 2', 'Värde 3']}
/>
<CheckboxGroup
bind:value={values.checkboxGroup2}
legend="Checkboxgrupp 2"
options={[
{ label: 'Värde 1', value: 'value1'},
{ label: 'Värde 2', value: 'value2'},
{ label: 'Värde 3', value: 'value3'},
]}
/>
</Panel>

Default slot after checkbox group.

<CheckboxGroup name="checkboxGroup" legend="Checkbox group" {options} />
<p>Element in the checkbox group</p>
</CheckboxGroup>

Slot for the text in the legend element.

<CheckboxGroup name="checkboxGroup" {options} />
{#snippet legend()}
Custom <em>legend</em>
{/snippet}
</CheckboxGroup>

Slot for content in the description in the legend element.

<CheckboxGroup name="checkboxGroup" {options} />
{#snippet description()}
Custom <em>description</em>
{/snippet}
</CheckboxGroup>

Use the value prop to set a default value when not binding the value:

<CheckboxGroup
name="checkboxGroup1"
legend="Checkboxgrupp 1"
options={['Värde 1', 'Värde 2', 'Värde 3']}
value="{['Värde 2', 'Värde 3']}"
/>