Documentation Upgrade
Start here
CwDropdown is a custom select/combobox wrapper. Pass the option list, bind the selected value, and let the component handle keyboard navigation and popover positioning.
Copy-paste examples
These snippets intentionally show the full public API surface the live demo relies on.
Controlled dropdown
This is the most common usage in forms and filters.
<script lang="ts">
const fruitOptions = [
{ label: 'Apple', value: 'apple' },
{ label: 'Banana', value: 'banana' },
{ label: 'Dragonfruit', value: 'dragonfruit', disabled: true }
];
let selectedFruit = $state('');
</script>
<CwDropdown
options={fruitOptions}
label="Fruit"
placeholder="Choose a fruit..."
bind:value={selectedFruit}
/>
Form validation and change callback
Use `required` and `error` when the selection is mandatory.
<script lang="ts">
const siteOptions = [
{ label: 'North greenhouse', value: 'north' },
{ label: 'South greenhouse', value: 'south' }
];
let site = $state('');
let error = $state('');
function handleChange(value: string) {
site = value;
error = '';
}
</script>
<CwDropdown
options={siteOptions}
name="site"
required
label="Deployment site"
error={error}
value={site}
onchange={handleChange}
/>