AisField
AisField provides the structure around a form field. This includes the label, required marker, description, and error list.
Props
id
id specifies the enclosed input's unique id. By default, an id will be generated from the label attribute. For example, if the label is 'First Name', the field will generate an id of the form first-name-34f9. The value will be injected such that child components have access to it. Inspect the example below to see the id is set on the text input.
label
The label prop defines the field label, which is required for accessibility even if it is not visible on the screen.
labelMode
labelMode controls the display of the field's label. Valid options are:
normal- Visible to users and screen readers (default option).transparent- Visible to screen readers - holds space on the page.sr-only- Visible only to screen readers - does not occupy space on the page.
sr-only is useful for inline forms where no visible labels are used. transparent is useful when a field without a visible label is displayed alongside fields with labels. If you toggle between normal and transparent, you can see the form input doesn't change position.
required
Indicates the field is required. Visually indicated by an asterisk. When the user hovers over the label, a tooltip will be revealed labelling the field as required. Enclosed input will pick up the required designation.
size
Set the field size -- expected values are sm, md, lg. Field size can impact the size of the field's label and is provided to field's children.
- Something wrong
description
Set a brief description that appears below the form field. Description will be hidden if errors are present.
Username must be between 8 and 20 characters
errors
The errors prop will accept one or more strings or error objects. When passed objects, the errorMessage prop will be used to resolve the error message. If errors are present, the field's description will be hidden, and the error messages will display in red under the input element.
- Specify address in pig latin
- Do not wear white after Labor Day
- Tacos only available on Tuesday
errorMessage
When an error object or objects are passed to errors, errorMessage is used to convert the object into a display string. If errorMessage is a string, it represents a field in the object and the value of that field is used as the message. If errorMessage is a function, the error object is passed to the function and the return value is used as the message.
There is no default value for errorMessage. If no value is specified, the field will look for message, $message, and msg fields in the error object.
- Submit form in triplicate
- Where is the carbon paper?
- Burn after reading
- ROT13 is not secure
disabled
disabled is a boolean prop that will disable its enclosed form element and visually de-emphasize the field's display.
This is a disabled field.
Slots
AisField exposes four slots. The default slot is used all the time to specify the field's form input. The other slots can be used to override the label, description, and error presentation. It is not expected that these slots will be used very often.
default
The default slot typically accepts the form field definition and related content. The label and required props are passed to the slot. AisField will also inject some of its data to make it available to its descendents. The AIS form components know to look for this data and apply it to their own templates.
label
The label slot can be used to override the construction and presentation of the field's label. The label and required props are passed to the slot.
description
The description slot can be used to override the construction and presentation of the field's description. The description prop is passed to the slot.
errors
The errors slot can be used to override the construction and presentation of the field's errors. The errors prop is passed to the slot.
Field test
Explore AisField's interaction with different input types by exercising the example below.
Sic transit gloria mundi
Sic transit gloria mundi
Sic transit gloria mundi
Sic transit gloria mundi
Sic transit gloria mundi