Inputs
SearchBox
A search box (SearchBox) provides an input field for searching content within a site or app to find specific items. On top of a plain text input it adds a search icon, a clear button, an optional search button, and an optional suggest (auto-complete) callout backed either by an in-memory list or by an async, cancellable items provider. The input follows the WAI-ARIA combobox pattern: it exposes the suggest list to screen readers, announces the outcome of every search through its own live region, and supports full keyboard navigation with the arrow keys, Page Up/Page Down, Home/End, Enter and Escape.
Usage
Every example is live. Open its code to see exactly what produced the component running underneath.
Basic
ReadOnly keeps the value visible and selectable but blocks editing, clearing and picking suggestions, while IsEnabled="false" renders the disabled state which additionally takes the whole component out of the tab order. Required renders the required html attribute on the input element.
Label
Use LabelTemplate when the label needs custom markup such as an icon or a required marker.
Underlined
NoBorder
Background
Icon
Search Button
Its glyph is customizable through SearchButtonIconName, SearchButtonIcon or a full SearchButtonTemplate, and its accessible name through SearchButtonAriaLabel.
Clear Button
Use HideClearButton to remove it, ClearButtonIconName / ClearButtonIcon / ClearButtonTemplate to restyle it, ClearButtonAriaLabel to localize its accessible name, and NoClearOnEscape to keep the value when escape is pressed.
Prefix & Suffix
https:// prefix still returns only what the user typed.
For anything richer than text, PrefixTemplate and SuffixTemplate take arbitrary markup and replace the plain-text variants entirely.
Input Behavior
Three attributes tune the on-screen keyboard of a touch device: InputMode picks which virtual keyboard to bring up (
BitInputMode.Search shows the layout optimized for search terms),
EnterKeyHint picks the label of its return key and already defaults to
BitEnterKeyHint.Search here because pressing enter always runs a search, and
SpellCheck turns the red squiggles on or off - setting it to false is usually the right call for
a search field, whose terms are rarely dictionary words.
SelectTextOnFocus selects whatever is already in the field every time it takes the focus, so that typing replaces the previous term instead of appending to it - the behavior a search box the user keeps coming back to needs.
FullWidth stretches the search box to fill the width of its container, which is required when the component sits inside a flex layout that would otherwise shrink it to its content.
Binding
OnChange is raised whenever the value changes, while OnSearch is raised only when the user actually asks for a search: pressing enter, clicking the search button, or picking a suggest item. Use DefaultValue instead of Value for the uncontrolled mode where the component owns its own state.
Events
Type, click, tab away and press escape in the field below to watch the event log fill up.
Suggestion (AutoComplete)
SuggestFilterFunction replaces the default case-insensitive "contains" matching, SuggestIgnoreDiacritics keeps that default matching but folds the accents away on both sides, so that "Jose" finds "José" without the user having to reproduce the diacritics, MinSuggestTriggerChars (3 by default) sets how many characters are needed before searching, MaxSuggestCount (5 by default) caps the number of rendered suggestions, and DebounceTime avoids hammering a remote provider on every keystroke. Stale provider calls are cancelled automatically through the CancellationToken of the request, so a slow response can never overwrite a newer one.
Modeless removes the invisible overlay that otherwise captures the first outside click, and FixedCalloutWidth pins the callout to the width of the component instead of letting it grow with the longest suggestion.
Picking a suggestion (by clicking it or by pressing enter while it is highlighted) writes it into the field, leaves the caret at its end so the term can be refined right away, and raises OnSuggestItemSelect followed by OnSearch.
Suggest Callout
NoResultsText (or NoResultsTemplate) keeps the callout open with an explanatory message when a search returns nothing, instead of silently closing it, LoadingText / LoadingTemplate show progress while an async SuggestItemsProvider is still running, and MinSuggestTriggerCharsText explains the third silent state: a term that is still shorter than MinSuggestTriggerChars, which otherwise looks exactly like a search that found nothing. It is a composite format receiving how many characters are still missing, and it also replaces the built-in sentence announced to screen readers.
AutoSelectSuggestItem pre-highlights the first suggestion so enter picks it right away, and ShowSuggestItemsOnFocus combined with MinSuggestTriggerChars="0" opens the list as soon as the field is focused, which is the usual way to surface default or recent searches.
Keyboard & Screen Readers
Screen readers never see the list appear, so the component also owns a visually hidden live region that reports the outcome of every search: how many suggestions were found, that there were none, or that the term is still shorter than MinSuggestTriggerChars. The AnnouncementProvider replaces those built-in English sentences with your own, which is the hook to localize them; it receives the search term, the suggestions, whether the provider is still loading and whether the term is too short, and returning null keeps the region silent.
Turn on a screen reader (or inspect the
role="status" element inside the component) and
type in both fields below to hear the difference between the default and the custom announcements.
Programmatic Control
InputElement exposes the underlying
ElementReference for anything the component
does not wrap itself.
Validation
aria-invalid attribute and
an error state when the field is invalid, and works with ValidationMessage. Set NoValidate to
opt out of that integration.
Color
External Icons
Size
Style & Class
RTL
API
Every parameter, public member, sub-class and enum this component exposes.
BitSearchBox parameters
| Name | Type | Default value | Description |
|---|---|---|---|
| AnnouncementProvider | Func<BitSearchBoxAnnouncementArgs, string?>? | null | Builds the text that the screen reader announces through the live region of the search box whenever the suggest items change, in place of the built-in English announcements. Returning null or an empty string announces nothing. |
| AutoSelectSuggestItem | bool | false | Automatically highlights the first suggest item as soon as the suggest list opens, so pressing enter selects it without pressing the arrow keys first. |
| Background | BitColorKind? | null | The background color kind of the search box. |
| CalloutFooterTemplate | RenderFragment? | null | The custom template rendered at the bottom of the suggest items callout. |
| CalloutHeaderTemplate | RenderFragment? | null | The custom template rendered at the top of the suggest items callout. |
| Classes | BitSearchBoxClassStyles? | null | Custom CSS classes for different parts of the search box. |
| ClearButtonAriaLabel | string | Clear | The accessible label (aria-label) of the clear button. |
| ClearButtonIcon | BitIconInfo? | null | Gets or sets the icon to display on the clear button using custom CSS classes for external icon libraries. Takes precedence over ClearButtonIconName when both are set. |
| ClearButtonIconName | string? | Cancel | Gets or sets the name of the icon to display on the clear button from the built-in Fluent UI icons. |
| ClearButtonTemplate | RenderFragment? | null | The custom template for clear button icon. |
| Color | BitColor? | null | The general color of the search box, used for colored parts like icons. |
| DisableAnimation | bool | false | Whether or not to animate the search box icon on focus. |
| EnterKeyHint | BitEnterKeyHint? | BitEnterKeyHint.Search | Sets the enterkeyhint html attribute of the input element, which tells virtual keyboards which action label to render on their enter key. It defaults to Search because pressing enter always runs a search here. |
| FixedCalloutWidth | bool | false | Forces the suggest callout width to be always fixed at the component's width. |
| FixedIcon | bool | false | Whether or not to make the icon be always visible (it hides by default when the search box is focused). |
| FullWidth | bool | false | Expands the search box to fill the available width of its container. |
| HideClearButton | bool | false | Whether to hide the clear button when the search box has value. |
| HideIcon | bool | false | Whether or not the icon is visible. |
| HighlightSuggestItems | bool | false | Highlights the part of each suggest item that matches the current search term. |
| Icon | BitIconInfo? | null | Gets or sets the icon to display using custom CSS classes for external icon libraries. Takes precedence over IconName when both are set. |
| IconName | string? | Search | Gets or sets the name of the icon to display from the built-in Fluent UI icons. |
| InputMode | BitInputMode? | null | Sets the inputmode html attribute of the input element. |
| Label | string? | null | The text of the label of the search box, rendered as a real label element tied to the input. |
| LabelTemplate | RenderFragment? | null | The custom template for the label of the search box. |
| LoadingTemplate | RenderFragment? | null | The custom template rendered in place of the default spinner while the SuggestItemsProvider is resolving the suggest items. |
| LoadingText | string? | null | The text rendered next to the loading indicator while the SuggestItemsProvider is resolving the suggest items. |
| MaxLength | int | -1 | Sets the maxlength html attribute of the input element. A negative value means no limit. |
| MaxSuggestCount | int | 5 | The maximum number of items or suggestions that will be displayed. A value of zero or less means no limit. |
| MinSuggestTriggerChars | int | 3 | The minimum character requirement for doing a search in suggest items. Setting it to zero also enables searching with an empty search term which is useful for showing default or recent items. |
| MinSuggestTriggerCharsText | string? | null | The composite format of the hint the callout shows while the typed term is still shorter than MinSuggestTriggerChars, which receives the number of characters that are still missing, for example "Type {0} more characters to search". The hint is never shown while the field is empty, and it replaces the built-in English sentence announced to screen readers as well. |
| Modeless | bool | false | Removes the overlay of suggest items callout. |
| NoBorder | bool | false | Removes the default border of the search box. |
| NoClearOnEscape | bool | false | Prevents clearing the value of the search box when the user presses the escape key. |
| NoResultsTemplate | RenderFragment? | null | The custom template rendered in the callout when the search finds no suggest item. |
| NoResultsText | string? | null | The text rendered in the callout when the search finds no suggest item. |
| NoWrapNavigation | bool | false | Stops the up and down arrows from cycling between the two ends of the suggest list, so that the highlight stops at the first and the last item instead of jumping from one to the other. |
| OnClear | EventCallback | Callback executed when the user clears the search box by either clicking 'X' or hitting escape. | |
| OnClick | EventCallback<MouseEventArgs> | Callback executed when the user clicks on the input of the search box. | |
| OnEscape | EventCallback | Callback executed when the user presses escape in the search box. | |
| OnFocus | EventCallback<FocusEventArgs> | Callback executed when the input of the search box gets focused. | |
| OnFocusIn | EventCallback<FocusEventArgs> | Callback executed when the input of the search box gets focused in. | |
| OnFocusOut | EventCallback<FocusEventArgs> | Callback executed when the input of the search box loses focus. | |
| OnKeyDown | EventCallback<KeyboardEventArgs> | Callback executed on each key down of the input of the search box. | |
| OnKeyUp | EventCallback<KeyboardEventArgs> | Callback executed on each key up of the input of the search box. | |
| OnSearch | EventCallback<string?> | Callback executed when the user presses enter in the search box, clicks the search button, or picks one of the suggest items. | |
| OnSuggestItemSelect | EventCallback<string> | Callback executed when the user selects one of the suggest items either by clicking on it or by pressing enter while it is highlighted. | |
| OnSuggestItemsToggle | EventCallback<bool> | Callback executed with true when the suggest items callout opens and with false when it closes. | |
| Placeholder | string? | null | Placeholder for the search box. |
| Prefix | string? | null | Prefix text displayed before the search box input. This is not included in the value. |
| PrefixTemplate | RenderFragment? | null | The custom template for the prefix of the search box. |
| SearchButtonAriaLabel | string | Search | The accessible label (aria-label) of the search button. |
| SearchButtonIcon | BitIconInfo? | null | Gets or sets the icon to display on the search button using custom CSS classes for external icon libraries. Takes precedence over SearchButtonIconName when both are set. |
| SearchButtonIconName | string? | ChromeBackMirrored | Gets or sets the name of the icon to display on the search button from the built-in Fluent UI icons. |
| SearchButtonTemplate | RenderFragment? | null | The custom template for search button icon. |
| SelectTextOnFocus | bool | false | Selects the text already in the search box whenever the input takes the focus, so that typing replaces the previous term instead of appending to it. It does nothing while the field is empty. |
| ShowSearchButton | bool | false | Whether to show the search button. |
| ShowSuggestItemsOnFocus | bool | false | Opens the suggest items callout as soon as the input gets focused, without waiting for the user to type. Combine it with a zero MinSuggestTriggerChars to implement default or recent search items. |
| Size | BitSize? | null | The size of the search box. |
| SpellCheck | bool? | null | Sets the spellcheck html attribute of the input element. Leaving it null keeps the default behavior of the browser, setting it to false removes the red squiggles from search terms that are not real words. |
| Styles | BitSearchBoxClassStyles? | null | Custom CSS styles for different parts of the search box. |
| Suffix | string? | null | Suffix text displayed after the search box input. This is not included in the value. |
| SuffixTemplate | RenderFragment? | null | The custom template for the suffix of the search box. |
| SuggestFilterFunction | Func<string?, string?, bool>? | null | Custom search function to be used in place of the default search algorithm. The first argument is the current search term and the second one is the suggest item to examine. |
| SuggestIgnoreDiacritics | bool | false | Matches the search term against the suggest items with the diacritics of both removed, so that "Jose" finds "José" and "Muller" finds "Müller". The item text itself is left untouched, and so is the part of it that HighlightSuggestItems emphasizes. Ignored when a SuggestFilterFunction is provided, but still applied to the highlight. |
| SuggestItems | IEnumerable<string>? | null | The list of suggest items to display in the callout. |
| SuggestItemsAriaLabel | string | Suggestions | The accessible label (aria-label) of the suggest items list. |
| SuggestItemsProvider | BitSearchBoxSuggestItemsProvider? | null | The item provider function providing suggest items. |
| SuggestItemTemplate | RenderFragment<string>? | null | The custom template for rendering the suggest items of the search box. |
| Trim | bool | false | Trims the leading and trailing white-spaces of the value of the search box. |
| Underlined | bool | false | Whether or not the search box is underlined. |
BitSearchBox public members
| Name | Type | Default value | Description |
|---|---|---|---|
| InputElement | ElementReference | The ElementReference to the input element of the BitSearchBox. | |
| FocusAsync | ValueTask | Gives focus to the input element of the BitSearchBox. | |
| IsSuggestItemsOpen | bool | false | Whether the callout of the suggest items is currently open. |
| Clear | Task | Clears the value of the BitSearchBox and invokes the OnClear callback. | |
| ShowSuggestItems | Task | Runs the suggest items search of the current value and opens the callout of the suggest items. | |
| HideSuggestItems | Task | Closes the callout of the suggest items. |
BitTextInputBase parameters
| Name | Type | Default value | Description |
|---|---|---|---|
| AutoComplete | string? | null | Specifies the value of the autocomplete attribute of the input component. |
| AutoFocus | bool | false | Determines if the text input is auto focused on first render. |
| DebounceTime | int | 0 | The debounce time in milliseconds. |
| Immediate | bool | false | Change the content of the input field when the user write text (based on 'oninput' HTML event). |
| ThrottleTime | int | 0 | The throttle time in milliseconds. |
BitInputBase parameters
| Name | Type | Default value | Description |
|---|---|---|---|
| DefaultValue | TValue? | null | The default value of the input to be used in uncontrolled mode (i.e. when the Value is not bound), typically used alongside the OnChange callback. |
| DisplayName | string? | null | Gets or sets the display name for this field. |
| InputHtmlAttributes | IReadOnlyDictionary<string, object>? | null | Gets or sets a collection of additional attributes that will be applied to the created element. |
| Name | string? | null | Gets or sets the name of the element. Allows access by name from the associated form. |
| NoValidate | bool | false | Disables the validation of the input. |
| OnChange | EventCallback<TValue?> | Callback for when the input value changes. | |
| ReadOnly | bool | false | Makes the input read-only. |
| Required | bool | false | Makes the input required. |
| Value | TValue? | null | Gets or sets the value of the input. This should be used with two-way binding. |
BitInputBase public members
| Name | Type | Default value | Description |
|---|---|---|---|
| InputElement | ElementReference | The ElementReference of the input element. | |
| FocusAsync() | () => ValueTask | Gives focus to the input element. | |
| FocusAsync(bool preventScroll) | (bool preventScroll) => ValueTask | Gives focus to the input element. |
BitComponentBase parameters
| Name | Type | Default value | Description |
|---|---|---|---|
| AriaLabel | string? | null | Gets or sets the accessible label for the component, used by assistive technologies. |
| Class | string? | null | Gets or sets the CSS class name(s) to apply to the rendered element. |
| Dir | BitDir? | null | Gets or sets the text directionality for the component's content. |
| ForceAnimation | bool | false | Gets or sets a value indicating whether the component's animations play at their full duration even when reduced motion is requested. |
| HtmlAttributes | Dictionary<string, object> | new Dictionary<string, object>() | Captures additional HTML attributes to be applied to the rendered element, in addition to the component's parameters. |
| Id | string? | null | Gets or sets the unique identifier for the component's root element. |
| IsEnabled | bool | true | Gets or sets a value indicating whether the component is enabled and can respond to user interaction. |
| Style | string? | null | Gets or sets the CSS style string to apply to the rendered element. |
| TabIndex | string? | null | Gets or sets the tab order index for the component when navigating with the keyboard. |
| Visibility | BitVisibility | BitVisibility.Visible | Gets or sets the visibility state (visible, hidden, or collapsed) of the component. |
BitComponentBase public members
| Name | Type | Default value | Description |
|---|---|---|---|
| UniqueId | Guid | Guid.NewGuid() | Gets the readonly unique identifier for the component's root element, assigned when the component instance is constructed. |
| RootElement | ElementReference | Gets the reference to the root HTML element associated with this component. |
BitSearchBoxClassStyles properties
| Name | Type | Default value | Description |
|---|---|---|---|
| Root | string? | null | Custom CSS classes/styles for the root element of the search box. |
| Focused | string? | null | Custom CSS classes/styles for the focus state of the search box. |
| Label | string? | null | Custom CSS classes/styles for the search box's label. |
| Wrapper | string? | null | Custom CSS classes/styles for the wrapper of the input container and the search button of the search box. |
| InputContainer | string? | null | Custom CSS classes/styles for the search box's input container. |
| IconWrapper | string? | null | Custom CSS classes/styles for the search box's icon wrapper. |
| Icon | string? | null | Custom CSS classes/styles for the search box's search icon. |
| PrefixContainer | string? | null | Custom CSS classes/styles for the search box's search prefix container. |
| Prefix | string? | null | Custom CSS classes/styles for the search box's search prefix. |
| Input | string? | null | Custom CSS classes/styles for the search box's Input. |
| SuffixContainer | string? | null | Custom CSS classes/styles for the search box's search suffix container. |
| Suffix | string? | null | Custom CSS classes/styles for the search box's search suffix. |
| ClearButton | string? | null | Custom CSS classes/styles for the search box's clear button. |
| ClearButtonIcon | string? | null | Custom CSS classes/styles for the search box's clear button icon. |
| SearchButton | string? | null | Custom CSS classes/styles for the search box's search button. |
| SearchButtonIcon | string? | null | Custom CSS classes/styles for the search box's search button icon. |
| Overlay | string? | null | Custom CSS classes/styles for the search box's overlay. |
| Callout | string? | null | Custom CSS classes/styles for the search box's callout. |
| CalloutHeader | string? | null | Custom CSS classes/styles for the header of the search box's callout. |
| CalloutFooter | string? | null | Custom CSS classes/styles for the footer of the search box's callout. |
| Loading | string? | null | Custom CSS classes/styles for the loading container of the search box's callout. |
| NoResults | string? | null | Custom CSS classes/styles for the no-results container of the search box's callout. |
| Hint | string? | null | Custom CSS classes/styles for the too-short-term hint of the search box's callout. |
| ScrollContainer | string? | null | Custom CSS classes/styles for the search box's scroll container. |
| SuggestItemWrapper | string? | null | Custom CSS classes/styles for the search box's suggest item wrapper. |
| SuggestItemButton | string? | null | Custom CSS classes/styles for the search box's suggest item button. |
| SuggestItemText | string? | null | Custom CSS classes/styles for the search box's suggest item text. |
| SuggestItemHighlight | string? | null | Custom CSS classes/styles for the highlighted part of the search box's suggest item text. |
BitSearchBoxSuggestItemsProviderRequest properties
The context passed to the SuggestItemsProvider delegate on every search.
| Name | Type | Default value | Description |
|---|---|---|---|
| SearchTerm | string? | null | The current value of the search box that the suggest items must be resolved for. |
| Take | int | 0 | The value of the MaxSuggestCount parameter, so the provider can only fetch as many items as will be rendered. |
| CancellationToken | CancellationToken | A token that is cancelled as soon as a newer search starts, so an outdated request can be aborted and can never overwrite a newer result. |
BitSearchBoxAnnouncementArgs properties
The state of the suggest items at the moment the screen reader announcement is built, passed to the AnnouncementProvider.
| Name | Type | Default value | Description |
|---|---|---|---|
| SearchTerm | string? | null | The current value of the search box that the suggest items were resolved for. |
| SuggestItems | IReadOnlyList<string> | [] | The suggest items that are about to be rendered in the callout. |
| IsLoading | bool | false | Whether an asynchronous SuggestItemsProvider is still resolving the suggest items. |
| IsSearchTermTooShort | bool | false | Whether the search term is still shorter than the MinSuggestTriggerChars, so no search was performed at all. |
| MinSuggestTriggerChars | int | 3 | The value of the MinSuggestTriggerChars parameter. |
BitIconInfo properties
| Name | Type | Default value | Description |
|---|---|---|---|
| Name | string? | null | Gets or sets the name of the icon. |
| BaseClass | string? | null | Gets or sets the base CSS class for the icon. For built-in Fluent UI icons, this defaults to "bit-icon". For external icon libraries like FontAwesome, you might set this to "fa" or leave empty. |
| Prefix | string? | null | Gets or sets the CSS class prefix used before the icon name. For built-in Fluent UI icons, this defaults to "bit-icon--". For external icon libraries, you might set this to "fa-" or leave empty. |
BitColorKind enum
| Name | Value | Description |
|---|---|---|
| Primary | 0 | The primary color kind. |
| Secondary | 1 | The secondary color kind. |
| Tertiary | 2 | The tertiary color kind. |
| Transparent | 3 | The transparent color kind. |
BitColor enum
| Name | Value | Description |
|---|---|---|
| Primary | 0 | Info Primary general color. |
| Secondary | 1 | Secondary general color. |
| Tertiary | 2 | Tertiary general color. |
| Info | 3 | Info general color. |
| Success | 4 | Success general color. |
| Warning | 5 | Warning general color. |
| SevereWarning | 6 | SevereWarning general color. |
| Error | 7 | Error general color. |
| PrimaryBackground | 8 | Primary background color. |
| SecondaryBackground | 9 | Secondary background color. |
| TertiaryBackground | 10 | Tertiary background color. |
| PrimaryForeground | 11 | Primary foreground color. |
| SecondaryForeground | 12 | Secondary foreground color. |
| TertiaryForeground | 13 | Tertiary foreground color. |
| PrimaryBorder | 14 | Primary border color. |
| SecondaryBorder | 15 | Secondary border color. |
| TertiaryBorder | 16 | Tertiary border color. |
BitSize enum
| Name | Value | Description |
|---|---|---|
| Small | 0 | The small size. |
| Medium | 1 | The medium size. |
| Large | 2 | The large size. |
BitEnterKeyHint enum
| Name | Value | Description |
|---|---|---|
| Enter | 0 | Typically inserting a new line. |
| Done | 1 | Typically meaning there is nothing more to input and the input method editor will be closed. |
| Go | 2 | Typically meaning to take the user to the target of the text they typed. |
| Next | 3 | Typically taking the user to the next field that will accept text. |
| Previous | 4 | Typically taking the user to the previous field that will accept text. |
| Search | 5 | Typically taking the user to the results of searching for the text they have typed. |
| Send | 6 | Typically delivering the text to its target. |
BitInputMode enum
| Name | Value | Description |
|---|---|---|
| None | 0 | The input expects text characters. |
| Text | 1 | Standard input keyboard for the user's current locale. |
| Decimal | 2 | Fractional numeric input keyboard containing the digits and decimal separator for the user's locale. |
| Numeric | 3 | Numeric input keyboard, but only requires the digits 0–9. |
| Tel | 4 | A telephone keypad input, including the digits 0–9, the asterisk (*), and the pound (#) key |
| Search | 5 | A virtual keyboard optimized for search input. |
| 6 | A virtual keyboard optimized for entering email addresses. | |
| Url | 7 | A keypad optimized for entering URLs. |
BitVisibility enum
| Name | Value | Description |
|---|---|---|
| Visible | 0 | The content of the component is visible. |
| Hidden | 1 | The content of the component is hidden, but the space it takes on the page remains (visibility:hidden). |
| Collapsed | 2 | The component is hidden (display:none). |
BitDir enum
| Name | Value | Description |
|---|---|---|
| Ltr | 0 | Ltr (left to right) is to be used for languages that are written from the left to the right (like English). |
| Rtl | 1 | Rtl (right to left) is to be used for languages that are written from the right to the left (like Arabic). |
| Auto | 2 | Auto lets the user agent decide. It uses a basic algorithm as it parses the characters inside the element until it finds a character with a strong directionality, then applies that directionality to the whole element. |
Feedback
Found a mistake, a gap, or something that could be clearer? Every page and every component is one click from its source.