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 through "Add pair". Keying rows by id (not position) lets a parent reorder, insert, or remove other rows without disturbing a row's focused input.
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.
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' | Label for the add-row action. 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'`. |