Form provides components for building accessible and well-structured forms, including error messages, hints, and labels for form-related content.
This package includes reusable form components that help create consistent and accessible form experiences:
<daff-form-label>): Accessible labels for form controls<daff-hint>): Helpful information and validation hints<daff-error-message>): Validation error messages for form controlsThese components can be used independently or within a form field to organize and style form-related content consistently.
To use form, import DAFF_FORM_HELPER_COMPONENTS directly into your custom component:
import { DAFF_FORM_HELPER_COMPONENTS } from '@daffodil/design/form';
@Component({
selector: 'custom-component',
templateUrl: './custom-component.component.html',
imports: [
DAFF_FORM_HELPER_COMPONENTS,
],
})
export class CustomComponent {}
Labels help users understand what information to enter into a form control. Use <daff-form-label> to create accessible labels for form controls.
<daff-form-label>First Name</daff-form-label>
When used within a form field, the label is automatically associated with the form control for accessibility. If a form control is marked as required, an asterisk will be attached to the label to indicate that it's a required field.
<daff-form-field>
<daff-form-label>Email Address</daff-form-label>
<input daff-input type="email" name="email" required />
</daff-form-field>
Hints can be used to provide helpful information that assists users in correctly completing a field.
<daff-hint>Password must have 8 characters.</daff-hint>
Use the validated property to show hints with validation styling:
<daff-hint [validated]="isControlValid">Password must have 8 characters.</daff-hint>
Error messages can be used to display validation errors.
@if (control.errors?.required) {
<daff-error-message>Email is a required field.</daff-error-message>
}
These components include built-in accessibility features:
<daff-error-message> is set to aria-live="polite" by default so assistive technology only announce errors when they appearWhen used with a form field:
<daff-form-label> automatically associates with form controls<daff-hint> and <daff-error-message> are linked to form controls via aria-describedbyFor complete accessibility information and best practices, refer to the form field accessibility documentation.