# Select (`<z-select>`)

> Custom select with a searchable, keyboard-navigable listbox, optional multi-select, insertable options, and remote option insertion.

- **Kind:** hwc
- **Category:** inputs
- **Inherits:** `BaseSelectMixin`, `DropdownMixin`, `InputMixin`, `Hwc`, `Base`

## Attributes

| Attribute | Type | Default | From | Description |
| --- | --- | --- | --- | --- |
| `searchable` | `boolean` | `false` | — | Shows a search field that filters options by text, value, and keywords. |
| `insertable` | `boolean` | `false` | — | Allows inserting the current search term as a new option (forces `searchable`); with `send-url` the term is sent to the server first. |
| `send-headers` | `string` | `''` | — | JSON object of request headers for the insert request (defaults to `Content-Type: application/json`). |
| `send-url` | `string` | `''` | — | Endpoint that receives `{ term }` when inserting; the JSON response must be an option item, otherwise a local option is created from the term. |
| `send-method` | `string` | `'POST'` | — | HTTP method for the insert request (default `POST`). |
| `multiple` | `boolean` | `false` | — | Allows selecting several options; the value submits as `name[]`. |
| `icon` | `string` | `''` | — | Icon key for the trigger affordance; defaults to the built-in `chevrons-up-down` icon. |

### Inherited from `InputMixin`

| Attribute | Type | Default | From | Description |
| --- | --- | --- | --- | --- |
| `disabled` | `boolean` | `false` | `InputMixin` | Disables the control so it cannot be interacted with. |
| `form` | `string` | `''` | `InputMixin` | Associates the hidden form input with a form by id, even when the component sits outside that form. |
| `name` | `string` | `''` | `InputMixin` | Field name for the hidden form input; array values submit as `name[]`. |
| `placeholder` | `string` | `''` | `InputMixin` | Placeholder text for the control's empty state. |
| `required` | `boolean` | `false` | `InputMixin` | Marks the control as required. |
| `value` | `string` | `''` | `InputMixin` | Initial value of the control, synchronized with the hidden form input. |

### Inherited from `Hwc`

| Attribute | Type | Default | From | Description |
| --- | --- | --- | --- | --- |
| `i18n` | `string` | `''` | `Hwc` | Per-instance text overrides as `key: text` pairs, merged over the global `z-i18n` script and the built-in defaults. |
| `floating` | `string` | `''` | `Hwc` | Floating UI placement options (for example `offset` and `shiftPadding`) parsed as `key: value` pairs. |
| `force-prevent-rerender` | `boolean` | `false` | `Hwc` | Skips re-rendering after the first render; an existing `data-host-inner` child is adopted as the rendered DOM. |
| `template` | `string` | `''` | `Hwc` | Selector or id of an external element or `<template>` whose inner content is cloned in place of an inline `template[data-fn="template"]` child. |

### Inherited from `Base`

| Attribute | Type | Default | From | Description |
| --- | --- | --- | --- | --- |
| `cls` | `string` | `''` | `Base` | Adds classes to named parts as `key: classes` pairs; a plain string targets the default part. |
| `stl` | `string` | `''` | `Base` | Adds inline styles to named parts as `key: styles` pairs; a plain string targets the default part. |

## Styling Parts (`cls` / `stl`)

Default `cls` target: `button`. Default `stl` target: `button`.

| Key | Default class | cls | stl | Description |
| --- | --- | --- | --- | --- |
| `button` | — | ✓ | ✓ | The combobox trigger button. |
| `button-text` | — | ✓ | ✓ | Text span inside the trigger showing the selection. |
| `divider` | `z-hr` | ✓ | ✓ | Divider between option groups (default `z-hr`). |
| `dropdown` | `z-select-dropdown` | ✓ | ✓ | The floating dropdown panel (default `z-select-dropdown`). |
| `host-inner` | `z-position-relative` | ✓ | ✓ | Rendered root wrapper (default `z-position-relative`). |
| `icon` | — | ✓ | ✓ | Trigger affordance icon slot. |
| `item` | — | ✓ | — | One option row. |
| `item-active` | `z-active` | ✓ | — | Class applied to the focused/selected option (default `z-active`). |
| `item-check` | — | ✓ | — | Selection check indicator. |
| `item-disabled` | `z-disabled` | ✓ | — | Class applied to disabled options (default `z-disabled`). |
| `item-header` | `z-nav-header` | ✓ | ✓ | Group header row (default `z-nav-header`). |
| `item-icon` | `z-custom-select-item-icon` | ✓ | — | Option icon slot (default `z-custom-select-item-icon`). |
| `item-link` | — | ✓ | — | Clickable link/button inside an option row. |
| `item-subtitle` | — | ✓ | — | Secondary option text. |
| `item-text` | `z-custom-select-item-text` | ✓ | — | Option label text (default `z-custom-select-item-text`). |
| `item-wrapper` | `z-custom-select-item-wrapper` | ✓ | — | Inner wrapper of an option row (default `z-custom-select-item-wrapper`). |
| `list` | `z-nav z-dropdown-nav z-overflow-auto z-custom-select-list` | ✓ | ✓ | The option listbox (default `z-nav z-dropdown-nav z-overflow-auto z-custom-select-list`). |
| `search` | `z-custom-select-search` | ✓ | — | Search field wrapper (default `z-custom-select-search`). |
| `search-icon` | — | ✓ | — | Icon inside the search field. |
| `search-input` | — | ✓ | — | The search text input. |

## Reference inventories

- [CSS Variables (7)](https://next.0build.dev/docs/components/select/css-vars.md)
- [CSS Classes (6)](https://next.0build.dev/docs/components/select/css-classes.md)
- [Accessibility (18 ARIA parts)](https://next.0build.dev/docs/components/select/accessibility.md)

## i18n Keys

| Key | Default | Description |
| --- | --- | --- |
| `button-label` | `Select an option` | Accessible label of the trigger button. |
| `insert` | `Insert` | Label of the insert-option action. |
| `list-label` | `Options` | Accessible label of the option listbox. |
| `search-placeholder` | `Search` | Placeholder and accessible label of the search input. |
| `selection-count` | `{n} options selected` | Trigger text template for multi-select with `{n}` placeholder. |

## Icon Keys

| Key | Used in | Description |
| --- | --- | --- |
| `check` | `item-check` | Marks selected options. |
| `chevrons-up-down` | `icon` | Default trigger affordance. |
| `search` | `search-icon` | Search field icon. |

## Events

| Event | Cancelable | Detail | Description |
| --- | --- | --- | --- |
| `z-select:input` | — | `{ value: string \| string[] }` | Fires when the selection changes; `detail.value` carries the new value as a string or string array. |
| `z-select:search` | — | `{ value: string }` | Fires when the search term changes; `detail.value` carries the current term. |

## Data Hooks

| Attribute | Values | Applies to | Role | Description |
| --- | --- | --- | --- | --- |
| `data-host-inner` | — | `descendant` | `config` | Marks the rendered inner wrapper so `force-prevent-rerender` can adopt server-rendered DOM without re-rendering. |
| `data-index` | — | `descendant` | `marker` | Set by the component on option rows to their global index. |
| `data-key` | — | `descendant` | `marker` | Set by the component on option rows to their option key. |
| `data-part` | `dropdown` | `descendant` | `marker` | Marks the dropdown panel in adopted server-rendered DOM (`data-part="dropdown"`). |
| `data-reactive` | — | `descendant` | `config` | Opts the marked child (config script, data source, icons, or template) into live re-parsing when its DOM mutates. |

## Child Content

- `<script data-fn="config">` — JSON configuration script parsed by the base class (i18n, cls, stl, floating).

  | Attribute | Required | Type | Description |
  | --- | --- | --- | --- |
  | `data-fn` | ✓ | `config` | Marks the script as configuration (value: `config`). |
  | `data-reactive` | — | `boolean` | Re-parses the configuration when the script mutates. |

- `<select data-fn="data-source">` — Hidden select parsed into grouped option data by the base class.

  | Attribute | Required | Type | Description |
  | --- | --- | --- | --- |
  | `data-fn` | ✓ | `data-source` | Marks the select as the data source (value: `data-source`). |
  | `data-reactive` | — | `boolean` | Re-parses the options when the select mutates. |

  - `<optgroup>` — Groups options under a label.

    | Attribute | Required | Type | Description |
    | --- | --- | --- | --- |
    | `label` | ✓ | `string` | Group header text; also the default group key. |
    | `disabled` | — | `boolean` | Disables every option in the group. |
    | `data-key` | — | `string` | Overrides the group key used in the parsed data. |
    | `data-keywords` | — | `comma-separated string` | Comma-separated keywords stored with the group's data. |

    - `<option>` — One option entry within the group.

      | Attribute | Required | Type | Description |
      | --- | --- | --- | --- |
      | `value` | — | `string` | Value carried by this option in the parsed data. |
      | `disabled` | — | `boolean` | Makes the option non-selectable. |
      | `selected` | — | `boolean` | Marks the option as initially selected. |
      | `data-keywords` | — | `comma-separated string` | Extra search terms, comma-separated; searched alongside the label and value. |
      | `data-description` | — | `string` | Secondary text shown under the option label. |
      | `data-gid` | — | `string` | Group id stored in the option's parsed data. |
      | `data-icon` | — | `string` | Icon key rendered beside the option label, resolved from the icon repository. |

  - `<option>` — One ungrouped option entry.

    | Attribute | Required | Type | Description |
    | --- | --- | --- | --- |
    | `value` | — | `string` | Value carried by this option in the parsed data. |
    | `disabled` | — | `boolean` | Makes the option non-selectable. |
    | `selected` | — | `boolean` | Marks the option as initially selected. |
    | `data-keywords` | — | `comma-separated string` | Extra search terms, comma-separated. |
    | `data-description` | — | `string` | Secondary text shown under the option label. |
    | `data-gid` | — | `string` | Group id stored in the option's parsed data. |
    | `data-icon` | — | `string` | Icon key rendered beside the option label, resolved from the icon repository. |

- `<template data-fn="icons">` — Instance-level icon repository.

  | Attribute | Required | Type | Description |
  | --- | --- | --- | --- |
  | `data-fn` | ✓ | `icons` | Marks the template as an icon source (value: `icons`). |
  | `data-reactive` | — | `boolean` | Re-parses the icons when the template mutates. |

  - `<*>` — One icon element.

    | Attribute | Required | Type | Description |
    | --- | --- | --- | --- |
    | `data-key` | ✓ | `string` | Icon key referenced by `$icons`. |

- `<template data-fn="template">` — Deferred content template mounted by the base class.

  | Attribute | Required | Type | Description |
  | --- | --- | --- | --- |
  | `data-fn` | ✓ | `template` | Marks the template for deferred mounting (value: `template`). |
  | `data-reactive` | — | `boolean` | Re-parses the template when it mutates. |

## Keyboard

| Keys | Action | When |
| --- | --- | --- |
| `ArrowDown` / `ArrowUp` / `Home` / `End` | Move the focused option; Enter/Space selects it. | The dropdown is open. |
| `Escape` | Closes the dropdown. | — |

## Notes

- The dropdown teleports and positions with Floating UI; `floating` tunes offset/shift.
- Insert flow: with `send-url`, the term is POSTed and the response must validate as an option item; on any failure a local option is created from the term.

## Guides

- [Styling with cls and stl](https://next.0build.dev/docs/guides/styling.md)
- [Translating Components](https://next.0build.dev/docs/guides/i18n.md)
- [Icon Resolution](https://next.0build.dev/docs/guides/icons.md)
- [The data-source Convention](https://next.0build.dev/docs/guides/data-source.md)
- [Openers & Triggers](https://next.0build.dev/docs/guides/triggers.md)
- [Dialog Behavior](https://next.0build.dev/docs/guides/dialogs.md)
- [Utilities](https://next.0build.dev/docs/guides/utilities.md)
- [Runtime](https://next.0build.dev/docs/guides/runtime.md)

## Related

- [Tag Input](https://next.0build.dev/docs/components/input-tag.md)
- [Command](https://next.0build.dev/docs/components/command.md)
