Skip to content
GitHub11 stars

Autocomplete input with a list of suggestions.

<Combobox Items="@Frameworks">
    <ComboboxInput Placeholder="Select a framework" />
    <ComboboxContent>

Installation

dnx Blazix.Cli add combobox

Usage

<Combobox Items="Frameworks">
    <ComboboxInput Placeholder="Select a framework" />
    <ComboboxContent>
        <ComboboxEmpty>No items found.</ComboboxEmpty>
        <ComboboxList>
            <Template Context="item">
                <ComboboxItem Value="@item">@item</ComboboxItem>
            </Template>
        </ComboboxList>
    </ComboboxContent>
</Combobox>

@code {
    private static readonly string[] Frameworks = ["Next.js", "SvelteKit", "Nuxt.js", "Remix", "Astro"];
}

Composition

Simple

A single-line input and a flat list (see Basic).

Combobox
├── ComboboxInput
└── ComboboxContent
    ├── ComboboxEmpty
    └── ComboboxList
        ├── ComboboxItem
        └── ComboboxItem

With chips

Multi-select with Multiple, chips, and a chips input (see Multiple).

Combobox
├── ComboboxChips
│   ├── ComboboxValue
│   │   └── ComboboxChip
│   └── ComboboxChipsInput
└── ComboboxContent
    ├── ComboboxEmpty
    └── ComboboxList
        ├── ComboboxItem
        └── ComboboxItem

With groups and collection

Nested items per group using ComboboxCollection inside each ComboboxGroup, with a separator between groups (see Groups).

Combobox
├── ComboboxInput
└── ComboboxContent
    ├── ComboboxEmpty
    └── ComboboxList
        ├── ComboboxGroup
        │   ├── ComboboxLabel
        │   └── ComboboxCollection
        │       ├── ComboboxItem
        │       └── ComboboxItem
        ├── ComboboxSeparator
        └── ComboboxGroup
            ├── ComboboxLabel
            └── ComboboxCollection
                ├── ComboboxItem
                └── ComboboxItem

Custom Items

Items are string values. When your items are objects, use their values as the items and ItemToLabel to name them.

<Combobox Items="@Frameworks.Select(f => f.Value)" ItemToLabel="LabelOf">
    <ComboboxInput Placeholder="Select a framework" />
    <ComboboxContent>
        <ComboboxEmpty>No items found.</ComboboxEmpty>
        <ComboboxList>
            <Template Context="value">
                <ComboboxItem Value="@value">@LabelOf(value)</ComboboxItem>
            </Template>
        </ComboboxList>
    </ComboboxContent>
</Combobox>

@code {
    private sealed record Framework(string Label, string Value);

    private static readonly Framework[] Frameworks =
    [
        new("Next.js", "next"),
        new("SvelteKit", "sveltekit"),
        new("Nuxt", "nuxt"),
    ];

    private static string LabelOf(string value) => Frameworks.First(f => f.Value == value).Label;
}

Multiple Selection

Use Multiple with chips for multi-select behavior.

<Combobox Items="Frameworks" Multiple="true" @bind-Values="_values">
    <ComboboxChips id="frameworks-chips">
        <Template Context="item">
            <ComboboxChip Value="@item">@item</ComboboxChip>
        </Template>
        <ChildContent>
            <ComboboxChipsInput Placeholder="Add framework" />
        </ChildContent>
    </ComboboxChips>
    <ComboboxContent Anchor="frameworks-chips">
        <ComboboxEmpty>No items found.</ComboboxEmpty>
        <ComboboxList>
            <Template Context="item">
                <ComboboxItem Value="@item">@item</ComboboxItem>
            </Template>
        </ComboboxList>
    </ComboboxContent>
</Combobox>

@code {
    private static readonly string[] Frameworks = ["Next.js", "SvelteKit", "Nuxt.js", "Remix", "Astro"];

    private IReadOnlyList<string> _values = [];
}

Basic

A simple combobox with a list of frameworks.

<Combobox Items="@Frameworks">
    <ComboboxInput Placeholder="Select a framework" />
    <ComboboxContent>

Multiple

A combobox with multiple selection using Multiple and ComboboxChips.

Next.js
<Combobox Multiple="true" AutoHighlight="true" Items="Frameworks" @bind-Values="_values">
    <ComboboxChips id="combobox-multiple-chips" Class="w-full max-w-xs">
        <Template Context="value">

Clear Button

Use the ShowClear parameter to show a clear button.

<Combobox Items="Frameworks" Value="@Frameworks[0]">
    <ComboboxInput Placeholder="Select a framework" ShowClear="true" />
    <ComboboxContent>

Groups

Use ComboboxGroup and ComboboxSeparator to group items.

<Combobox Items="AllTimezones">
    <ComboboxInput Placeholder="Select a timezone" />
    <ComboboxContent>

Custom Items

You can render a custom component inside ComboboxItem.

<Combobox Items="Countries.Values" ItemToLabel="Countries.LabelOf">
    <ComboboxInput Placeholder="Search countries..." />
    <ComboboxContent>

Invalid

Use the aria-invalid parameter to make the combobox invalid.

<Combobox Items="@Frameworks">
    <ComboboxInput Placeholder="Select a framework" aria-invalid="true" />
    <ComboboxContent>

Disabled

Use the Disabled parameter to disable the combobox.

<Combobox Items="@Frameworks">
    <ComboboxInput Placeholder="Select a framework" Disabled="true" />
    <ComboboxContent>

Auto Highlight

Use the AutoHighlight parameter to automatically highlight the first item on filter.

<Combobox Items="@Frameworks" AutoHighlight="true">
    <ComboboxInput Placeholder="Select a framework" />
    <ComboboxContent>

You can trigger the combobox from a button or any other component by using the Render parameter. Move the ComboboxInput inside the ComboboxContent.

<Combobox Items="Countries.Values" ItemToLabel="Countries.LabelOf">
    <ComboboxTrigger Class="@ButtonVariants.Get(ButtonVariant.Outline, ButtonSize.Default, "w-64 justify-between font-normal")">
        <ComboboxValue Placeholder="Select country" />

Input Group

You can add an addon to the combobox by using the InputGroupAddon component inside the ComboboxInput.

<Combobox Items="AllTimezones">
    <ComboboxInput Placeholder="Select a timezone">
        <InputGroupAddon>

RTL

To enable RTL support in Blazix, see the RTL configuration guide.

Translated with AI for the demo, so it may have mistakes.

التكنولوجيا
<Field Class="mx-auto w-full max-w-xs">
    <FieldLabel for="combobox-rtl-input">@T.Label</FieldLabel>
    <Combobox Multiple="true" AutoHighlight="true" Items="@T.Categories" @bind-Values="_values">

API Reference

Combobox

ParameterTypeDefault
Multiple bool false
OpenChanged EventCallback<bool> -
Open bool false
Grid bool false
Modal bool false
OpenOnInputClick bool? -
AutoHighlight bool false
Name string? -
Required bool false
ReadOnly bool false
Disabled bool false
OnOpenChange EventCallback<OpenChangeEventArgs> -
OnOpenChangeComplete EventCallback<bool> -
InputValue string? -
OnValueChange EventCallback<ValueChangeEventArgs<IReadOnlyList<string>>> -
ValuesChanged EventCallback<IReadOnlyList<string>?> -
Values IReadOnlyList<string>? -
ValueChanged EventCallback<string?> -
Value string? -
Limit int? -
Filter Func<string, string, bool>? -
ItemToLabel Func<string, string>? -
Items IEnumerable<string>? -
InputValueChanged EventCallback<string> -
ChildContent RenderFragment? -

ComboboxChip

ParameterTypeDefault
Value string? -
ShowRemove bool true
Class string? -
ChildContent RenderFragment? -

Other attributes are passed to the element it renders.

ComboboxChips

ParameterTypeDefault
Template RenderFragment<string>? -
Class string? -
ChildContent RenderFragment? -

Other attributes are passed to the element it renders.

ComboboxChipsInput

ParameterTypeDefault
Placeholder string? -
Class string? -

Other attributes are passed to the element it renders.

ComboboxClear

ParameterTypeDefault
Class string? -

Other attributes are passed to the element it renders.

ComboboxCollection

ParameterTypeDefault
ChildContentrequired RenderFragment<string> -

ComboboxContent

ParameterTypeDefault
Render RenderFragment<ComboboxRenderProps>? -
Side Side Side.Bottom
SideOffset int 6
Align Align Align.Start
AlignOffset int 0
Anchor string? -
Class string? -
ChildContent RenderFragment? -

Other attributes are passed to the element it renders.

ComboboxEmpty

ParameterTypeDefault
Class string? -
ChildContent RenderFragment? -

Other attributes are passed to the element it renders.

ComboboxGroup

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

Other attributes are passed to the element it renders.

ComboboxInput

ParameterTypeDefault
Placeholder string? -
Disabled bool false
ShowTrigger bool true
ShowClear bool false
Class string? -
ChildContent RenderFragment? -

Other attributes are passed to the element it renders.

ComboboxItem

ParameterTypeDefault
Render RenderFragment<ComboboxItemRenderProps>? -
Valuerequired string -
Label string? -
Disabled bool false
Class string? -
ChildContent RenderFragment? -

Other attributes are passed to the element it renders.

ComboboxLabel

ParameterTypeDefault
Class string? -
ChildContent RenderFragment? -

Other attributes are passed to the element it renders.

ComboboxList

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

Other attributes are passed to the element it renders.

ComboboxSeparator

ParameterTypeDefault
Class string? -

Other attributes are passed to the element it renders.

ComboboxTrigger

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

Other attributes are passed to the element it renders.

ComboboxValue

ParameterTypeDefault
Placeholder string? -
Template RenderFragment<IReadOnlyList<string>>? -

Other attributes are passed to the element it renders.