ValidValuesEditor
Edits the valid values of a list field or of a status list field, and emits them as an array of strings.
Install
Section titled “Install”pnpm dlx shadcn@latest add https://sg-widgets.vercel.app/r/react/valid-values-editor.jsonpnpm dlx shadcn-svelte@latest add https://sg-widgets.vercel.app/r/svelte/valid-values-editor.jsonReact
Loading the React demo…
Svelte
Loading the Svelte demo…
A list is one row per value. The order of the rows is the order of the array, which is the order of the field’s drop-down.
| done | emitted |
|---|---|
Look Dev typed in the add row, then Enter |
the list with "Look Dev" appended |
padded typed in a row |
that row as "padded" |
| a row emptied, or left with spaces only | the list without that row |
| three lines pasted in the add row | the list with three values appended, in order |
| three lines pasted in a row | the three values in that row’s place |
| a row dragged, or moved with the keyboard | the list in its new order |
| the cross on a row | the list without that row |
A blank line in a pasted text is dropped. A paste of one line is the input’s own, so it lands at the caret. A row commits when it loses focus and on Enter, never on a keystroke.
A repeated value is kept as typed. With unique the later one is dropped, compared byte for byte,
so Type A and type a are two values.
A status list is a picker over the site’s statuses, each drawn with its icon, name and code. It is
the status multi picker with no entity type and a chip row, and it
emits the codes in the order they were picked; that order carries no meaning. It needs a context to
read the statuses. Without one the codes are typed, one row per code, as a list’s values are.
| prop | type | default | meaning |
|---|---|---|---|
dataType | 'list' | 'status_list' | 'list' | The field's data type: an ordered list of strings, or status codes. |
value | string[] | [] | The valid values: strings in drop-down order, or status codes. bind:value in Svelte, value with onValueChange in React. |
context | SgContext | — | The widget context. A status list picks from the site's statuses through it; without one its codes are typed. |
unique | boolean | false | Drops a value the list already holds, keeping the first. Off, a repeated value is kept. |
placeholder | string | by data type | Shown in the add row, or in an empty status picker. |
emptyLabel | string | 'No values' | Shown in a read-only editor that holds no value. |
size | 'sm' | 'md' | 'lg' | 'md' | Row height. A box of one row stands at 28, 32 and 36. |
disabled | boolean | false | Greys the editor and takes it out of the tab order. |
readonly | boolean | false | Keeps full contrast and drops the grips, the remove controls and the add row. |
invalid | boolean | false | Sets aria-invalid and the destructive ring. |
class / className | string | — | Merged after the widget's own classes. |
Every other attribute is spread onto the root: id, aria-*, data-*, key handlers and a ref
to the root element.
The trimming, the split into lines and the option to drop repeats are functions of the core package, for a caller that takes the values from somewhere else, a textarea or a file.
import { normalizeListValues, splitListValues } from 'sg-widgets-core';
splitListValues('VFX\n 2D \n\nFull CG'); // ['VFX', '2D', 'Full CG']normalizeListValues(['a', ' a ', ''], { unique: true }); // ['a']Events
Section titled “Events”| event | payload | when |
|---|---|---|
onValueChange | string[] | A value was committed, added, removed or moved, or a status was picked or removed. |
None.
Keyboard
Section titled “Keyboard”| key | does |
|---|---|
| Enter in a value | Commits the value and moves to the next one, or to the add row |
| Esc in a value | Puts back the value as it was |
| Backspace in an empty value | Removes the value and moves to the one before |
| Enter in the add row | Adds the value and stays in the add row |
| Backspace in an empty add row | Moves to the last value |
| Alt + ↑, Alt + ↓ | Moves the value holding focus one place |
| Space, Enter on a grip | Picks the value up for the arrow keys |
| ↑ ↓ while carrying a value | Move it one place |
| Space, Enter while carrying a value | Drop it where it is |
| Esc while carrying a value | Put it back where it was |
| Tab | Moves through each value's grip, text and remove control, then to the add row |
A status list takes the keyboard of the status multi picker.
API behaviour
Section titled “API behaviour”A list field’s value is one of its valid values, compared byte for byte on write: another case and a trailing space are both a 400. So the editor trims a value where it is defined and never changes its case (field_types/list).
A status list field holds a status code, never a label, and the icon and the colour of a code come from the site’s Status table, which is site-wide and keyed by code (field_types/status_list, probe 010).
The reordering is the registry’s own sortable, the one the sort picker uses.