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

Select2

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>

<Select2 bind:selectedValue>
  {#each items as item}
    <ListItem value={item} />
  {/each}
</Select2>

Members

Property NameTypeBindableDefaultComment
disabledboolean | null | undefinednofalseWhen true, the select's button is disabled and list is closed.
iconSnippet | undefinednoundefinedThe snippet to render the icon. Defaults to a chevron.
listClassstring | undefinednoundefinedAdditional class names to apply to the list.
onPending(value: string) => voidnoundefinedCalled when a value is selected in the list but not yet committed.
onSelect(value: string) => voidnoundefinedCalled when a value is selected.
openboolean | null | undefinednofalseWhen true, the select's dropdown is open.
selectedValuestring | undefinednoundefinedThe value of the selected item.
valueSnippet<[string | undefined]> | string | undefinednoundefinedThe string or snippet to display the value. The snippet is passed the selected value. If undefined, the selectedValue is displayed.
buttonSnippetSnippet | undefinednoundefinedDeprecated. Use icon instead.
valueSnippetSnippet<[string | undefined]> | undefinednoundefinedDeprecated. Use value instead.

Method NameParametersReturn TypeComment
scrollToSelectedItemScrolls to the selected item.

Considerations

  • Select2 uses Popover2
  • 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-2">
  <div class="value">
    {@render value()}
  </div>
  <div class="icon">
    {@render icon()}
  </div>
  <Popover>
    <div class="sterling-select-2-content">
      <List>
        {@render children()}
      </List>
    </div>
  </Popover>
</div>