Form input fields provide a structured format for capturing form data, such as text, dates, emails and other data types. Further customization of input fields can be achieved by providing a custom input component, such as an application-specific control.
Form fields should:
Form fields should not:
Allows users to provide short text input. Optionally, additional context can be given in the form of helper text to provide further instructional content.
Lets the user know that there is a problem with the provided input.
Whenever possible, validate the input after the user has finished their interaction with a field (but not before). If the user does not interact with the field before the form is submitted, the input should be validated on submission of the form. Error messages should be removed as early as possible, ideally as the user is typing, so that the user can see when an error has been addressed.
error
prop to provide a validation message to display to the user. The presence of a value indicates that the field is currently in an invalid state.touched
prop to indicate that the user has interacted with or has visited the field. This value is used to determine whether or not to show an error and helps to avoid overwhelming users with error messages for fields they have not interacted with.Note: Recipe doesn't maintain the value of touched
, and instead expects the touched
state to be managed within the application, typically via formik or another form validation library. For a complete example demonstrating these props in use, see the Cookbook: Complex form example.
Allows user to provide text input that may span more than one line. Optionally, a character count can be used to indicate the restrictions on the maximum length of an input. Use size
to specify how tall the field should be with the options: small
, medium
, large
.
Allows the user to provide numeric input values.
Allows the user to securely enter a password, typically as part of a login form.
Allows the user to input email values.
list
, maxLength
, minLength
, multiple
, pattern
, placeholder
, and readOnly
.Allows the user to choose between a larger set of options than would be appropriate for radio buttons. Use type="select"
to enable the user to pick from a dropdown list of available options.
type="select"
to enable the user to pick from a list of available options.options
to provide a array of objects with label
and value
properties for each option to present for selection. Optionally add description
if a label needs further detail.onSelectionChange
to identify the selected item. The onSelectionChange
callback is provided the value
of the selected option.Using onChange
for EzField[type=select]
is currently supported, but is deprecated in favor of onSelectionChange
.
Allows the user to choose from smaller lists of logically related options. Use a select list grouping to make the list of options easier to navigate to assist the user in finding the option they are looking for. The group
prop should be applied to each option that belongs to a group, and represents the label that wil be used to group the items.
Options are presented in the order in which they are grouped, and then by the order in which they are provided. To avoid options rendering options out of sequence, provide the options prop
a list pre-sorted by group.
Allows the user to filter longer lists of options to a set that match the text entered.
If you have fewer than 6 items, consider using radio buttons instead.
type="autosuggest"
to enable the user to pick from a filtered list of available options.onSelectionChange
to identify the selected item.onFilter
to react to user text input, in order to filter options to match. When updating the options list, it is strongly recommended that results are first sorted so that options are listed in the order in which the term appears earliest. For example, when searching "al", "Albany, New York" appears before "Tallahassee, Florida".When providing
Allows the user to pick a date from a popup calendar or enter their own date directly into the input field. Use type="date"
to enable the user to pick a date from a popup calendar.
Dates in this component are displayed with the format MM/DD/YYYY
.
Allows the user to pick a restricted range of available dates from a popup calendar or enter their own date directly into the input field.
While the minDate
and maxDate
options will prevent the selection of unavailable dates from the calendar, additional validation is required to prevent invalid values from being entered directly into the input.
type="date"
to enable the user to pick a date from a popup calendar.minDate={dateValue}
prop to disallow the selection of dates prior to dateValue
.maxDate={dateValue}
prop to disallow the selection of dates after dateValue
.Allows the user to pick from an arbitrary selection available dates from a popup calendar or enter their own date directly into the input field.
While the filterDate
option will prevent the selection of unavailable dates from the calendar, additional validation is required to prevent invalid values from being entered directly into the input.
type="date"
to enable the user to pick a date from a popup calendar.filterDate={fn}
prop to restrict the range of dates presented to only the set that are returned by the filter.The below example demonstrates using the filterDate
prop to restrict the calendar selection to only allow weekdays.
Programmatically clear the selection in a date input.
Allows the user to pick a time from a select dropdown. Use type="time"
to enable the user to pick a time from a select dropdown. An optional range can be used to limit the number of options in the select dropdown. Use start="9:00am"
to specify the start of the range, and end="5:00pm"
to specify the end of the range. An optional step can change the interval in which the times are generated. By default the step is 60
minutes. You can change it by adding step={15}
.
The steps that are supported are: 5
, 10
, 15
, 20
, 30
, 60
Optional Props:
displayAsNoon: <boolean>
: Replaces the "12:00 PM" label with "Noon"focusLabel: <string>
: Determines which option is guaranteed to be within view when the dropdown opensTimes in this component are displayed with the format h:mma, for example, 9:45am
.
Allows the usage of application-specific input components while still providing standard field behaviors, such as validation. The custom component will have props forwarded from EzField.
Visually hide the fields label when the fields purpose is clear from context.
This is alternative style of label for fields, reserved for fields where the intent of the field is otherwise clear from the context of the page, such as filter controls inside the page header or subheader.
This label style should be used to provide additional context in an understated way, as not to draw the focus away from the primary actions on the page.
helperText
.Provides the user with additional context hint about the expected input.
Show users that a field is not available for interaction. Often used where a form field is not available due to the current state of the form.
The Field component internally uses Array.prototype.findIndex()
and may require a polyfill to provide browser support depending on the specific requirements for your application. We recommend using Polyfill.io in your application to apply necessary polyfills only when they are needed for the requesting browser.