Select
A value and a button to open/close a list of choices and select a single value
Code
<script lang="ts">
import { Select, ListItem } from '@geoffcox/sterling-svelte';
let selectedValue : string;
let items = [/* list of items */];
</script>
<Select bind:selectedValue>
{#each items as item}
<ListItem value={item} />
{/each}
</Select>
Members
| Property Name | Type | Default | Comment | | open | boolean | false |
| selectedValue | string | undefined | undefined |
| variant | string | '' |
| listVariant | string | '' |
| Event Name | Data | Comment | | pending | { value: string } |
| select | { value: string } |
| Method Name | Parameters | Return Type | Comment | | scrollToSelectedItem | | |
Considerations
- Due to lack of styling capabilities with <select>, the Select component does not use <select>
- Includes HTMLDivElement props, event, and methods
Anatomy
<div class="sterling-select">
<div class="value">
<slot name="value" {disabled} {open} {selectedValue} {variant}>
{selectedValue}
</slot>
</div>
<div class="button">
<slot name="button" {disabled} {open} {selectedValue} {variant}>
<slot name="icon" {disabled} {open} {selectedValue} {variant}>
<div class="chevron" />
</slot>
</slot>
</div>
<Popover>
<div class="sterling-select-popup-content">
<List>
<!-- Items to display in the dropdown -->
<slot {variant} {listVariant} />
</List>
</div>
</Popover>
</div>