Overview
Reference usage
KeyValueEditor edits repeatable string key/value pairs. Pass secret(key) to render sensitive values in an editable password Input.
The component owns row addition, removal, and change reporting. The consumer owns key validation and the policy that determines which keys are secret.
Usage
entries is the editable list; onValueChange is the callback form when the parent does not use a binding. The editor adds and removes rows and reports the resulting array, but it does not validate key syntax, deduplicate names, or persist changes. Supply secret={(key) => ...} to route matching values through a password input; the predicate receives the key only, so that callback does not receive the secret value or a policy object.
Each row's id is an immutable identity, independent of its editable key/value text — it must be unique within one editor's entries, but two rows may otherwise share equal key/value text. Consumers own minting id for the rows they supply (e.g. crypto.randomUUID()); the editor mints its own id for a row added by typing into its empty last row. Keying rows by id (not position) lets a parent reorder, insert, or remove other rows without disturbing a row's focused input.
Each row is one line: the key box, the value box, and an icon-only Remove control at the inline end, all the same height. keyLabel and valueLabel are drawn once, as quiet column headings above the rows, and name every row's two inputs for assistive technology (the inputs have no visible label of their own). A very narrow container stacks a row's key over its value, with Remove beside the key.
To add a pair, type into the empty row after the last one: the first keystroke makes it a real row, in place and without moving focus, and a new empty row appears under it. The empty row is not part of entries until then, and addLabel is its accessible description.
Give the list a name and a help line with label and description: the editor then becomes a labelled group, the label draws above the rows, and the description draws under them and is linked with aria-describedby. monospace draws both inputs in the code face, as environment variable names and secrets read best.
Give addLabel and removeLabel concrete action wording when the surrounding page has more than one editor. If a value fails validation or saving, keep the row and its text in the list so the user can correct it instead of treating a rejected update as a deletion.
When to use
- Editing headers, environment variables, or configuration fields.
- Values need rich structured content; use Table.
Examples
Basic key-value editor
Edit a small set of environment-style key-value entries.
Environment variables
A labelled list of masked variables: one line per row with a name box, a masked value box and an icon Remove at the end, Name and Value headings once above the rows, an empty last row that adds a variable when typed into, and help under it. Every value is masked, so the help says they are never shown again.
Props
Name | Type | Default | Description |
|---|---|---|---|
entries bindable | KeyValueEntry[] | [] | The editable list of key/value rows. Bindable. Defaults to [].
(KeyValueEntry is not expressible in JSON Schema, so this default
only appears here in prose.) |
onValueChange | (entries: KeyValueEntry[]) => void | Callback form of the resulting array, for when the parent does not use bind:entries. | |
secret | (key: string) => boolean | Predicate receiving a row's key; routes that row's value through a password input when it returns true. | |
addLabel | text | 'Add pair' | Accessible description of the empty last row, whose key and value boxes add a pair when typed
into. Give it concrete wording when more than one editor is on the page. Defaults to
'Add pair'. |
removeLabel | (key: string) => string | Label for a row's remove action, given that row's key. Give it concrete
wording when more than one editor is on the page. Defaults to
` (key) => Remove ${key || 'pair'} —an empty key (a newly added,
not-yet-named row) falls back to 'Remove pair'`. | |
label | text | Visible name for the whole list, shown above the rows ("Environment"). The editor becomes a labelled group, so a screen reader announces it when focus enters the list. | |
description | text | Help under the rows, linked to the group with aria-describedby. State what the values
are, such as that they are masked and never shown again. | |
keyLabel | text | 'Key' | Accessible name of every row's key input, also drawn once as the column heading above the
rows (the inputs have no visible label of their own). Give it the noun the rows use, such as
'Name' for environment variables. |
valueLabel | text | 'Value' | Accessible name of every row's value input, also drawn once as the column heading above the rows. |
monospace | boolean | false | Draws the key and value inputs in the monospace face, for identifiers and secrets such as environment variable names. |