Skip to content

TextEditor

Edits a text field and emits the string the API stores.

Terminal window
pnpm dlx shadcn@latest add https://sg-widgets.vercel.app/r/react/text-editor.json
Terminal window
pnpm dlx shadcn-svelte@latest add https://sg-widgets.vercel.app/r/svelte/text-editor.json
TextEditor: single line, multi-line, and the three blocked states

React

Loading the React demo…

Svelte

Loading the Svelte demo…

typed emitted
plate delivered "plate delivered"
padded "padded"
empty, or spaces only null
line1 newline line2 "line1\nline2"
proptypedefaultmeaning
valuestring | nullnullThe stored string. Two-way in Svelte.
onValueChange(value: string | null) => void—Called when the input commits.
fieldPick<FieldSchema, 'displayName' | 'mandatory'> | nullnullSupplies the accessible label and the required flag.
multilinebooleanfalseRenders a textarea.
rowsnumber3Rows of the textarea.
disabledbooleanfalse
readonlybooleanfalse
invalidbooleanfalseForced invalid state.
errorstring | nullnullA message from the caller, shown in place of the parse error.
onErrorChange(error: string | null) => void—Called when the parse error appears or clears.
placeholderstring—
class / classNamestring—Merged after the widget's own classes.
errorMessagefrom ValueEditor(message: string) => ReactNode / Snippet<[string]>—Renders the message. Default is a small destructive line under the control.
sizefrom ValueEditor'sm' | 'md' | 'lg''md'Control height.

onValueChange fires on commit only, never on a keystroke. onErrorChange reports the parse error.

errorMessage receives the message and renders it. Without it the message is a small line under the control.

keydoes
EnterCommits, on a single-line input.
EscapeRestores the stored value.
TabCommits by leaving the control.
Enterfrom ValueEditorCommits the draft. In a textarea it adds a line, and commitOnEnter turns the commit off.
Escapefrom ValueEditorRestores the stored value and drops what the last parse said.
Tabfrom ValueEditorLeaves the control, which commits.

Both ends of the value are stripped on write, and an empty string is stored as null, so there is no “set but blank” state to round-trip. A non-string is a 400 (field_types/text).