Skip to content

ValidValuesEditor

Edits the valid values of a list field or of a status list field, and emits them as an array of strings.

Terminal window
pnpm dlx shadcn@latest add https://sg-widgets.vercel.app/r/react/valid-values-editor.json
Terminal window
pnpm dlx shadcn-svelte@latest add https://sg-widgets.vercel.app/r/svelte/valid-values-editor.json
ValidValuesEditor: an ordered list, an empty one, unique values, a status list with and without a site, and the blocked states

React

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.

proptypedefaultmeaning
dataType'list' | 'status_list''list'The field's data type: an ordered list of strings, or status codes.
valuestring[][]The valid values: strings in drop-down order, or status codes. bind:value in Svelte, value with onValueChange in React.
contextSgContext—The widget context. A status list picks from the site's statuses through it; without one its codes are typed.
uniquebooleanfalseDrops a value the list already holds, keeping the first. Off, a repeated value is kept.
placeholderstringby data typeShown in the add row, or in an empty status picker.
emptyLabelstring'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.
disabledbooleanfalseGreys the editor and takes it out of the tab order.
readonlybooleanfalseKeeps full contrast and drops the grips, the remove controls and the add row.
invalidbooleanfalseSets aria-invalid and the destructive ring.
class / classNamestring—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']
eventpayloadwhen
onValueChangestring[]A value was committed, added, removed or moved, or a status was picked or removed.

None.

keydoes
Enter in a valueCommits the value and moves to the next one, or to the add row
Esc in a valuePuts back the value as it was
Backspace in an empty valueRemoves the value and moves to the one before
Enter in the add rowAdds the value and stays in the add row
Backspace in an empty add rowMoves to the last value
Alt + ↑, Alt + ↓Moves the value holding focus one place
Space, Enter on a gripPicks the value up for the arrow keys
↑ ↓ while carrying a valueMove it one place
Space, Enter while carrying a valueDrop it where it is
Esc while carrying a valuePut it back where it was
TabMoves 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.

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.