Skip to content

UrlEditor

Edits a url field as a web link. Uploads are not in scope.

Terminal window
pnpm dlx shadcn@latest add https://sg-widgets.vercel.app/r/react/url-editor.json
Terminal window
pnpm dlx shadcn-svelte@latest add https://sg-widgets.vercel.app/r/svelte/url-editor.json
UrlEditor: a web link, an unset field, and a local path it will not edit

React

Loading the React demo…

Svelte

Loading the Svelte demo…

typed emitted
an address and a name { url, name }
an address, no name { url }; the field reads back the address as its name
both empty null
an address holding a raw space nothing; percent-encode it
a name and no address nothing
proptypedefaultmeaning
valueUrlValue | nullnullThe stored object. Two-way in Svelte.
onValueChange(value: UrlWriteValue | null) => void—Called when either input commits.
fieldPick<FieldSchema, 'displayName' | 'mandatory'> | nullnullSupplies the accessible label and the required flag.
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.
placeholderstringan example addressPlaceholder of the address input.
namePlaceholderstring'Name'Placeholder of the name input.
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.

A value whose link type is local carries paths and no address. The control shows a line saying so and takes no input.

onValueChange fires on commit only. Input that does not parse emits nothing.

errorMessage receives the message and renders it.

keydoes
EnterCommits both inputs.
EscapeRestores the stored value.
TabMoves between address and name.
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.

The only accepted write is an object holding url. A bare string is a 400, and so is {} and an object carrying only a type and an id (field_types/url).

The address itself is validated. A raw space is the one character measured to fail; the same address with the space percent-encoded is accepted (field_types/url).

Each accepted write mints a new Attachment row and the value reads back as link_type: web. Only null clears the field, and each derived field has to be cleared by name (field_types/url).