Field
VField places a label, a hint and an error message around any control. Its slot provides fieldProps to bind on the control.
Usage
Examples
Native control
Native elements and third-party components take the same fieldProps as library controls.
Error
error shows a message in place of the hint, so the field does not grow, and marks the control invalid. The message is announced when it appears. required adds an asterisk and passes required to the control.
Label beside the control
labelPosition="start" places the label in its own column. In a narrow field, the label moves back above the control.
Hidden label
hideLabel hides the label visually. It still names the control for screen readers.
Group of elements
group names a group of elements, such as a row of fields with a group role. The label becomes plain text and fieldProps provides aria-labelledby instead of the states a group cannot carry.
Content beside the hint
The meta slot places content at the end of the hint line, such as a character counter. Bind the id it provides: it joins the control’s aria-describedby.
API
Props
| Prop | Type | Default |
|---|---|---|
label | string | none |
Label linked to the control through for. | ||
hint | string | none |
Help text below the control, linked through aria-describedby. | ||
error | string | none |
Error message shown in place of the hint. Sets aria-invalid, is linked through aria-describedby and is announced when it appears. | ||
required | boolean | false |
Adds an asterisk after the label and passes required to the control. | ||
disabled | boolean | false |
Greys out the label and the hint and passes disabled to the control. | ||
hideLabel | boolean | false |
| Hides the label visually while keeping it as the accessible name. | ||
labelPosition | FieldLabelPosition'top' | 'start' | 'top' |
| Places the label above the control or beside it. | ||
group | boolean | false |
Names a group of elements through aria-labelledby instead of for. | ||
Slots
| Slot | Type |
|---|---|
default | { fieldProps: FieldControlProps; } |
The control. Bind fieldProps: id, descriptions, invalid state, required, disabled and the attributes set on the field other than class and style. | |
meta | { id: string; } |
| Content at the end of the hint line, such as a character counter. | |
Types
Types used in the API tables. Import exported types from vectis-ui.
export type FieldControlProps = {
id: string
'aria-labelledby'?: string
'aria-describedby'?: string
'aria-invalid'?: 'true'
required?: true
disabled?: true
} & Record<string, unknown>CSS variables
| Token | Value |
|---|---|
--vectis-control-size-field-label | 10rem |
--vectis-control-size-field-control-min | 16rem |