<!--
  GENERATED FILE - do not edit by hand.
  Source of truth: src/components/mds-paginator-item/usage/ in the magma monorepo.
-->

# mds-paginator-item - examples

> The API of this component: [`AGENTS.md`](AGENTS.md).

Correct and idiomatic ways to use the `<mds-paginator-item>` component, ordered from most common to most specialized. The examples assume a working knowledge of the shared component rules in [`agents/conventions.md`](../../../../agents/conventions.md).

> **Note:** `<mds-paginator-item>` is an internal sub-part of [`mds-paginator`](../mds-paginator/AGENTS.md). The idiomatic way to display page navigation is to use `<mds-paginator>` directly - it renders and manages all items automatically. The patterns below document the component's surface to show how the parent assembles it.

#### Using mds-paginator (the normal case)

Render a paginator by setting `pages` and `current-page` on the parent. The parent creates one `<mds-paginator-item>` per page number plus the back and forward arrow items; you never instantiate them yourself.

```html
<mds-paginator pages="12" current-page="1"></mds-paginator>
```

#### Listening for Page Changes

The page-change event is emitted by the parent `<mds-paginator>` as `mdsPaginatorChange`. Do not listen for click events on individual items.

```html
<mds-paginator id="paginatore" pages="20" current-page="1"></mds-paginator>

<script>
  document.querySelector('#paginatore').addEventListener('mdsPaginatorChange', (e) => {
    console.log('Pagina selezionata:', e.detail.page);
  });
</script>
```

#### Numbered Page Item (text slot)

When `icon` is not set, the item renders the default slot content as the page number label. The slot expects a plain text string - no HTML elements or components.

```html
<!-- Rendered internally by mds-paginator; shown here for reference only -->
<mds-paginator-item>7</mds-paginator-item>
```

#### Icon-Based Navigation Item

When `icon` is set, the item renders an icon instead of the text slot and is used for the back and forward arrow controls. The parent passes its own back and forward arrow icons, bundled in the component, and names each arrow with an `aria-label`: an icon alone gives the item no accessible name.

```html
<!-- Rendered internally by mds-paginator; shown here for reference only -->
<mds-paginator-item icon="mi/baseline/arrow-back" aria-label="Pagina precedente" disabled></mds-paginator-item>
<mds-paginator-item icon="mi/baseline/arrow-forward" aria-label="Pagina successiva"></mds-paginator-item>
```

#### Selected and Disabled States

`selected` marks the current page and makes the item inert. `disabled` marks a navigation arrow as unavailable (e.g. back arrow on page 1) and also blocks activation. Both are boolean attributes that the parent manages.

```html
<!-- Current page - selected, inert -->
<mds-paginator-item selected>3</mds-paginator-item>

<!-- Back arrow on page 1 - disabled, inert -->
<mds-paginator-item icon="mi/baseline/arrow-back" aria-label="Pagina precedente" disabled></mds-paginator-item>
```

#### CSS Customization

The items live in the shadow DOM of the parent `mds-paginator`, so the public `--mds-paginator-item-*` CSS custom properties reach them by inheritance: set them on the `mds-paginator` host or on a containing selector, next to the parent's own `--mds-paginator-background` and `--mds-paginator-scroll-behavior`. Use the semantic color roles so dark mode keeps working.

```css
mds-paginator {
  --mds-paginator-background: rgb(var(--magma-wash-strong));
  --mds-paginator-item-size: calc(var(--spacing) * 800);
}
```
