enes

AutoSuggestBox New

The AutoSuggestBox component provides an input field with dynamic suggestions as users type. It enhances user experience by offering relevant suggestions, improving efficiency in form inputs and searches.

Usage

<script>
	import { AutoSuggestBox } from 'fluentui-svelte';
</script>

<AutoSuggestBox placeholder="Type a fruit...">
	<AutoSuggestBoxOption index={0} value="Apple">Apple</AutoSuggestBoxOption>
	<AutoSuggestBoxOption index={1} value="Banana">Banana</AutoSuggestBoxOption>
	<AutoSuggestBoxOption index={2} value="Cherry">Cherry</AutoSuggestBoxOption>
</AutoSuggestBox>

Suggestions are provided as AutoSuggestBoxOption a children of the AutoSuggestBox. As the user types, matching options will be shown.

Keyboard Navigation

Users can navigate through suggestions using the Up and Down arrow keys. Pressing Enter selects the highlighted suggestion.

Shape

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

Open on focus

Use the openOnFocus prop to show suggestions as soon as the text box receives focus, before anything is typed.

Virtualization

Window large suggestion sets by connecting AutoSuggestBox to a virtual list through the virtualizer prop.

Multiselect

Allow people to choose several suggestions and optionally show the selected values in the text box.

Virtualization with filtering

A virtualized list must filter its source data itself and report the filtered length through virtualizer.size.

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
wrapperRef bindableHTMLDivElement | nullThe DOM reference of the wrapper element.
ref bindableHTMLInputElement | nullThe DOM reference of the text box element.
value bindablestring''The current text of the box.
open bindablebooleanfalseControls the open state of the suggestion list.
multiselectbooleanLets more than one suggestion be chosen, and keeps the list open after each one.
selectOnFocusbooleanMirrors the suggestion under the cursor into the text box as it is walked over. Not supported together with multiselect.
openOnFocusbooleanfalseOpens the suggestion list as soon as the text box takes focus, instead of waiting for the first keystroke. Useful on touch devices, which have no arrow key to open the list with.
showTextualMultiselectbooleanLists every chosen suggestion in the text box, comma separated. Multiselect only.
notFoundTextstring'No results found'The message shown in place of the list when nothing matches.
selectedOptions bindable{ id: string; value: string }[][]The suggestions currently chosen.
suggestionChosen(e: Event, selection: string) => voidCalled when a suggestion is chosen: by clicking it, by pressing Enter on it, or by walking onto it while selectOnFocus is set.
querySubmitted(e: MouseEvent | KeyboardEvent, query: string) => voidCalled when Enter is pressed with no suggestion under the cursor, or when the search button is clicked. This is where a fresh set of suggestions is fetched. Enter then also submits the form with the typed text, unless the event is prevented.
virtualizerAutoSuggestVirtualizerBridge to a windowed list, for suggestion sets too long to render whole.
maxItemsInViewnumber6How many suggestions are visible before the list scrolls.
wrapperAttributesHTMLAttributesThe attributes to spread on the wrapper element.
flyoutRef bindableHTMLElement | nullThe DOM reference of the flyout holding the suggestion list.
flyoutPropsFlyoutPropsThe props to spread on the flyout.
listViewRef bindableHTMLUListElement | nullThe DOM reference of the suggestion list.
listViewPropsListViewItemPropsThe props to spread on the suggestion list.
shape, type, placeholder, hideActionButtons, textChanged, onClear from TextBoxProps
HTMLInputAttributes without value, type, role, size, placeholder

AutoSuggestBoxOption Props

NameTypeDefaultDescription
valuestringThe value reported to the box when the suggestion is chosen. Falls back to the id.
textstringThe text shown in the box once the suggestion is chosen. Falls back to value.
idstringThe id of the option element, referenced by the box through aria-activedescendant. Falls back to a generated id.
ref bindableHTMLLIElement | nullThe DOM reference of the option element.
disabledbooleanTakes the suggestion out of reach: it is shown, but the cursor steps over it.
indexnumberWhere the suggestion sits in the whole set. A windowed list needs the real index, not the position within the rendered slice.
ListViewItemProps<'li'> without as, value
Edit this Doc View as Markdown