An interactive key-value table component for managing dynamic pairs of keys and values, supporting per-row sensitivity, multiline textareas, granular field locking, and native form integration.
The Key-Value component (<z-kv>) is designed for configuration panels, environment variable managers, metadata editors, and any interface requiring structured key-value pair inputs. Common use cases include:
.env style editors)Once everything is configured, you may use the <z-kv> markup in your HTML code:
Initial rows and fine-grained per-row behaviors are configured using a hidden <select data-fn="data-source"> element inside <z-kv>. Each <option> represents a single row in the table:
You can also pass the key as the text content of the <option> if data-key is omitted (as long as the text differs from the value attribute):
<z-kv>
<select data-fn="data-source" hidden>
<option value="Acme Corp">SITE_NAME</option>
</select>
</z-kv>Adding the data-reactive attribute to <select data-fn="data-source"> enables a MutationObserver that automatically syncs and re-renders the component whenever <option> elements or their attributes are modified externally in the DOM:
<z-kv>
<select data-fn="data-source" data-reactive hidden>
<option data-key="FEATURE_FLAG" value="true"></option>
</select>
</z-kv>Each <option> inside <select data-fn="data-source"> supports the following attributes for granular control over its row:
| Attribute | Aliases | Type | Default | Description |
|---|---|---|---|---|
data-key | <option> text | string | "" | Sets the key name for the row and binds it to the value input’s name attribute. |
value | — | string | "" | Sets the value for the row. |
data-sensitive | data-type="password" | boolean | false | Enables password masking, a random value generator button (wand), and a visibility toggle button (eye/eye-off) for the row. |
data-textarea | data-type="textarea" | boolean | false | Renders a multiline <textarea> instead of a single-line <input> for the value field. |
data-rows | — | number | 3 | Sets the rows attribute when the row is rendered as a <textarea>. |
data-removable | — | boolean | true | Controls whether the row can be deleted. Set data-removable="false" to lock the row against removal. |
data-readonly | — | boolean | false | Marks both the key and value fields as readonly and prevents DOM tampering. |
data-key-readonly | data-readonly-key | boolean | false | Marks only the key input as readonly (strict key mode) while keeping the value editable. |
data-value-readonly | data-readonly-value | boolean | false | Marks only the value field as readonly while keeping the key editable. |
disabled | — | boolean | false | Disables the entire row (key input, value field, action buttons, and removal). |
data-key-disabled | data-disabled-key | boolean | false | Disables only the key input for the row. |
data-value-disabled | data-disabled-value | boolean | false | Disables only the value field and its sensitive action buttons for the row. |
data-key-placeholder | data-placeholder-key | string | — | Overrides the key input placeholder text for this specific row. |
data-value-placeholder | data-placeholder-value, data-placeholder | string | — | Overrides the value input/textarea placeholder text for this specific row. |
When an <option> has data-sensitive (or data-type="password"), that specific row masks its value and renders two additional controls:
wand): Generates a 16-character random string when clicked, automatically reveals the value, and moves focus to the value field. To prevent accidental overwrites, the generator button is automatically disabled once the value field is non-empty, or if the value field is disabled/readonly.eye / eye-off): Toggles the value field between masked and plain text modes.Use data-textarea (or data-type="textarea") on an <option> to render a <textarea> for long values such as JSON payloads, descriptions, or SSH keys. You can customize the visible height using data-rows (defaults to 3), and even combine data-textarea with data-sensitive (which masks the textarea using -webkit-text-security: disc):
For predefined schema keys (such as meta-description or system keys) where users should edit the value without renaming or deleting the key, combine data-key-readonly and data-removable="false". Built-in tamper guards automatically revert unauthorized DOM edits if a user attempts to modify a readonly or disabled field via browser DevTools.
Control how many rows can exist in the table using min, max, and noninsertable:
min: Enforces a minimum number of rows (defaults to 1). If the data source has fewer rows than min, empty rows are automatically appended on initialization, and the remove button is disabled once the row count reaches min.max: Caps the total number of rows (defaults to 0 for unlimited). Once reached, the “Add” button is disabled.noninsertable: Hides the bottom “Add” button row completely and disables the Ctrl/Cmd + Enter shortcut.Because <z-kv> renders in the Light DOM, every row’s value <input> or <textarea> automatically binds its name attribute to that row’s key (option.data.key).
disabled so unnamed values are never submitted.<form> submission (FormData) under the key’s name.<form method="POST" action="/api/config">
<z-kv>
<select data-fn="data-source" hidden>
<option data-key="HOST" value="localhost"></option>
<option data-key="PORT" value="8080"></option>
</select>
</z-kv>
<button type="submit">Save Configuration</button>
</form>
<!-- Submits: HOST=localhost&PORT=8080 -->By default, internal icon slots use built-in icons, and you can also supply your own SVG icons globally via <template id="z-icons"> or locally per component via <template data-fn="icons">:
| Icon Key | Element Target | Description |
|---|---|---|
plus | add-button | Displayed inside the bottom “Add” button next to the button label. |
wand | random-button | Displayed inside the random value generator button on sensitive rows. |
eye | toggle-button | Displayed when a sensitive row’s value is currently masked (click to reveal). |
eye-off | toggle-button | Displayed when a sensitive row’s value is currently visible (click to mask). |
trash-2 | remove-button | Displayed inside the remove row button in the actions column. |
The Key-Value component supports internationalization through multiple methods with the following priority order (highest to lowest):
i18n attribute or <script data-fn="config">)<script id="z-i18n">)Place this in your document <head> or before any <z-kv> components:
<script id="z-i18n" type="application/json">
{
"z-kv": {
"header-key": "Schlüssel",
"header-value": "Wert",
"placeholder-key": "Schlüssel eingeben",
"placeholder-value": "Wert eingeben",
"add-button-text": "Hinzufügen",
"add-row-label": "Zeile hinzufügen",
"remove-row-label": "Zeile {index} entfernen",
"toggle-visibility-label": "Sichtbarkeit für Zeile {index} umschalten",
"generate-random-label": "Zufallswert für Zeile {index} generieren",
"table-label": "Schlüssel-Wert-Paare",
"actions-label": "Aktionen",
"key-label": "Schlüssel für Zeile {index}",
"value-label": "Wert für Zeile {index}"
}
}
</script>| Key | Default | Description |
|---|---|---|
header-key | "Key" | Column header text for the key column. |
header-value | "Value" | Column header text for the value column. |
actions-label | "Actions" | Column header text and ARIA group label for the actions column. |
placeholder-key | "Enter key" | Default placeholder for key input fields (unless overridden per row). |
placeholder-value | "Enter value" | Default placeholder for value input/textarea fields (unless overridden per row). |
add-button-text | "Add" | Visible text label inside the bottom add button. |
add-row-label | "Add row" | aria-label for the bottom add button. |
remove-row-label | "Remove row {index}" | aria-label for a row’s remove button. Supports {index} replacement (1-based). |
toggle-visibility-label | "Toggle visibility for row {index}" | aria-label for a sensitive row’s visibility toggle button. Supports {index}. |
generate-random-label | "Generate random value for row {index}" | aria-label for a sensitive row’s random generator button. Supports {index}. |
table-label | "Key-value pairs" | Default aria-label for the <table> element if the aria-label attribute is not set. |
key-label | "Key for row {index}" | aria-label for a row’s key input field. Supports {index}. |
value-label | "Value for row {index}" | aria-label for a row’s value input or textarea field. Supports {index}. |
The Key-Value component supports custom CSS classes through the cls attribute or configuration script. Every styled element also exposes a matching data-part="<target>" attribute in the DOM for easy inspection in browser DevTools.
Apply a class to the default element (host-inner):
<z-kv cls="z-kv my-custom-kv-wrapper"></z-kv>Target specific elements within the component:
<z-kv
cls='{
"host-inner": "z-kv rounded-lg",
"table": "z-table z-table-divider z-table-striped",
"input": "z-input z-input-sm",
"add-button": "z-button z-button-primary z-button-sm"
}'
></z-kv><z-kv>
<script type="application/json" data-fn="config">
{
"cls": {
"table": "z-table z-table-divider",
"add-button": "z-button z-button-default z-button-sm",
"remove-button": "z-button z-button-danger z-button-icon"
}
}
</script>
</z-kv>Target (data-part) | Default Class | Description |
|---|---|---|
host-inner | "z-kv" | Outer wrapper <div> around the table (default target for string cls/stl). |
table | "z-table z-table-divider" | The <table> element. |
header-row | "" | The <tr> element inside <thead>. |
header-key | "" | The Key column <th> element. |
header-value | "" | The Value column <th> element. |
header-actions | "z-table-shrink" | The Actions column <th> element. |
row | "" | Each data <tr> element inside <tbody>. |
data-key | "" | The <td> cell containing the key input. |
key-input | "" | Specific class for the key <input>. Falls back to input if empty. |
input | "z-input" | Shared fallback class for both key and value <input> elements. |
textarea | "z-textarea" | Fallback class for <textarea> elements (falls back to input if empty). |
data-value | "" | The <td> cell containing the value wrapper. |
value-wrapper | "z-kv-value-wrapper" | Flex container <div> holding the random generator button and value field. |
random-button | "" | Specific class for the wand button. Falls back to button if empty. |
value-input | "z-input" | Specific class for the value <input>. Falls back to input if empty. |
value-textarea | "z-textarea" | Specific class for the value <textarea>. Falls back to textarea then input. |
data-actions | "z-table-shrink" | The <td> cell containing the row action buttons. |
actions | "z-kv-actions" | Flex wrapper <div> around the visibility toggle and remove buttons. |
button | "z-button z-button-default z-button-icon" | Shared fallback class for icon action buttons (random-button, toggle-button, remove-button). |
toggle-button | "" | Specific class for the password visibility toggle button. Falls back to button. |
remove-button | "" | Specific class for the remove row button. Falls back to button. |
add-row | "" | The bottom <tr> housing the add button. |
add-cell | "" | The <td colspan="3"> cell spanning the bottom row. |
add-wrapper | "z-kv-add-wrapper" | Flex container <div> centering the add button inside add-cell. |
add-button | "z-button z-button-default" | The bottom “Add” <button> with icon and text label. |
The Key-Value component supports custom inline styles through the stl attribute or configuration script.
Apply inline styles to the default element (host-inner):
<z-kv stl="max-width\: 800px;"></z-kv>Target specific elements with custom inline styles:
<z-kv
stl='{
"host-inner": "max-width: 900px;",
"data-key": "width: 30%;",
"add-cell": "padding: 0.75rem;"
}'
></z-kv><z-kv>
<script type="application/json" data-fn="config">
{
"stl": {
"data-key": "width: 240px;",
"value-textarea": "min-height: 80px;"
}
}
</script>
</z-kv>The stl attribute supports the exact same targets as the cls attribute. See the Available cls targets table above for the complete list of targetable elements.
To indicate a validation error state on the component or specific inputs, apply .z-form-danger via the cls attribute:
When loading Web Components, a brief delay before hydration may cause a flash of unstyled content. Reserve vertical space on a wrapper element or use force-prevent-rerender when pre-rendering [data-host-inner] on the server:
<div class="[min-h]" style="--min-h: 8.75rem">
<z-kv></z-kv>
</div>The Key-Value component is built with comprehensive keyboard navigation and screen reader support:
role="table", role="row", role="columnheader" with scope="col", role="cell", and role="group" on each row’s action bar."Key for row 1", "Value for row 1", "Remove row 1", "Toggle visibility for row 1"), ensuring screen reader users always know which row they are interacting with.aria-pressed="true|false" to announce whether the secret value is currently visible.Ctrl + Enter (or Cmd + Enter on macOS) anywhere inside the component appends a new row (unless noninsertable or max is reached).wand) button automatically shifts focus to that row’s value input so keyboard focus is never lost when the generator button becomes disabled.min="0").The following attributes are available on the <z-kv> element:
| Name | Type | Default | Description |
|---|---|---|---|
noninsertable | boolean | false | Hides the “Add” button row and prevents users from inserting new rows. |
min | number | 1 | Minimum number of rows required. Prevents row deletion once this count is reached and pads initial rows if fewer are provided. |
max | number | 0 | Maximum number of rows allowed (0 means unlimited). Disables the “Add” button once reached. |
aria-label | string | "" | Accessible label for the <table>. Overrides the table-label i18n string when provided. |
cls | string | "" | Custom CSS classes (plain string for host-inner or serialized JSON/options object for specific targets). |
stl | string | "" | Custom inline styles (plain string for host-inner or serialized JSON/options object for specific targets). |
i18n | string | "" | Custom localization strings (serialized JSON/options object). |
force-prevent-rerender | boolean | false | Prevents re-rendering if [data-host-inner] is already present in the DOM (useful for SSR hydration). |