# Blazor Chip and Chip List

URL: https://flexcoreui.com/demo/chips  
Section: Components  
Controls: ChipListControl, ChipControl, ChipItem  
Keywords: chip, chip list, filter chips, tags, pills

Blazor chips for filters, tags and quick choices: ChipListControl tracks which are picked and removed; ChipControl toggles, acts or dismisses.

## Documentation

### List

| Name | Type | Default | Description |
|---|---|---|---|
| Items | IReadOnlyList<ChipItem> | empty | The chips, in order. Two-way with @bind-Items: a removed chip leaves the list. |
| SelectedIds | IReadOnlyList<string> | empty | Ids of the picked chips. Two-way with @bind-SelectedIds. |
| Selection | ChoiceSelectionMode | Multiple | Multiple toggles each chip; Single keeps one at most, and picking it again leaves none. |
| Removable | bool | true | Shows a × on every chip. |
| AriaLabel | string | "Chips" | Accessible name of the group. |
| Enabled (base) | bool | true | False disables every chip. |
| Visible (base) | bool | true | False hides the list with display:none. |
| CssClass / Style (base) | string? | null | On the list element. |
| Id / Title / Tag / Data / Parent (base) |  | null | Accepted but not rendered. |
| (unmatched attributes) | Dictionary<string,object> |  | Accepted but not rendered: an id or aria-* given here is dropped. |

### Chip

| Name | Type | Default | Description |
|---|---|---|---|
| Text | string | "" | Label, and the name used by the × button. |
| ChildContent | RenderFragment? | null | Label markup; replaces Text in the label only. |
| IconCss | string? | null | Classes for an icon before the label, such as bi bi-tag. |
| Selected | bool | false | Picked state. Two-way with @bind-Selected. |
| Selectable | bool | true | False makes the label a plain action: no toggle, no aria-pressed. |
| Removable | bool | false | Shows the ×. |
| Enabled (base) | bool | true | False disables the label and the ×. |
| Visible (base) | bool | true | False renders nothing. |
| CssClass / Style (base) | string? | null | On the chip element. |
| Id / Title / Tag / Data / Parent (base) |  | null | Accepted but not rendered. |
| (unmatched attributes) | Dictionary<string,object> |  | Accepted but not rendered: an id or aria-* given here is dropped. |

### Events

| Name | Type | Description |
|---|---|---|
| ChipListControl.ItemsChanged | IReadOnlyList<ChipItem> | After a chip is removed, by its × or RemoveAsync, with the remaining items. |
| ChipListControl.SelectedIdsChanged | IReadOnlyList<string> | On each pick and unpick, and when a picked chip is removed. |
| ChipControl.SelectedChanged | bool | After each toggle, with the new state. |
| ChipControl.OnClick | none | The label was clicked, after any toggle. No payload. |
| ChipControl.OnRemove | none | The × was clicked. The chip does not remove itself; the page does. |

### Item

| Name | Type | Default | Description |
|---|---|---|---|
| Id | string |  | Key reported in SelectedIds. Unique within the list. |
| Text | string |  | The chip's label. |
| Disabled | bool | false | Grayed; cannot be picked or removed. |
| IconCss | string? | null | Classes for an icon before the label. |
| ctor |  |  | new(id, text, disabled, iconCss); a positional record, so name the later arguments, as in IconCss: "bi bi-bug". |

### Methods

| Name | Type | Description |
|---|---|---|
| ChipListControl.RemoveAsync(string id) | Task | Removes a chip from code, as the × does. Needs @bind-Items or an ItemsChanged handler that stores the new list; without one the page's old list is drawn again. Ignored for an unknown or disabled chip, or when the list is disabled. |

### Css

| Name | Description |
|---|---|
| fx-chip-list | The list. Its wrapping flex row and 6px gap are an inline style, not a stylesheet rule, so change them through Style. |
| fx-chip · .selected | One pill: rounded border and gray fill; selected turns it blue. |
| fx-chip-label | The label button inside the pill. |
| fx-chip-remove | The × button inside the pill. |

## Examples

### Filter

```razor
@using Fx.ControlKit

<div class="ch">
    <ChipListControl Items="_labels" @bind-SelectedIds="_picked" Selection="ChoiceSelectionMode.Multiple" Removable="false" AriaLabel="Task label" />
    <ul class="tasks">
        @foreach (var task in Shown)
        {
            <li><span class="task-icon @_labels.First(l => l.Id == task.Label).IconCss" aria-hidden="true"></span><span class="task-name">@task.Name</span><span class="task-label">@task.Label</span></li>
        }
    </ul>
    <span class="result" role="status">@(_picked.Count == 0 ? $"Showing all {_tasks.Length} tasks" : $"Showing {Shown.Length} of {_tasks.Length} tasks: {string.Join(", ", _picked)}")</span>
</div>
```

```csharp
// Filter
private readonly ChipItem[] _labels =
{
    new("Design", "Design", IconCss: "bi bi-palette"),
    new("Frontend", "Frontend", IconCss: "bi bi-code-slash"),
    new("Content", "Content", IconCss: "bi bi-file-text"),
    new("QA", "QA", Disabled: true, IconCss: "bi bi-bug"),
};
private IReadOnlyList<string> _picked = new[] { "Frontend" };
private sealed record TaskItem(string Name, string Label);
private readonly TaskItem[] _tasks =
{
    new("WEB-101 Style guide", "Design"), new("WEB-102 Logo refresh", "Design"), new("WEB-113 Site footer", "Frontend"),
    new("WEB-117 Order form", "Frontend"), new("WEB-121 Menu copy", "Content"), new("WEB-122 About page", "Content"),
};
private TaskItem[] Shown => _tasks.Where(t => _picked.Count == 0 || _picked.Contains(t.Label)).ToArray();
```

### Tags

```razor
@using Fx.ControlKit

<div class="ch">
    <div class="lbl"><span class="bi bi-card-checklist" aria-hidden="true"></span>WEB-117 Order form: review notes from Hermione Ranger</div>
    <ChipListControl @ref="_list" @bind-Items="_notes" @bind-SelectedIds="_fixed" AriaLabel="Review notes" />
    <form class="demo-row mt" @onsubmit="AddNote">
        <TextBoxControl @bind-Value="_new" UpdateOnInput="true" Placeholder="Add a note" Width="200px" aria-label="New note" />
        <ButtonControl ButtonType="submit" CssClass="btn-primary btn-sm" Disabled="@string.IsNullOrWhiteSpace(_new)">Add</ButtonControl>
        <ButtonControl CssClass="btn-sm" Disabled="@(_fixed.Count == 0)" OnClick="RemoveFixedAsync">Remove fixed</ButtonControl>
        <ButtonControl CssClass="btn-sm" OnClick="ResetNotes">Reset</ButtonControl>
    </form>
    <span class="result" role="status">Review notes: @_notes.Count, fixed by the developer: @_fixed.Count</span>
</div>
```

```csharp
// Tags
private static readonly ChipItem[] Seed =
{
    new("contrast", "Button contrast"), new("alt", "Missing alt text"), new("mobile", "Cramped on mobile"), new("error", "Vague error text"),
};
private ChipListControl? _list;
private IReadOnlyList<ChipItem> _notes = Seed;
private IReadOnlyList<string> _fixed = new[] { "alt" };
private string? _new;
private int _next;
private void AddNote()
{
    if (string.IsNullOrWhiteSpace(_new)) return;
    _notes = _notes.Append(new ChipItem($"new{_next++}", _new.Trim())).ToList();
    _new = null;
}
private async Task RemoveFixedAsync()
{
    foreach (var id in _fixed.ToArray()) await _list!.RemoveAsync(id);
}
private void ResetNotes()
{
    _notes = Seed;
    _fixed = new[] { "alt" };
}
```

### Chip

```razor
@using Fx.ControlKit

<div class="ch">
    <div class="demo-row">
        <ChipControl Text="Rush delivery" IconCss="bi bi-lightning-charge" @bind-Selected="_rush" />
        <ChipControl IconCss="bi bi-file-earmark-plus" Selectable="false" OnClick="@(() => _pages++)">Add a page · <strong>@_pages</strong></ChipControl>
        @if (_discount)
        {
            <ChipControl Text="Repeat client discount" IconCss="bi bi-tag" Selectable="false" Removable="true" OnRemove="@(() => _discount = false)" />
        }
        else
        {
            <ChipControl Text="Apply discount" IconCss="bi bi-plus-lg" Selectable="false" OnClick="@(() => _discount = true)" />
        }
        <ChipControl Text="Sprint 8: full" Enabled="false" />
    </div>
    <span class="result" role="status">Change request for Green Fork Cafe: @_pages extra pages@(_rush ? ", rush delivery" : "")@(_discount ? ", 10% off" : "") = @Estimate.ToString("C0")</span>
</div>
```

```csharp
// Single chips
private bool _rush = true, _discount = true;
private int _pages = 2;
private decimal Estimate => _pages * (400 + (_rush ? 50 : 0)) * (_discount ? 0.9m : 1m);
```

