Skip to content
GitHub11 stars

An input that suggests options as you type.

<AutocompleteRoot Items="Tags">
    <label class="autocomplete-label">
        Search tags

Usage guidelines

  • Avoid when selection state is needed: Use Combobox instead of Autocomplete if the selection should be remembered and the input can't hold custom text. Unlike Combobox, Autocomplete's input can contain free-form text, as its suggestions only optionally complete the text.
  • Form controls must have an accessible name: Give it one with a <label> element or the Field parts.
  • Closing animations: The popup stays rendered until its closing animation finishes. See Animation.

Anatomy

Import the primitives and assemble the parts:

@using Blazix.Primitives

<AutocompleteRoot>
    <AutocompleteInputGroup>
        <AutocompleteInput />
        <AutocompleteTrigger />
        <AutocompleteIcon />
        <AutocompleteClear />
        <AutocompleteValue />
    </AutocompleteInputGroup>

    <AutocompletePortal>
        <AutocompleteBackdrop />
        <AutocompletePositioner>
            <AutocompletePopup>
                <AutocompleteArrow />

                <AutocompleteStatus />
                <AutocompleteEmpty />

                <AutocompleteList>
                    <AutocompleteRow>
                        <AutocompleteItem />
                    </AutocompleteRow>

                    <AutocompleteSeparator />

                    <AutocompleteGroup>
                        <AutocompleteGroupLabel />
                    </AutocompleteGroup>

                    <AutocompleteCollection />
                </AutocompleteList>
            </AutocompletePopup>
        </AutocompletePositioner>
    </AutocompletePortal>
</AutocompleteRoot>

API Reference

AutocompleteRoot

Doesn't render its own HTML element.

ParameterTypeDefault
Mode AutocompleteMode AutocompleteMode.List
Items IEnumerable<string>? -
ItemToLabel Func<string, string>? -
Filter Func<string, string, bool>? -
Limit int? -
Value string? -
ValueChanged

Called with the new value when Value changes, for @bind-Value.

EventCallback<string?> -
Values IReadOnlyList<string>? -
ValuesChanged

Called with the new value when Values changes, for @bind-Values.

EventCallback<IReadOnlyList<string>?> -
OnValueChange

Runs before the value changes, with the reason; call Cancel() to keep it.

EventCallback<ValueChangeEventArgs<IReadOnlyList<string>>> -
InputValue string? -
InputValueChanged

Called with the new value when InputValue changes, for @bind-InputValue.

EventCallback<string> -
Multiple bool false
Disabled

Whether the component should ignore user interaction.

bool false
ReadOnly

Whether the user should be unable to change the value. It stays focusable.

bool false
Required

Whether the user must enter a value before submitting a form.

bool false
Name string? -
AutoHighlight bool false
HighlightItemOnHover

Whether moving the pointer over an item highlights it.

bool true
OpenOnInputClick bool? -
LoopFocus bool true
Modal bool false
Grid bool false
Open bool false
OpenChanged

Called with the new value when Open changes, for @bind-Open.

EventCallback<bool> -
OnOpenChange EventCallback<OpenChangeEventArgs> -
OnOpenChangeComplete EventCallback<bool> -
Handle PopupHandle? -
ContentTemplate RenderFragment<object?>? -
ChildContent

The part's content.

RenderFragment? -

AutocompleteTrigger

Renders a <button> element.

ParameterTypeDefault
Disabled

Whether the component should ignore user interaction.

bool false
NativeButton bool? -
Render RenderFragment<ComboboxRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

AttributeType
data-popup-open

Present when the corresponding popup is open.

-
data-list-empty

Present when the corresponding items list is empty.

-
data-pressed

Present when the trigger is pressed.

-
data-disabled

Present when the component is disabled.

-
data-readonly

Present when the component is readonly.

-
data-required

Present when the component is required.

-
data-valid

Present when the component is in a valid state (when wrapped in FieldRoot).

-
data-invalid

Present when the component is in an invalid state (when wrapped in FieldRoot).

-
data-dirty

Present when the component's value has changed (when wrapped in FieldRoot).

-
data-touched

Present when the component has been touched (when wrapped in FieldRoot).

-
data-filled

Present when the component has a value (when wrapped in FieldRoot).

-
data-focused

Present when the trigger is focused (when wrapped in FieldRoot).

-

AutocompleteValue

Renders a <span> element.

ParameterTypeDefault
Placeholder string? -
Template RenderFragment<IReadOnlyList<string>>? -
Render RenderFragment<ComboboxRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

AutocompleteInput

Renders a <input> element.

ParameterTypeDefault
Placeholder string? -
Disabled

Whether the component should ignore user interaction.

bool false
Render RenderFragment<ComboboxRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

AttributeType
data-popup-open

Present when the corresponding popup is open.

-
data-list-empty

Present when the corresponding items list is empty.

-
data-pressed

Present when the input is pressed.

-
data-disabled

Present when the component is disabled.

-
data-readonly

Present when the component is readonly.

-
data-required

Present when the component is required.

-
data-valid

Present when the component is in a valid state (when wrapped in FieldRoot).

-
data-invalid

Present when the component is in an invalid state (when wrapped in FieldRoot).

-
data-dirty

Present when the component's value has changed (when wrapped in FieldRoot).

-
data-touched

Present when the component has been touched (when wrapped in FieldRoot).

-
data-filled

Present when the component has a value (when wrapped in FieldRoot).

-
data-focused

Present when the input is focused (when wrapped in FieldRoot).

-

AutocompleteIcon

Renders a <span> element.

ParameterTypeDefault
Render RenderFragment<ComboboxRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

AutocompleteClear

Renders a <button> element.

ParameterTypeDefault
Disabled

Whether the component should ignore user interaction.

bool false
NativeButton bool? -
Render RenderFragment<ComboboxRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

AttributeType
data-popup-open

Present when the corresponding popup is open.

-
data-disabled

Present when the button is disabled.

-
data-visible

Present when the clear button is visible.

-
data-starting-style

Present when the button begins animating in.

-
data-ending-style

Present when the button is animating out.

-

AutocompleteList

Renders a <div> element.

ParameterTypeDefault
Template RenderFragment<string>? -
Render RenderFragment<ComboboxRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

AutocompletePortal

Doesn't render its own HTML element.

ParameterTypeDefault
KeepMounted bool false
ChildContent

The part's content.

RenderFragment? -

AutocompleteBackdrop

Renders a <div> element.

ParameterTypeDefault
Render RenderFragment<PopupRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

AttributeType
data-open

Present when the popup is open.

-
data-closed

Present when the popup is closed.

-
data-starting-style

Present when the popup begins animating in.

-
data-ending-style

Present when the popup is animating out.

-

AutocompletePositioner

Doesn't render its own HTML element.

ParameterTypeDefault
Side Side? -
Align Align? -
SideOffset int? -
AlignOffset int? -
CollisionPadding int? -
ArrowPadding int? -
Sticky bool? -
Anchor string? -
ChildContent

The part's content.

RenderFragment? -
AttributeType
data-open

Present when the popup is open.

-
data-closed

Present when the popup is closed.

-
data-anchor-hidden

Present when the anchor is hidden.

-
data-align

Indicates how the popup is aligned relative to specified side.

'start' | 'center' | 'end'
data-empty

Present when the items list is empty.

-
data-side

Indicates which side the popup is positioned relative to the trigger.

'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start'
CSS variableType
--anchor-height

The anchor's height.

number
--anchor-width

The anchor's width.

number
--available-height

The available height between the trigger and the edge of the viewport.

number
--available-width

The available width between the trigger and the edge of the viewport.

number
--transform-origin

The coordinates that this element is anchored to. Used for animations and transitions.

string

AutocompletePopup

Renders a <div> element.

ParameterTypeDefault
Side Side? -
Align Align? -
SideOffset int? -
AlignOffset int? -
CollisionPadding int? -
ArrowPadding int 5
Sticky bool false
Anchor string? -
FallbackAxis bool? -
KeepMounted bool false
InitialFocus string? -
FinalFocus string? -
PositionerAttributes IReadOnlyDictionary<string, object>? -
Render RenderFragment<ComboboxRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

AttributeType
data-open

Present when the popup is open.

-
data-closed

Present when the popup is closed.

-
data-anchor-hidden

Present when the anchor is hidden.

-
data-align

Indicates how the popup is aligned relative to specified side.

'start' | 'center' | 'end'
data-empty

Present when the items list is empty.

-
data-side

Indicates which side the popup is positioned relative to the trigger.

'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start'
data-starting-style

Present when the popup begins animating in.

-
data-ending-style

Present when the popup is animating out.

-

AutocompleteArrow

Renders a <div> element.

ParameterTypeDefault
Render RenderFragment<PopupRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

AttributeType
data-open

Present when the popup is open.

-
data-closed

Present when the popup is closed.

-
data-uncentered

Present when the arrow is uncentered.

-
data-align

Indicates how the popup is aligned relative to specified side.

'start' | 'center' | 'end'
data-side

Indicates which side the popup is positioned relative to the trigger.

'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start'

AutocompleteItem

Renders a <div> element.

ParameterTypeDefault
Valuerequired string -
Label string? -
Disabled

Whether the component should ignore user interaction.

bool false
Render RenderFragment<ComboboxItemRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

AttributeType
data-highlighted

Present when the item is highlighted.

-
data-disabled

Present when the item is disabled.

-

AutocompleteGroup

Renders a <div> element.

ParameterTypeDefault
Items IEnumerable<string>? -
Render RenderFragment<PartRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

AutocompleteGroupLabel

Renders a <div> element.

ParameterTypeDefault
Render RenderFragment<PartRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

AutocompleteSeparator

Renders a <div> element.

ParameterTypeDefault
Render RenderFragment<PartRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

AttributeType
data-orientation

Indicates the orientation of the separator.

'horizontal' | 'vertical'

AutocompleteStatus

Renders a <div> element.

ParameterTypeDefault
Render RenderFragment<ComboboxRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

AutocompleteEmpty

Renders a <div> element.

ParameterTypeDefault
Render RenderFragment<ComboboxRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

AutocompleteCollection

Doesn't render its own HTML element.

ParameterTypeDefault
ChildContentrequired

The part's content.

RenderFragment<string> -

AutocompleteRow

Renders a <div> element.

ParameterTypeDefault
Render RenderFragment<PartRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

AutocompleteInputGroup

Renders a <div> element.

ParameterTypeDefault
Render RenderFragment<ComboboxRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

AttributeType
data-popup-open

Present when the corresponding popup is open.

-
data-list-empty

Present when the corresponding items list is empty.

-
data-pressed

Present when the input group is pressed.

-
data-disabled

Present when the component is disabled.

-
data-readonly

Present when the component is readonly.

-
data-valid

Present when the component is in a valid state (when wrapped in FieldRoot).

-
data-invalid

Present when the component is in an invalid state (when wrapped in FieldRoot).

-
data-dirty

Present when the component's value has changed (when wrapped in FieldRoot).

-
data-touched

Present when the component has been touched (when wrapped in FieldRoot).

-
data-filled

Present when the component has a value (when wrapped in FieldRoot).

-
data-focused

Present when the component is focused (when wrapped in FieldRoot).

-