# Rich Text Editor (`<z-rte>`)

> TipTap-based rich text editor with a configurable grouped toolbar, word counter, and HTML value submission.

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

## Attributes

| Attribute | Type | Default | From | Description |
| --- | --- | --- | --- | --- |
| `toolbar` | `string` | `''` | — | Custom toolbar as grouped JSON arrays, e.g. `[["bold","italic"],["list"]]`. Items: bold, italic, underline, strikethrough, list, list-ordered, h1–h6, align-left/center/right/justify, blockquote (aliases like `strike` and `bullet-list` are accepted). |
| `readonly` | `boolean` | `false` | — | Makes the editor non-editable while keeping the toolbar visible. |

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

| Key | Default class | cls | stl | Description |
| --- | --- | --- | --- | --- |
| `body` | `z-rte-body` | ✓ | ✓ | Editor body wrapper (default `z-rte-body`). |
| `button` | `z-button z-button-default z-button-icon z-button-xsmall` | ✓ | ✓ | Toolbar button (default `z-button z-button-default z-button-icon z-button-xsmall`). |
| `editor` | — | ✓ | ✓ | The editable content region. |
| `footer` | `z-rte-footer` | ✓ | ✓ | Footer region with the word counter (default `z-rte-footer`). |
| `header` | `z-rte-header` | ✓ | ✓ | Header region above the toolbar. |
| `host-inner` | `z-rte` | ✓ | ✓ | Editor root (default `z-rte`); the default `cls`/`stl` target. |
| `toolbar` | `z-rte-toolbar` | ✓ | ✓ | The toolbar (default `z-rte-toolbar`). |
| `toolbar-group` | `z-rte-toolbar-group` | ✓ | ✓ | One toolbar button group (default `z-rte-toolbar-group`). |

## Reference inventories

- [Accessibility (7 ARIA parts)](https://next.0build.dev/docs/components/rte/accessibility.md)

## i18n Keys

| Key | Default | Description |
| --- | --- | --- |
| `aria-editor` | `Rich text editor` | Accessible label of the editable region. |
| `aria-toolbar` | `Formatting options` | Accessible label of the toolbar. |
| `tooltip-align-center` | `Align Center` | Align center button tooltip. |
| `tooltip-align-justify` | `Align Justify` | Align justify button tooltip. |
| `tooltip-align-left` | `Align Left` | Align left button tooltip. |
| `tooltip-align-right` | `Align Right` | Align right button tooltip. |
| `tooltip-blockquote` | `Blockquote` | Blockquote button tooltip. |
| `tooltip-bold` | `Bold` | Bold button tooltip. |
| `tooltip-h1` | `Heading 1` | Heading 1 button tooltip. |
| `tooltip-h2` | `Heading 2` | Heading 2 button tooltip. |
| `tooltip-h3` | `Heading 3` | Heading 3 button tooltip. |
| `tooltip-h4` | `Heading 4` | Heading 4 button tooltip. |
| `tooltip-h5` | `Heading 5` | Heading 5 button tooltip. |
| `tooltip-h6` | `Heading 6` | Heading 6 button tooltip. |
| `tooltip-italic` | `Italic` | Italic button tooltip. |
| `tooltip-list` | `List` | Bullet list button tooltip. |
| `tooltip-list-ordered` | `Ordered List` | Ordered list button tooltip. |
| `tooltip-strikethrough` | `Strikethrough` | Strikethrough button tooltip. |
| `tooltip-underline` | `Underline` | Underline button tooltip. |
| `word-counter-plural` | `words` | Word counter plural unit. |
| `word-counter-singular` | `word` | Word counter singular unit. |

## Events

| Event | Cancelable | Detail | Description |
| --- | --- | --- | --- |
| `z-rte:input` | — | `{ value: string \| string[] }` | Fires when the content changes; `detail.value` carries the HTML string. |

## Data Hooks

| Attribute | Values | Applies to | Role | Description |
| --- | --- | --- | --- | --- |
| `data-disabled` | — | `descendant` | `marker` | Set while the control is disabled. |
| `data-host-inner` | — | `descendant` | `config` | Marks the rendered inner wrapper so `force-prevent-rerender` can adopt server-rendered DOM without re-rendering. |
| `data-part` | `body` | `descendant` | `marker` | Marks the editor body in adopted server-rendered DOM (`data-part="body"`). |
| `data-reactive` | — | `descendant` | `config` | Opts the marked child (config script, data source, icons, or template) into live re-parsing when its DOM mutates. |
| `data-readonly` | — | `descendant` | `marker` | Set while the editor is read-only. |
| `data-tooltip` | — | `descendant` | `marker` | Tooltip text on toolbar buttons (consumed by the tooltip singleton). |

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

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

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

- `<template data-fn="value">` — Initial HTML content template (`<template data-fn="value">`).

  | Attribute | Required | Type | Description |
  | --- | --- | --- | --- |
  | `data-fn` | ✓ | `value` | Marks the template as the initial value (value: `value`). |
  | `data-reactive` | — | `boolean` | Re-reads the initial content when the template mutates. |

## Keyboard

| Keys | Action | When |
| --- | --- | --- |
| `Mod+B` / `Mod+I` / `Mod+U` | TipTap shortcuts for bold/italic/underline inside the editor. | — |

## Notes

- TipTap is an optional dependency loaded by the editor pack; there is no kit CSS layer — style via the parts.
- Toolbar buttons carry `data-tooltip`, so the shared tooltip singleton shows their labels on hover/focus.

## 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)
