enes

Dropdown

import { Dropdown } from 'fluentui-svelte';

The Dropdown lets users select one or more options from a list of DropdownOption children. Options can render rich content, such as a Persona, and the current selection is exposed through a bindable value.

Usage

<script>
	import { Dropdown, DropdownOption } from 'fluentui-svelte';
</script>

<Dropdown aria-label="Choose an option">
	<DropdownOption value="A" text="Option A">Option A</DropdownOption>
	<DropdownOption value="B" text="Option B">Option B</DropdownOption>
</Dropdown>

Shape

Set shape to rounded (default), square, or circular.

Custom Option Content

Options can render any content, such as a Persona. Pass a text prop so the closed dropdown can still display the selection.

Multiple Selection

Set the multiple prop to allow selecting more than one option at a time while pressing Ctrl (or Cmd on Mac).

Form Control Attributes

Attributes and events apply to the native form field; ref gives you access to it. For the container, use wrapperAttributes and wrapperRef.

Component Props

NameTypeDefaultDescription
shape'circular' | 'rounded' | 'square''rounded'Shape of the input surface, including its border and focus indicator.
value bindablestring | string[]multiple ? [] : ''The selected value. An array of values when multiple is set.
multiplebooleanAllows more than one option to be selected at a time.
placeholderstring'Select an option'The text shown by the trigger while no option is selected.
disabledbooleanDisables the user interaction.
namestring | nullThe name the value is submitted under. Without one, the form leaves the value out, as with any field.
wrapperRef bindableHTMLDivElement | nullThe DOM reference of the wrapper element.
wrapperAttributesHTMLAttributesThe attributes to spread on the wrapper element.
ref bindableHTMLSelectElement | nullThe DOM reference of the native select that holds the value. The other attributes of the dropdown are applied to it.
buttonRef bindableHTMLButtonElement | nullThe DOM reference of the button that opens the dropdown.
buttonAttributesHTMLButtonAttributesThe attributes to spread on the button that opens the dropdown.
flyoutRef bindableHTMLDivElement | nullThe DOM reference of the flyout element.
flyoutPropsFlyoutPropsThe props to spread on the flyout.
flyoutMaxHeightstringThe maximum height of the flyout, as a CSS length.
listboxRef bindableHTMLUListElement | nullThe DOM reference of the listbox element.
listboxPropsListViewPropsThe props to spread on the listbox rendered inside the flyout.
childrenSnippetThe DropdownOption elements of the list.
DropdownMultipleValue | DropdownSingleValue
NativeFieldAttributes<HTMLSelectAttributes>

DropdownOption Props

NameTypeDefaultDescription
textstringThe text shown by the dropdown once the option is selected. Falls back to the rendered children, which the server cannot read: pass it when rendering on the server.
ListViewItemProps<'li'>
Edit this Doc View as Markdown