Field
Associate an input with instructions and errors.
Examples
Associate an input with instructions and errors
Use a short, specific title.
Enter a title before continuing.
React code
import {
Field,
Label,
Input,
FieldDescription,
FieldError,
} from "@accelerate/react/components";
export function Example() {
return (
<>
<Field>
<Label htmlFor="field-title">Request title</Label>
<Input id="field-title" aria-describedby="title-help title-error" aria-invalid="true" />
<FieldDescription id="title-help">Use a short, specific title.</FieldDescription>
<FieldError id="title-error">Enter a title before continuing.</FieldError>
</Field>
</>
);
}Angular code
import { Component } from "@angular/core";
import {
AccField,
AccLabel,
AccInput,
AccFieldDescription,
AccFieldError,
} from "@accelerate/angular/components";
@Component({
selector: "app-example",
imports: [
AccField,
AccLabel,
AccInput,
AccFieldDescription,
AccFieldError,
],
template: `
<div accField>
<label accLabel for="field-title">Request title</label>
<input accInput id="field-title" aria-describedby="title-help title-error" aria-invalid="true">
<p accFieldDescription id="title-help">Use a short, specific title.</p>
<p accFieldError id="title-error">Enter a title before continuing.</p>
</div>
`,
})
export class Example {}Help without an error
Use a name reviewers will recognize.
React code
import { Field, Label, Input, FieldDescription } from "@accelerate/react/components";
export function Example() {
return (
<>
<Field>
<Label htmlFor="valid-name">Project name</Label>
<Input id="valid-name" aria-describedby="valid-name-help" />
<FieldDescription id="valid-name-help">Use a name reviewers will recognize.</FieldDescription>
</Field>
</>
);
}Angular code
import { Component } from "@angular/core";
import {
AccField,
AccLabel,
AccInput,
AccFieldDescription,
} from "@accelerate/angular/components";
@Component({
selector: "app-example",
imports: [
AccField,
AccLabel,
AccInput,
AccFieldDescription,
],
template: `
<div accField>
<label accLabel for="valid-name">Project name</label>
<input accInput id="valid-name" aria-describedby="valid-name-help">
<p accFieldDescription id="valid-name-help">Use a name reviewers will recognize.</p>
</div>
`,
})
export class Example {}Installation
Source preview. The expanded component catalog is ahead of the public npm releases. To run these examples in your own application, use packages built from the SDK source used for the previews or a release that includes the APIs below.
- React
@accelerate/ui@0.4.0and@accelerate/react@0.4.0- Angular
@accelerate/ui@0.4.0and@accelerate/angular@0.2.0
Load @accelerate/ui/theme.css and put acc-theme on the app or the region using Accelerator components. See the framework setup guide for the theme and adapter conventions.
Usage
Compose Label, control, FieldDescription and FieldError. Associate help and error IDs with the control. FormField remains available for its existing high-level API.
Import the React component Field from @accelerate/react/components. For Angular, add AccField to the standalone component’s imports and use <div accField>.
Examples use these React parts: Field, Label, Input, FieldDescription, FieldError. The Angular examples show the corresponding directives and template hosts.
API reference
- for / id
- Connect the input and label.
- aria-describedby
- References help and error IDs.
- aria-invalid
- Set on the control only when its value is invalid.