Selector
Selector lets someone choose one string value from a dropdown. keep the selected value in your app and use the option labels for the words people see.
New articles will go to Weekend reading.
usage
<script>
import { Selector } from '@ciabi/loafkit-ui';
let shelf = $state('weekend');
const options = [
{ value: 'weekend', label: 'Weekend reading' },
{ value: 'garden', label: 'Garden notes' },
{ value: 'recipes', label: 'Recipes to try' }
];
</script>
<Selector label="Save to shelf" {options} bind:selected={shelf} />
<p>New articles will go to {options.find(option => option.value === shelf)?.label}.</p>state and options
the label appears inside the trigger. use aria-label for an explicit accessible name and aria-describedby for guidance. invalid adds a data attribute; it doesn’t create a form validity rule.
Selector has no name prop or hidden form input. include the selected value in app submission logic, or add a separate hidden input when using FormData.
keyboard and dismissal
Enter or Space opens the list. arrows move through options; Home and End move to the edges. selecting returns focus to the trigger. Escape closes and returns focus, Tab closes while leaving normal tab navigation, and an outside pointer closes without stealing its target’s focus.
submit an app-owned selection
<script lang="ts">
import { Selector } from '@ciabi/loafkit-ui';
let formShelf = $state('');
let shelfError = $state('');
let submittedShelf = $state('');
</script>
<form onsubmit={event => {
event.preventDefault();
if (!formShelf) { shelfError = 'choose a shelf first.'; return; }
shelfError = '';
submittedShelf = String(new FormData(event.currentTarget).get('shelf'));
}}>
<Selector label="collection shelf" bind:selected={formShelf} invalid={!!shelfError} aria-describedby="selector-form-error"
options={[{value:'weekend',label:'weekend reading'},{value:'garden',label:'garden notes'}]} />
<input type="hidden" name="shelf" value={formShelf} />
<p id="selector-form-error" role="status">{shelfError}</p>
<button type="submit">save shelf</button>
</form>
{#if submittedShelf}<p role="status">submitted shelf: {submittedShelf}</p>{/if}API reference
Selector
options- Default:
[]distinct string values with visible labels.
label- Default:
''text in the trigger.
disabled- Default:
falsemakes the control unavailable.
fullWidth- Default:
truefills the available width.
selected- Default:
''the selected option value.
onValueChange-
called with the selected string value.
id-
unique ID used by the component and its control relationships.
aria-label-
an explicit accessible name.
aria-describedby-
IDs of supporting descriptions.
invalid- Default:
falsemarks the visual invalid state; your app supplies validation.
class- Default:
''extra classes on the component root.
style-
inline styles on the component root.
SelectOption
one option supplied to Selector; this local shape is not a package export.