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

Dropdown2

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

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

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

Members

Property NameTypeBindableDefaultComment
allowFlipPopover2FlipAxis | undefinedno'both'Which axis/axes allow the dropdown content to flip to the other side when there is not enough space.
anchorOriginPopover2Nonant | undefinedno'bottom-left'The point in a 3x3 grid on the anchor that should be used as the origin for the dropdown.
disabledboolean | null | undefinednofalseWhen true, the dropdown is disabled and closed
lightDismissboolean | null | undefinednotrueWhen true, the dropdown closes when another element is clicked or focused. Also closes when another dropdown opens.
iconSnippet | undefinednoundefinedThe icon after the value. When undefined, displays a chevron.
onOpen(open: boolean | null | undefined) => voidnoundefinedCalled when the dropdown opens or closes
offsetXnumberno0The how many pixels to move the dropdown left (negative) or right (positive).
offsetYnumberno0The how many pixels to move the dropdown up (negative) or down (positive).
openboolean | null | undefinedyesfalseWhen true, the dropdown is open
placement'auto'| Popover2Nonant | undefinedno'bottom-right'How the dropdown should be positioned relative to the anchor point. When 'auto', placement follows anchorOrigin.
valuestring | Snippet | undefinednoundefinedThe value to display.

Considerations

  • Dropdown2 uses Popover2.
  • Includes HTMLDivElement props, events, and methods.

Anatomy

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