Field Builder

Examples

Basic Field Builder

This is a basic field builder!

NameEmailActions

Field Builder Select

This is a field builder with Select components!

DepartmentRoleActions

Props

FieldBuilder

FieldBuilder is a component group that simplifies the creation of dynamic, multi-row forms with a consistent layout. It manages the layout and actions for adding and removing rows, while giving the consumer full control over the fields themselves.
*required
NameTypeDefaultDescription
childrenrequired(helpers: FieldRowHelpers, index: number) => React.ReactNodeA function that returns the content for each row. This "render prop" provides maximum flexibility for defining the inputs within each row. Can return 1 child (single-column) or 2 children (two-column). The second parameter provides the 0-based index of the current row.
firstColumnLabelrequiredReact.ReactNodeLabel for the first column
onAddRowrequired(event: React.MouseEvent) => voidA callback triggered when the "Add" button is clicked.
onRemoveRowrequired(event: React.MouseEvent, index: number) => voidA callback triggered when a "Remove" button is clicked, which receives the index of the row to remove.
rowCountrequirednumberThe total number of rows to render. This should be derived from the length of the state array managed by the parent.
addButtonContentReact.ReactNodeContent for the "Add" button. Defaults to "Add another".
addButtonPropsOmit<ButtonProps, 'onClick'>{}Additional props to customize the "Add" button.
aria-labelstringProvides an accessible name for the field builder table via a human readable string.
aria-labelledbystringProvides an accessible name for the field builder table via a space separated list of IDs.
fieldBuilderIdPrefixstring'field-builder'Unique ID prefix for this FieldBuilder instance. This ensures unique IDs when multiple FieldBuilders exist on the same page.
onAddRowAnnouncement(rowNumber: number, rowGroupLabelPrefix: string) => stringCallback to customize the announcement message when a row is added. If not provided, defaults to "New {rowGroupLabelPrefix} added. {rowGroupLabelPrefix} {newRowNumber}."
onRemoveRowAnnouncement(rowNumber: number, rowGroupLabelPrefix: string) => stringCallback to customize the announcement message when a row is removed. If not provided, defaults to "{rowGroupLabelPrefix} {removedRowNumber} removed."
removeButtonAriaLabel(rowNumber: number, rowGroupLabelPrefix: string) => stringCallback to customize the aria-label for remove buttons. If not provided, defaults to "Remove {rowGroupLabelPrefix} {rowNumber}".
removeButtonPropsOmit<ButtonProps, 'onClick' | 'ref'>{}Additional props to customize the "Remove" buttons.
rowGroupLabelPrefixstring'Row'Label prefix for each row group. Defaults to "Row". This is also used to create a default Table accessible name when the aria-label nor aria-labelledby are not provided.
secondColumnLabelReact.ReactNodeLabel for the second column in a two-column layout