Field
Field lays out a label, control, description and error as one form field. Use it for any labeled form control. For a group of related fields, wrap them in FieldSet or FieldGroup.
We never share it.
This example also needs: Input.
Installation
Run npx nxds-cli@latest init first if nxds isn’t set up in your app yet. See Install.
Usage
Composition
Examples
Orientations
Set orientation to vertical, horizontal or responsive, which follows the FieldGroup's width.
Shown on your public profile.
This example also needs: Checkbox.
Legend variants
Caption a FieldSet with a FieldLegend in the legend or smaller label size.
This example also needs: Checkbox.
With error
Set data-invalid on the Field and aria-invalid on the control, then link the FieldError with aria-errormessage.
Use a memorable passphrase.
With separator
Split alternative fields with a FieldSeparator that shows centered text.
Required and optional indicators
Mark a required field with FieldRequiredIndicator, or an optional one with its fallback text.
Disabled
Set data-disabled on the Field and disabled on the control to dim the label.
This field is locked.
Props
Field
| Prop | Type | Default | Description |
|---|---|---|---|
orientation | "horizontal" | "vertical" | "responsive" | null | "vertical" | No description |
FieldContent
FieldContent adds no props of its own; it accepts the props of the element or primitive it wraps.
FieldDescription
FieldDescription adds no props of its own; it accepts the props of the element or primitive it wraps.
FieldError
| Prop | Type | Default | Description |
|---|---|---|---|
errors | FieldErrors | No default documented | Validation errors to show. Duplicate messages show once, and several render as a list. Ignored when the error has content of its own. |
FieldGroup
FieldGroup adds no props of its own; it accepts the props of the element or primitive it wraps.
FieldLabel
FieldLabel adds no props of its own; it accepts the props of the element or primitive it wraps.
FieldLegend
| Prop | Type | Default | Description |
|---|---|---|---|
variant | "legend" | "label" | "legend" | Caption size. |
FieldRequiredIndicator
| Prop | Type | Default | Description |
|---|---|---|---|
fallback | ReactNode | No default documented | Text for an optional field, shown instead of the |
FieldSeparator
FieldSeparator adds no props of its own; it accepts the props of the element or primitive it wraps.
FieldSet
FieldSet adds no props of its own; it accepts the props of the element or primitive it wraps.
FieldTitle
FieldTitle adds no props of its own; it accepts the props of the element or primitive it wraps.
Field lays out a label, control, description and error as one form field. Use it for any labeled form control. For a group of related fields, wrap them in FieldSet or FieldGroup.
This example also needs: Input.
Installation
Install the following dependencies:
Copy and paste the following code into your project.
components/field/Field.vue components/field/FieldContent.vue components/field/FieldDescription.vue components/field/FieldError.vue components/field/FieldGroup.vue components/field/FieldLabel.vue components/field/FieldLegend.vue components/field/FieldRequiredIndicator.vue components/field/FieldSeparator.vue components/field/FieldSet.vue components/field/FieldTitle.vue components/field/index.ts lib/slots.ts Keep each file at the path shown above it.
Paths are relative to
packages/vue/src/. Keep the same folders under your@/root, and the imports between files work without edits.
Usage
Examples
Orientations
Set orientation to vertical, horizontal or responsive, which follows the FieldGroup's width.
This example also needs: Checkbox.
Legend variants
Caption a FieldSet with a FieldLegend in the legend or smaller label size.
This example also needs: Checkbox.
With error
Set data-invalid on the Field and aria-invalid on the control, then link the FieldError with aria-errormessage.
With separator
Split alternative fields with a FieldSeparator that shows centered text.
Required and optional indicators
Mark a required field with FieldRequiredIndicator, or an optional one with its #fallback text.
Disabled
Set data-disabled on the Field and disabled on the control to dim the label.
Props
Field
| Prop | Type | Default | Description |
|---|---|---|---|
orientation | "vertical" | "horizontal" | "responsive" | null | "vertical" | No description |
FieldContent
FieldContent adds no props of its own; it accepts the props of the element or primitive it wraps.
FieldDescription
FieldDescription adds no props of its own; it accepts the props of the element or primitive it wraps.
FieldError
| Prop | Type | Default | Description |
|---|---|---|---|
errors | FieldErrors | No default documented | Validation errors to show. Duplicate messages show once, and several render as a list. Ignored when the error has content of its own. |
FieldGroup
FieldGroup adds no props of its own; it accepts the props of the element or primitive it wraps.
FieldLabel
FieldLabel adds no props of its own; it accepts the props of the element or primitive it wraps.
FieldLegend
| Prop | Type | Default | Description |
|---|---|---|---|
variant | "label" | "legend" | "legend" | Caption size. |
FieldRequiredIndicator
FieldRequiredIndicator adds no props of its own; it accepts the props of the element or primitive it wraps.
FieldSeparator
FieldSeparator adds no props of its own; it accepts the props of the element or primitive it wraps.
FieldSet
FieldSet adds no props of its own; it accepts the props of the element or primitive it wraps.
FieldTitle
FieldTitle adds no props of its own; it accepts the props of the element or primitive it wraps.