Skip to content
GitHub11 stars

An input combined with a list of predefined items to select.

<ComboboxRoot Items="Fruits.Keys" ItemToLabel="@(value => Fruits[value])">
    <div class="combobox-label">
        <label for="@_id">Choose a fruit</label>

Usage guidelines

  • Combobox is a filterable Select: Use Combobox when the input is restricted to a set of predefined items, like Select, but whose items can be filtered by typing. Prefer it over Select when there are enough items to warrant filtering.
  • Avoid for simple search widgets: Combobox doesn't allow free-form text. For search widgets, consider Autocomplete.
  • Avoid when not rendering an input: Use Select instead if no input is rendered: it includes accessibility features specific to a listbox without an input.
  • Form controls must have an accessible name: If ComboboxInput is the form control, label it with a native <label> or FieldLabel, or give it an aria-label when no visible label is rendered. ComboboxLabel labels ComboboxTrigger, for the pattern where the input is inside the popup and the trigger is the form control.
  • Closing animations: The popup stays rendered until its closing animation finishes. See Animation.

Anatomy

Import the primitives and assemble the parts:

@using Blazix.Primitives

<ComboboxRoot>
    <ComboboxLabel />

    <ComboboxInputGroup>
        <ComboboxInput />
        <ComboboxTrigger />
        <ComboboxIcon />
        <ComboboxClear />
        <ComboboxValue />

        <ComboboxChips>
            <ComboboxChip>
                <ComboboxChipRemove />
            </ComboboxChip>
        </ComboboxChips>
    </ComboboxInputGroup>

    <ComboboxPortal>
        <ComboboxBackdrop />
        <ComboboxPositioner>
            <ComboboxPopup>
                <ComboboxArrow />

                <ComboboxStatus />
                <ComboboxEmpty />

                <ComboboxList>
                    <ComboboxRow>
                        <ComboboxItem>
                            <ComboboxItemIndicator />
                        </ComboboxItem>
                    </ComboboxRow>

                    <ComboboxSeparator />

                    <ComboboxGroup>
                        <ComboboxGroupLabel />
                    </ComboboxGroup>

                    <ComboboxCollection />
                </ComboboxList>
            </ComboboxPopup>
        </ComboboxPositioner>
    </ComboboxPortal>
</ComboboxRoot>

API Reference

ComboboxRoot

Doesn't render its own HTML element.

ParameterTypeDefault
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? -

ComboboxTrigger

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).

-
data-placeholder

Present when the combobox doesn't have a value.

-

ComboboxValue

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.

ComboboxInput

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).

-

ComboboxIcon

Renders a <span> element.

ParameterTypeDefault
Render RenderFragment<ComboboxRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

ComboboxClear

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.

-

ComboboxList

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.

ComboboxPortal

Doesn't render its own HTML element.

ParameterTypeDefault
KeepMounted bool false
ChildContent

The part's content.

RenderFragment? -

ComboboxBackdrop

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.

-

ComboboxPositioner

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

ComboboxPopup

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.

-

ComboboxArrow

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'

ComboboxItem

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-selected

Present when the item is selected.

-
data-highlighted

Present when the item is highlighted.

-
data-disabled

Present when the item is disabled.

-

ComboboxGroup

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.

ComboboxGroupLabel

Renders a <div> element.

ParameterTypeDefault
Render RenderFragment<PartRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

ComboboxSeparator

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'

ComboboxLabel

Renders a <label> element.

ParameterTypeDefault
Render RenderFragment<ComboboxRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

ComboboxStatus

Renders a <div> element.

ParameterTypeDefault
Render RenderFragment<ComboboxRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

ComboboxEmpty

Renders a <div> element.

ParameterTypeDefault
Render RenderFragment<ComboboxRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

ComboboxCollection

Doesn't render its own HTML element.

ParameterTypeDefault
ChildContentrequired

The part's content.

RenderFragment<string> -

ComboboxRow

Renders a <div> element.

ParameterTypeDefault
Render RenderFragment<PartRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

ComboboxChips

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.

ComboboxChip

Renders a <div> element.

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

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

ComboboxChipRemove

Renders a <button> element.

ParameterTypeDefault
Value string? -
NativeButton bool? -
Render RenderFragment<ComboboxRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

ComboboxItemIndicator

Renders a <span> element.

ParameterTypeDefault
KeepMounted bool false
Render RenderFragment<PartRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

AttributeType
data-starting-style

Present when the indicator begins animating in.

-
data-ending-style

Present when the indicator is animating out.

-

ComboboxInputGroup

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).

-
data-placeholder

Present when the combobox doesn't have a value.

-