sterling-svelte  2.0.3
A modern, accessible, lightweight UI component library for Svelte.

Select

A value and a button to open/close a list of choices.

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 NameTypeDefaultComment
disabledboolean | null | undefinedfalseWhen true, the select's button is disabled and list is closed.
iconSnippet | undefinedundefinedThe snippet to render the icon. Defaults to a chevron.
listClassstring | undefinedundefinedAdditional class names to apply to the list.
onPending(value: string) => voidundefinedCalled when a value is selected in the list but not yet committed.
onSelect(value: string) => voidundefinedCalled when a value is selected.
openboolean | null | undefinedfalseWhen true, the select's dropdown is open.
selectedValuestring | undefinedundefinedThe value of the selected item.
valueSnippet<[string | undefined]> | string | undefinedundefinedThe string or snippet to display the value. The snippet is passed the selected value. If undefined, the selectedValue is displayed.
buttonSnippetSnippet | undefinedundefinedDeprecated. Use icon instead.
valueSnippetSnippet<[string | undefined]> | undefinedundefinedDeprecated. Use value instead.

Method NameParametersReturn TypeComment
scrollToSelectedItemScrolls to the selected item.

Considerations

  • Due to lack of styling capabilities with <select>, the Select component does not use <select>
  • Includes HTMLDivElement props, events, and methods.

Anatomy

<div class="sterling-select">
  <div class="value">
    {@render value()}
  </div>
  <div class="icon">
    {@render icon()}
  </div>
  <Popover>
    <div class="sterling-select-popup-content">
      <List>
        {@render children()}
      </List>
    </div>
  </Popover>
</div>