sterling-svelte  2.0.0
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
buttonSnippetSnippet | undefinedundefinedThe snippet to render the button. Defaults to a chevron.
disabledboolean | null | undefinedfalseWhen true, the select's button is disabled and list is closed.
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.
valueSnippetSnippet<[string | undefined]> | undefinedundefinedThe snippet to render the value. Passed the selected value. Defaults to the selected value (string).

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

select (<div>)
  value (<div>)
    value (Snippet) | selectedValue (string) | &nbsp;
  button (<div>)
    button (Snippet) | chevron (<div>)
  popover (<Popover>)
    content <div>)
      list (<List>)
        children (Snippet)