Live preview

Interactive example

Loading example…

Usage

Import the component and its manager, then make it your own.

ComponentDropdown
Managercreate_dropdown_manager

svelte

<script>
  // Import the shared stylesheet once in your application's root layout.
  import "sveltekit-ui/style.css"
  import { Dropdown, create_dropdown_manager } from "sveltekit-ui"

  const manager = create_dropdown_manager({
    label: "Project status",
    val: "draft",
    options: [
      { key: "draft", name: "Draft" },
      { key: "review", name: "In review" },
      { key: "published", name: "Published" },
    ],
    is_searchable: true,
  })
</script>

<Dropdown {manager} />
<p>Selected: {manager.val}</p>

API reference

Configure the manager, call its methods, and read its reactive state.

42 entries in configuration

PropertyTypeDefaultDescription
valany nullthe current selection; can be a single value or array for multiselect
optionsarray []the array of selectable items; each item can be a simple value or an object
on_changefunction nullcallback invoked on each selection, receiving the new val
on_item_clickfunction nullcallback invoked whenever an item is clicked, receiving the item object
on_dropdown_openedfunction nullcallback triggered when the dropdown popover is opened
on_dropdown_closedfunction nullcallback triggered when the dropdown popover is closed
on_searchfunction nulloptional async callback for searching items, called with { input, id } and returning { options }
labelstring nulllabel text displayed above or near the dropdown
typestring dropdownmode: 'dropdown' or 'horiz_selector'
is_collapsedboolean falseif true, operates in 'collapsed' mode for toggling
val_keystring keykey in each option object used to identify the value
row_display_keysarray ["name"]array of keys from which to build a display string for each row
button_display_keysarray ["name"]array of keys used to show text in the dropdown button
is_multiselectboolean falseif true, multiple values can be selected
is_set_null_buttonboolean falseif true, provides a button to clear the selection
is_disabledboolean falsedisables the entire control if true
headerstring nullheader text for horizontal selector
header_iconstring nullicon id displayed next to header if using horiz_selector
header_icon_degnumber 0icon rotation in degrees for the header icon
min_header_widthnumber 2minimum width (rem) reserved for the header text in horiz_selector
spacer_colorstring var(--shadow2-t)color for the vertical spacer in horiz_selector
error_messagestring nullerror text displayed under the label
placeholderstring Selectplaceholder text if no selection is made
target_widthnumber 250popover width in px
target_heightnumber 200popover height in px
font_weightnumber 500font weight for displayed items
font_sizenumber 1.2font size (rem) for displayed items
is_show_xboolean falseif true, an x to close the popover is shown
text_alignstring lefttext alignment for items (left, center, right)
justify_contentstring space-betweenjustification for label+arrow in the default button
is_show_arrowboolean trueif true, an arrow toggle is shown in the button
button_typestring outlinedstyle type for the toggle button (primary, outlined, etc.)
selected_font_sizenumber nulloptional alternate font size used specifically for the selection in the toggle button
is_button_compressedboolean falsemakes the dropdown button narrower if true
is_searchableboolean falseif true, shows a text input for filtering or triggering an on_search callback
is_hide_buttonboolean falseif true, hides the main toggle button for a fully open experience
anchor_idstring nullspecifies the element id to anchor the popover, or defaults to the toggle button
mlnumber 0margin-left in rem for the button
mrnumber 0margin-right in rem for the button
mtnumber 0margin-top in rem for the button
mbnumber 0margin-bottom in rem for the button
item_mbnumber 0margin-bottom in rem for each dropdown item