enes

AutoSuggestBox Beta

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>

Component API

A brief explanation of the props that really need explaining. You can see the rest of the props here.

Suggestions

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.

Max Items In View

The `maxItemsInView` prop sets how many suggestions are visible before the flyout scrolls. If the number of options exceeds this value, a scrollbar will appear.

Suggestion Chosen Event

The `suggestionChosen` event is triggered when a user selects a suggestion from the list. The chosen suggestion value is passed as the second argument.

Query Submitted Event

The `querySubmitted` event is triggered when the user submits a query through the Search Button or typically by pressing Enter. This event can be used to handle the submission of the current input value.

Component Props

NameTypeDescription
placeholderstringPlaceholder text shown in the input.
valuestringThe current value of the input field.
openbooleanWhether the suggestion flyout is open. Default: `false`.
multiselectbooleanAllow selecting multiple suggestions.
selectOnFocusbooleanSelect a suggestion as it is focused during keyboard navigation.
notFoundTextstringText shown when no suggestions match. Default: `No results found`.
maxItemsInViewnumberNumber of suggestions visible before the flyout scrolls. Default: `6`.
refHTMLElementThe DOM reference of the auto-suggest box element.
suggestionChosen(e: Event, selection: string) => voidEvent triggered when a suggestion is chosen.
querySubmitted(e: MouseEvent | KeyboardEvent, query: string) => voidEvent triggered when a query is submitted.