Hoppa till innehåll

SelectField

SelectField

PropTypeDescription
idstringUnique identifier for the component.
Default: generateId()
labelstringLabel for the select field. Required.
namestringName attribute for the select field.
Default: undefined
requiredbooleanIf the field is required.
Default: false
disabledbooleanIf the field is disabled.
Default: false
showbooleanShow or hide the component without re-rendering.
Default: true
optionsArray<string> Array<{ label, value }>Array of options for the select field.
Default: []
valuestringBound value for the select field.
Default: ''
descriptionstringDescription text displayed below the input field.
<script>
import { Panel, SelectField } from '@soleil-se/config-svelte';
</script>
<Panel heading="Inställningar">
<SelectField name="select1" label="Select 1" options={['Värde 1', 'Värde 2', 'Värde 3']} />
<SelectField
name="select2"
label="Select 2"
options={[{ label: 'Value 1', value: 'value1' }, { label: 'Value 2', value: 'value2' }, { label: 'Value 3', value: 'value3' }]}
/>
</Panel>
Advanced
<script>
import { Panel, SelectField } from '@soleil-se/config-svelte';
import { onSave } from '@soleil-se/config-svelte/utils';
const values = {
select: '',
...window.CONFIG_VALUES
};
const options = ['Värde 1', 'Värde 2', 'Värde 3'];
onSave(() => values);
</script>
<Panel heading="Inställningar">
<SelectField bind:value={values.select} label="Select" {options} />
</Panel>

Default slot after select.

<SelectField name="select1" label="Select 1" options={['Värde 1', 'Värde 2', 'Värde 3']} >
<p>Some text</p>
</SelectField>

Slot for content in the label element.

<SelectField name="select1" options={['Värde 1', 'Värde 2', 'Värde 3']} >
{#snippet label()}
Custom <strong>label</strong>
{/snippet}
</SelectField>

Slot for content in the description element to be used instead of the prop when HTML formatting is needed.

<SelectField name="select1" options={['Värde 1', 'Värde 2', 'Värde 3']} >
{#snippet description()}
Custom <strong>description</strong>
{/snippet}
</SelectField>

Use the value attribute to set a default value:

<SelectField name="select1" label="Select 1" options={['Värde 1', 'Värde 2', 'Värde 3']} value="Värde 1" />