<!--
  GENERATED FILE - do not edit by hand.
  Source of truth: src/components/mds-filter-item/ in the magma monorepo (usage/*.md and the
  component's JSDoc). Regenerated on every stencil build (scripts/component-docs.ts).
-->

# mds-filter-item

> `@maggioli-design-system/magma` 2.15.0. Shadow DOM: style it only through the public CSS custom properties and the parts below.

The `<mds-filter-item>` web component is a single selectable option inside the [`<mds-filter>`](../mds-filter/AGENTS.md) container of the Magma Design System. It renders as a toggle button (icon, label, and an optional count badge) and acts as the toggleable unit that drives the parent's filter selection - it has no standalone HTML primitive equivalent.

#### Semantic Behavior

- **Compound child only**: `<mds-filter-item>` must be a direct slot child of `<mds-filter>`; it is not used standalone and should not be mixed with other child types.
- **Self-toggling + event**: Clicking (or activating via the keyboard) flips `selected` and emits `mdsFilterItemSelect` with `{ id, selected }`. The `id` is the one set in the markup; an item without one gets `item-<index>` from the parent on load. The parent enforces single vs. multiple selection and re-emits `mdsFilterChange` with the aggregated value list.
- **State owned with the parent**: `selected` doubles as a styling hook and as the flag the parent reads/writes - in single-select mode the parent clears the other items' selection, and on reset it clears the whole group. The parent also follows a `selected` set by the application, without emitting `mdsFilterChange`.
- **Toggle button**: The host is a `button` whose `aria-pressed` follows `selected`. Its name is the `label` followed by the `count` as a number of results in the page language (the `lang` of `<html>`): "Nuove, 11 results" in English, "Nuove, 11 risultati" in Italian. The name contains the text the item shows, the label and the count as separate words, so a speech-input user can say what they see (WCAG 2.5.3, Label in Name). An `aria-label` written on the host by the author stays, as written: it must contain that text too, and follow the count when it changes.
- **Keyboard activation**: Enter (and numpad Enter) and Space activate the item like a pointer click.
- **Focus management**: The item is focusable unless `disabled`, in which case it drops out of the tab order.

#### Properties & Visual Configurations

- **`selected`**: The selection state of the item. Set it on initial markup to pre-select a filter, or at runtime from the application (a filter restored from the address, a clear button outside the bar): the parent follows, in single mode clearing the others.
- **`value`**: The form/data value contributed to the parent's aggregated `mdsFilterChange` payload when the item is selected. Provide a meaningful value distinct from the human-readable `label`.
- **`count`**: An optional badge showing how many results the filter would yield. Use it only when the count is meaningful to the user; omit it for purely categorical filters.
- **`icon`**: Optional leading icon (an icon name string). Without a `label` the item is named after the last segment of the slug (`map` for `mi/baseline/map`); give it an `aria-label` of your own when the slug does not say what the filter does.
- **`disabled`**: Blocks the item: it leaves the tab order, ignores clicks and keys, is announced as unavailable (`aria-disabled`) and is painted in the disabled text colour.

## Read next

- [`examples.md`](examples.md) - correct usage, from the most common case
- [`mistakes.md`](mistakes.md) - the wrong forms, each with the right one
- [Storybook](https://magma-design-system.github.io/magma/storybook/?path=/docs/ui-filter-filter-item--docs) - the live examples, in the published Storybook of `main`
- [`conventions.md`](../../../../agents/conventions.md), [`variants.md`](../../../../agents/variants.md), [`mistakes.md`](../../../../agents/mistakes.md) - the rules shared by every component

## Props

| Prop | Attribute | Type | Default | Description |
| --- | --- | --- | --- | --- |
| `count` | `count` | `string \| undefined` | - | Shows the number of items will be filtered by the component, also read out after the label as a number of results |
| `disabled` | `disabled` | `boolean \| undefined` | - | Sets if the component is disabled or not |
| `icon` | `icon` | `string \| undefined` | - | Sets the icon of the filter item |
| `label` | `label` | `string` | - | Sets the label of the filter item |
| `selected` | `selected` | `boolean \| undefined` | - | Sets the component to selected state |
| `value` | `value` | `string` | - | Sets the value of the component to be used with forms |

## Events

| Event | Detail | Description |
| --- | --- | --- |
| `mdsFilterItemSelect` | `MdsFilterItemEventDetail` | Emits when the element is active |

## CSS custom properties

None is public: its 4 custom properties are internal and may change in any release. Style it with its props, its parts and the semantic roles.

## Dependencies

Uses: `mds-icon`, `mds-text`.
Used by: `mds-filter`.
