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

Dropdown

A value and associated button to open/close a floating content box.

Code
<script lang="ts">
  import { Dropdown } from '@geoffcox/sterling-svelte';
</script>

<Dropdown bind:open>
  {#snippet value()}
    <!-- TODO: value display -->
  {/snippet}
  {#snippet content()}
    <!-- TODO: dropdown content -->
  {/snippet}
</Dropdown>

Members

Property NameTypeBindableDefaultComment
disabledboolean | null | undefinednofalseWhen true, the dropdown is disabled and closed
iconSnippet | undefinednoundefinedThe icon after the value. When undefined, displays a chevron.
onOpen(open: boolean | null | undefined) => voidnoundefinedCalled when the dropdown opens or closes
openboolean | null | undefinednofalseWhen true, the dropdown is open
stayOpenOnClickAwayboolean | null | undefinednofalseWhen true and the user clicks away from the dropdown, it remains open
valuestring | Snippet | undefinednoundefinedThe value to display.
buttonstring | Snippet | undefinednoundefinedDeprecated. Use icon instead.
buttonIconstring | Snippet | undefinednoundefinedDeprecated. Use icon instead.

Considerations

  • Includes HTMLDivElement props, events, and methods.

Anatomy

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