# Key-Value Editor (`<z-kv>`)

> Editable key/value table with add/remove rows, value masking, random value generation, and row limits.

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

## Attributes

| Attribute | Type | Default | From | Description |
| --- | --- | --- | --- | --- |
| `noninsertable` | `boolean` | `false` | — | Hides the add-row affordances and blocks inserting rows. |
| `max` | `number` | `0` | — | Maximum number of rows (0 = unlimited). |
| `min` | `number` | `1` | — | Minimum number of rows; removal is blocked at the limit (default 1). |
| `aria-label` | `string` | `''` | — | Accessible label of the table (defaults to the `table-label` i18n text). |

### 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: `host-inner`. Default `stl` target: `host-inner`.

| Key | Default class | cls | stl | Description |
| --- | --- | --- | --- | --- |
| `actions` | `z-kv-actions` | ✓ | ✓ | Row actions group (default `z-kv-actions`). |
| `add-button` | `z-button z-button-default` | ✓ | ✓ | Add-row button (default `z-button z-button-default`). |
| `add-cell` | — | ✓ | ✓ | Add-row table cell. |
| `add-row` | — | ✓ | ✓ | Add-row table row. |
| `add-wrapper` | `z-kv-add-wrapper` | ✓ | ✓ | Add-row wrapper (default `z-kv-add-wrapper`). |
| `button` | `z-button z-button-default z-button-icon` | ✓ | — | Base row-action button styling. |
| `data-actions` | `z-table-shrink` | ✓ | ✓ | Row actions cell. |
| `data-key` | — | ✓ | ✓ | Key cell. |
| `data-value` | — | ✓ | ✓ | Value cell. |
| `header-actions` | `z-table-shrink` | ✓ | ✓ | Actions column header. |
| `header-key` | — | ✓ | ✓ | Key column header. |
| `header-row` | — | ✓ | ✓ | Row holding the column headers. |
| `header-value` | — | ✓ | ✓ | Value column header. |
| `host-inner` | `z-kv` | ✓ | ✓ | Editor root (default `z-kv`); the default `cls`/`stl` target. |
| `input` | `z-input` | ✓ | — | Shared input styling class (default `z-input`). |
| `key-input` | — | ✓ | — | Key text input. |
| `random-button` | — | ✓ | — | Random value generator button. |
| `remove-button` | `z-button z-button-danger z-button-outline z-button-icon` | ✓ | — | Row remove button (default danger outline icon button). |
| `row` | — | ✓ | ✓ | One data row. |
| `table` | `z-table z-table-divider z-table-responsive` | ✓ | ✓ | The key/value table (default `z-table z-table-divider z-table-responsive`). |
| `textarea` | `z-textarea` | ✓ | — | Shared textarea styling class (default `z-textarea`). |
| `toggle-button` | — | ✓ | — | Value visibility toggle button. |
| `value-input` | `z-input` | ✓ | — | Value text input. |
| `value-textarea` | `z-textarea` | ✓ | — | Value textarea (multiline values). |
| `value-wrapper` | `z-kv-value-wrapper` | ✓ | ✓ | Value field wrapper (default `z-kv-value-wrapper`). |

## CSS Variables

| Variable | Default | Scope | Affects | Description |
| --- | --- | --- | --- | --- |
| `--z-kv-border-color` | `var(--z-border)` | `.z-kv` | `border-color` | Border base color, mixed with transparency using `--z-kv-border-color-o`. |
| `--z-kv-border-color-o` | `10%` | `.z-kv` | `border-color` | Border opacity percentage used in the border color mix. |

## i18n Keys

| Key | Default | Description |
| --- | --- | --- |
| `actions-label` | `` | Accessible label of the actions group. |
| `add-button-text` | `` | Add-row button text. |
| `add-row-label` | `` | Accessible label of the add button. |
| `generate-random-label` | `` | Accessible label of random-value buttons. |
| `header-key` | `` | Key column header text. |
| `header-value` | `` | Value column header text. |
| `key-label` | `` | Accessible label of key inputs. |
| `placeholder-key` | `` | Placeholder of key inputs. |
| `placeholder-value` | `` | Placeholder of value inputs. |
| `remove-row-label` | `` | Accessible label of remove buttons. |
| `table-label` | `` | Accessible label of the table. |
| `toggle-visibility-label` | `` | Accessible label of visibility toggles. |
| `value-label` | `` | Accessible label of value inputs. |

## Icon Keys

| Key | Used in | Description |
| --- | --- | --- |
| `eye` | `toggle-button` | Show-value toggle icon. |
| `eye-off` | `toggle-button` | Hide-value toggle icon. |
| `plus` | `add-button` | Add-row button icon. |
| `trash-2` | `remove-button` | Remove-row button icon. |
| `wand` | `random-button` | Random-value button icon. |

## Data Hooks

| Attribute | Values | Applies to | Role | Description |
| --- | --- | --- | --- | --- |
| `data-action` | — | `descendant` | `marker` | Marks row action buttons. |
| `data-field` | `key`, `value` | `descendant` | `marker` | Marks key/value fields (`key` or `value`). |
| `data-host-inner` | — | `descendant` | `config` | Marks the rendered inner wrapper so `force-prevent-rerender` can adopt server-rendered DOM without re-rendering. |
| `data-part` | `add-button` | `descendant` | `marker` | Marks the add button in adopted server-rendered DOM (`data-part="add-button"`). |
| `data-reactive` | — | `descendant` | `config` | Opts the marked child (config script, data source, icons, or template) into live re-parsing when its DOM mutates. |
| `data-row-index` | — | `descendant` | `marker` | Set by the component on each row to its index. |

## 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-key` | — | `string` | Explicit key for this row; defaults to the option text when it differs from the value. |

  - `<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-key` | — | `string` | Explicit key for this row; defaults to the option text when it differs from the value. |

- `<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. |

## CSS Classes

| Class | Role | Applies to | Description |
| --- | --- | --- | --- |
| `.z-input` | `state` | `.z-kv` | Input styling applied to key/value fields. |
| `.z-kv` | `root` | `z-kv` | Root class of the editor. |
| `.z-kv-actions` | `state` | `.z-kv` | Row actions group layout. |
| `.z-kv-add-wrapper` | `state` | `.z-kv` | Add-row wrapper layout. |
| `.z-kv-value-wrapper` | `state` | `.z-kv` | Value field wrapper layout. |
| `.z-textarea` | `state` | `.z-kv` | Textarea styling applied to multiline values. |

## Keyboard

| Keys | Action | When |
| --- | --- | --- |
| `Mod+Enter` | Adds a new row (unless `noninsertable`). | — |

## Accessibility

| Part | Attributes | Description |
| --- | --- | --- |
| `actions` | `aria-label="${actionsLabel}"`, `role="group"` | Actions group: `role="group"` labeled by `actions-label`. |
| `add-button` | `aria-label="${addRowLabel}"` | Add button labeled by `add-row-label`. |
| `add-cell` | `role="cell"` | Add cell: `role="cell"`. |
| `add-row` | `role="row"` | Add row: `role="row"`. |
| `add-wrapper` | — | Add-row wrapper; no ARIA attributes. |
| `data-actions` | `role="cell"` | Actions cell: `role="cell"`. |
| `data-key` | `role="cell"` | Key cell: `role="cell"`. |
| `data-value` | `role="cell"` | Value cell: `role="cell"`. |
| `header-actions` | `role="columnheader"` | Actions header: `role="columnheader"`. |
| `header-key` | `role="columnheader"` | Key header: `role="columnheader"`. |
| `header-row` | `role="row"` | Header row: `role="row"`. |
| `header-value` | `role="columnheader"` | Value header: `role="columnheader"`. |
| `host-inner` | — | Editor root; no static ARIA attributes. |
| `key-input` | `aria-label="${keyLabel}"` | Key input labeled by `key-label`. |
| `random-button` | `aria-label="${randomLabel}"` | Random-value button labeled by `generate-random-label`. |
| `remove-button` | `aria-label="${removeLabel}"` | Remove button labeled by `remove-row-label`. |
| `row` | `role="row"` | Data row: `role="row"`. |
| `table` | `aria-label="${tableLabel}"`, `role="table"` | Table: `role="table"` labeled by `table-label`. |
| `toggle-button` | `aria-label="${toggleLabel}"`, `aria-pressed="${isVisible ? 'true' : 'false'}"` | Visibility toggle labeled by `toggle-visibility-label`, `aria-pressed` reflects visibility. |
| `value-input` | `aria-label="${valueLabel}"` | Value input labeled by `value-label`. |
| `value-textarea` | `aria-label="${valueLabel}"` | Value textarea labeled by `value-label`. |
| `value-wrapper` | — | Value wrapper; no ARIA attributes. |

> The editor is a labeled ARIA table; every input and action button carries an i18n-backed label.

## Notes

- Initial rows come from the shared `data-source` select: the option text is the key and the option value is the value.
- Masked values toggle between password-style and plain text per row; the wand button fills a random value.

## 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)
- [Table](https://next.0build.dev/docs/components/table.md)
