Shadcn Field
Combine labels, controls, help text, and validation errors into accessible form fields with synchronous and async validation.
Combine a label, form control, helper description, and validation errors into one accessible field unit supporting vertical and horizontal layouts, built-in constraints, controlled validity, and async validation. The examples on this page use the Shadcn Rhea style preset.
Preview
Section titled “Preview”<div class="grid max-w-sm gap-5">
<proto-ui-shadcn-field-root
id="field-user"
required
min-length="4"
validation-mode="onBlur"
>
<proto-ui-shadcn-field-label>
Username
</proto-ui-shadcn-field-label>
<proto-ui-shadcn-field-control
placeholder="At least 4 characters"
></proto-ui-shadcn-field-control>
<proto-ui-shadcn-field-description>
Validated automatically on blur.
</proto-ui-shadcn-field-description>
<proto-ui-shadcn-field-error></proto-ui-shadcn-field-error>
</proto-ui-shadcn-field-root>
<proto-ui-shadcn-field-root
id="field-async"
external-validation
validation-mode="onChange"
>
<proto-ui-shadcn-field-label>
Subdomain
</proto-ui-shadcn-field-label>
<proto-ui-shadcn-field-control
default-value="studio"
placeholder='Try "taken"'
></proto-ui-shadcn-field-control>
<proto-ui-shadcn-field-description>
Type "taken" to trigger an async availability error.
</proto-ui-shadcn-field-description>
<proto-ui-shadcn-field-error></proto-ui-shadcn-field-error>
</proto-ui-shadcn-field-root>
</div>
<script type="module">
const asyncField = document.querySelector('#field-async');
asyncField?.addEventListener('validationRequest', (event) => {
const { requestId, value } = event.detail;
setTimeout(() => {
const invalid = value === 'taken';
asyncField.getExposes().resolveValidation(requestId, {
invalid,
errors: invalid
? ['This subdomain is already reserved.']
: [],
});
}, 350);
});
</script>Installation
Section titled “Installation”This component is available from workspace source. In your application, install the CLI, Shadcn prototypes and target adapter built from the same workspace revision, then initialize the project with that CLI. Run the locally installed CLI to generate the facade.
npm exec -- proto-ui add wc shadcn-field
Replace wc with react, vue, or vue2 to generate the local facade for your framework.
You can also import fieldRoot, fieldLabel, fieldControl, fieldDescription, fieldError, and fieldValidity directly from @proto.ui/prototypes-shadcn/field.
import { FieldRoot, FieldLabel, FieldControl, FieldDescription, FieldError,} from '@/components/ui/shadcn-field';
export function ProfileField() { return ( <FieldRoot required minLength={3}> <FieldLabel>Username</FieldLabel> <FieldControl placeholder="Max Leiter" /> <FieldDescription>Choose a unique username for your account.</FieldDescription> <FieldError /> </FieldRoot> );}Anatomy
Section titled “Anatomy”FieldRoot├── FieldLabel├── FieldControl | FieldTextarea | FieldSelectTrigger | FieldSwitch | FieldCheckbox | FieldRadioGroup├── FieldDescription├── FieldError└── FieldValidity (optional, repeatable)- Root: Manages
invalid,pending,dirty,touched,filled, andfocusedstates along withdisabled,readOnly,required,orientation, andstyleProfile. Nested roots maintain isolated scopes. - Control: Renders a single-line text editor by default, or pair with
fieldTextarea,fieldSelectTrigger,fieldSwitch,fieldCheckbox,fieldRadioGroup, or custom controls bridged via BaseasFieldControl. - Label: Automatically wires
aria-labelledbyto the paired control and focuses it on click (disable withactivation={false}). - Description & Error: Automatically wire and clean up
aria-describedbyand (while invalid)aria-errormessage.Errorunmounts when hidden by default (setkeepMountedto retain a hidden node). - Validity: Passive reader exposing
getValidity().
Synchronous and asynchronous validation
Section titled “Synchronous and asynchronous validation”- Built-in rules: Supports
required,minLength, andmaxLength(UTF-16 code units; optional empty strings skip length checks). Built-in flags arevalueMissing,tooShort, andtooLong; external errors usecustomError. - Triggers:
validationModesupports'onBlur'(default),'onChange'(waits for IMEcompositionend), and'manual'. - Async validation: With
externalValidation={true}, passing built-in checks emitsvalidationRequest({ requestId, value, reason }). CallresolveValidation(requestId, { invalid, errors })once complete; stale replies are discarded automatically. - Controlled validity: Pass
invalidanderrorsto manage validity externally;validityChangeemits proposed updates. Pair with Fieldset and Form for grouped disabling, submission, and form reset.
Examples
Section titled “Examples”Compose FieldLabel, FieldControl, and FieldDescription with helper copy positioned below or above the input.
<div class="grid max-w-sm gap-5">
<proto-ui-shadcn-field-root required>
<proto-ui-shadcn-field-label>
Username
</proto-ui-shadcn-field-label>
<proto-ui-shadcn-field-control
placeholder="Max Leiter"
></proto-ui-shadcn-field-control>
<proto-ui-shadcn-field-description>
Choose a unique username for your account.
</proto-ui-shadcn-field-description>
<proto-ui-shadcn-field-error></proto-ui-shadcn-field-error>
</proto-ui-shadcn-field-root>
<proto-ui-shadcn-field-root required min-length="8">
<proto-ui-shadcn-field-label>
Workspace token
</proto-ui-shadcn-field-label>
<proto-ui-shadcn-field-description>
Must be at least 8 characters long.
</proto-ui-shadcn-field-description>
<proto-ui-shadcn-field-control
placeholder="pui_live_••••••••"
></proto-ui-shadcn-field-control>
<proto-ui-shadcn-field-error></proto-ui-shadcn-field-error>
</proto-ui-shadcn-field-root>
</div>Textarea
Section titled “Textarea”Use FieldTextarea so multiline editors share the same accessible labeling and validation lifecycle.
<proto-ui-shadcn-field-root
required
min-length="10"
class="max-w-sm"
>
<proto-ui-shadcn-field-label>
Feedback
</proto-ui-shadcn-field-label>
<proto-ui-shadcn-field-textarea
rows="4"
placeholder="Your feedback helps us improve..."
></proto-ui-shadcn-field-textarea>
<proto-ui-shadcn-field-description>
Share your thoughts about our service.
</proto-ui-shadcn-field-description>
<proto-ui-shadcn-field-error></proto-ui-shadcn-field-error>
</proto-ui-shadcn-field-root>Select
Section titled “Select”Replace the Select trigger with FieldSelectTrigger to link Select with FieldLabel, FieldDescription, and invalid styling.
<proto-ui-shadcn-field-root required class="max-w-sm">
<proto-ui-shadcn-field-label>
Department
</proto-ui-shadcn-field-label>
<proto-ui-shadcn-select-root default-value="engineering">
<proto-ui-shadcn-field-select-trigger>
<proto-ui-shadcn-select-value
placeholder="Choose department"
></proto-ui-shadcn-select-value>
</proto-ui-shadcn-field-select-trigger>
<proto-ui-shadcn-select-content>
<proto-ui-shadcn-select-surface>
<proto-ui-shadcn-select-viewport>
<proto-ui-shadcn-select-group>
<proto-ui-shadcn-select-label>
Departments
</proto-ui-shadcn-select-label>
<proto-ui-shadcn-select-item value="engineering">
<proto-ui-shadcn-select-item-text>
Engineering
</proto-ui-shadcn-select-item-text>
</proto-ui-shadcn-select-item>
<proto-ui-shadcn-select-item value="design">
<proto-ui-shadcn-select-item-text>
Design
</proto-ui-shadcn-select-item-text>
</proto-ui-shadcn-select-item>
</proto-ui-shadcn-select-group>
</proto-ui-shadcn-select-viewport>
</proto-ui-shadcn-select-surface>
</proto-ui-shadcn-select-content>
</proto-ui-shadcn-select-root>
<proto-ui-shadcn-field-description>
Select your department or primary area of work.
</proto-ui-shadcn-field-description>
<proto-ui-shadcn-field-error></proto-ui-shadcn-field-error>
</proto-ui-shadcn-field-root>Checkbox, Radio & Switch
Section titled “Checkbox, Radio & Switch”Use orientation="horizontal" for compact Switch and Checkbox rows, or compose FieldRadioGroup for single-choice plans.
<div class="grid max-w-sm gap-6">
<proto-ui-shadcn-field-root required>
<proto-ui-shadcn-field-label>
Subscription plan
</proto-ui-shadcn-field-label>
<proto-ui-shadcn-field-description>
Yearly and team plans include priority support.
</proto-ui-shadcn-field-description>
<proto-ui-shadcn-field-radio-group default-value="pro">
<proto-ui-shadcn-radio-group-item value="free">
<proto-ui-shadcn-radio-group-indicator></proto-ui-shadcn-radio-group-indicator>
</proto-ui-shadcn-radio-group-item>
<proto-ui-shadcn-radio-group-item value="pro">
<proto-ui-shadcn-radio-group-indicator></proto-ui-shadcn-radio-group-indicator>
</proto-ui-shadcn-radio-group-item>
<proto-ui-shadcn-radio-group-item value="team">
<proto-ui-shadcn-radio-group-indicator></proto-ui-shadcn-radio-group-indicator>
</proto-ui-shadcn-radio-group-item>
</proto-ui-shadcn-field-radio-group>
<proto-ui-shadcn-field-error></proto-ui-shadcn-field-error>
</proto-ui-shadcn-field-root>
<proto-ui-shadcn-field-root orientation="horizontal">
<proto-ui-shadcn-field-label>
Sync desktop & documents
</proto-ui-shadcn-field-label>
<proto-ui-shadcn-field-checkbox default-checked>
<proto-ui-shadcn-checkbox-indicator></proto-ui-shadcn-checkbox-indicator>
</proto-ui-shadcn-field-checkbox>
</proto-ui-shadcn-field-root>
<proto-ui-shadcn-field-root orientation="horizontal">
<proto-ui-shadcn-field-label>
Multi-factor authentication
</proto-ui-shadcn-field-label>
<proto-ui-shadcn-field-switch default-checked>
<proto-ui-shadcn-switch-thumb></proto-ui-shadcn-switch-thumb>
</proto-ui-shadcn-field-switch>
</proto-ui-shadcn-field-root>
</div>Validation & Async Check
Section titled “Validation & Async Check”Demonstrates blur-triggered built-in validation alongside async availability checks (type taken to trigger an error).
<div class="grid max-w-sm gap-5">
<proto-ui-shadcn-field-root
id="field-user"
required
min-length="4"
validation-mode="onBlur"
>
<proto-ui-shadcn-field-label>
Username
</proto-ui-shadcn-field-label>
<proto-ui-shadcn-field-control
placeholder="At least 4 characters"
></proto-ui-shadcn-field-control>
<proto-ui-shadcn-field-description>
Validated automatically on blur.
</proto-ui-shadcn-field-description>
<proto-ui-shadcn-field-error></proto-ui-shadcn-field-error>
</proto-ui-shadcn-field-root>
<proto-ui-shadcn-field-root
id="field-async"
external-validation
validation-mode="onChange"
>
<proto-ui-shadcn-field-label>
Subdomain
</proto-ui-shadcn-field-label>
<proto-ui-shadcn-field-control
default-value="studio"
placeholder='Try "taken"'
></proto-ui-shadcn-field-control>
<proto-ui-shadcn-field-description>
Type "taken" to trigger an async availability error.
</proto-ui-shadcn-field-description>
<proto-ui-shadcn-field-error></proto-ui-shadcn-field-error>
</proto-ui-shadcn-field-root>
</div>
<script type="module">
const asyncField = document.querySelector('#field-async');
asyncField?.addEventListener('validationRequest', (event) => {
const { requestId, value } = event.detail;
setTimeout(() => {
const invalid = value === 'taken';
asyncField.getExposes().resolveValidation(requestId, {
invalid,
errors: invalid
? ['This subdomain is already reserved.']
: [],
});
}, 350);
});
</script>Root props
Section titled “Root props”Passing invalid enables controlled validity mode (invalid and errors have no default).
| Prop | Type | Default | Description |
|---|---|---|---|
orientation | 'vertical' 'horizontal' | vertical | Layout orientation for label and control |
styleProfile | ShadcnStyleId | nova | Optional Shadcn visual preset (or inherited from ShadcnStyleScope) |
invalid | boolean | — | Controlled invalid state |
errors | string[] | — | Controlled error messages |
defaultInvalid | boolean | false | Initial uncontrolled invalid state |
defaultErrors | string[] | [] | Initial uncontrolled error messages |
disabled | boolean | false | Disables the field and its control |
readOnly | boolean | false | Blocks edits while keeping focus and manual validation |
required | boolean | false | Marks the field as required |
minLength | number | -1 | Minimum UTF-16 length (-1 disables) |
maxLength | number | -1 | Maximum UTF-16 length (-1 disables) |
validationMode | 'onBlur' 'onChange' 'manual' | onBlur | When validation runs |
externalValidation | boolean | false | Emits validationRequest after built-in checks pass |
Other parts
Section titled “Other parts”- Control:
value/defaultValue,disabled,readOnly,required,placeholder,name,autoComplete,inputMode,enterKeyHint,ariaLabel,styleProfile(local flags cannot override an activeRootconstraint). - Bound controls:
fieldTextarea,fieldSelectTrigger,fieldSwitch,fieldCheckbox, andfieldRadioGroupinherit their control props and integrate with Field validation and ARIA wiring. - Label:
activation?: boolean(defaulttrue),styleProfile. - Description / Validity:
styleProfile. - Error:
message?: string(explicit localized override),keepMounted?: boolean(defaultfalse),styleProfile.
Methods and events (Root)
Section titled “Methods and events (Root)”- Methods:
validate(reason?),resolveValidation(requestId, result),cancelValidation(),resetValidation(),focusControl(options?),getValidity(). - Events:
validityChange(validation snapshot),validationRequest({ requestId, value, reason }).