Skip to content

SelectField

A dropdown select field for choosing from a list of options.

PropTypeDescription
value(instance: TCommand) => unknownRequired. Accessor function returning the property value from the command instance.
titlestringThe label for the field.
optionsArray<{ [key: string]: unknown }>Required. Array of option objects.
optionIdFieldstringRequired. Name of the property to use as the option value.
optionLabelFieldstringRequired. Name of the property to display as the option label.
placeholderstringPlaceholder text shown for empty selection.
requiredbooleanOverride automatic required detection.
const countries = [
{ id: 'us', name: 'United States' },
{ id: 'uk', name: 'United Kingdom' },
{ id: 'ca', name: 'Canada' },
{ id: 'no', name: 'Norway' }
];
<SelectField<UserCommand>
value={c => c.country}
title="Country"
options={countries}
optionIdField="id"
optionLabelField="name"
placeholder="Select a country..."
/>

With custom data:

const roles = [
{ value: 'admin', display: 'Administrator' },
{ value: 'user', display: 'Standard User' },
{ value: 'guest', display: 'Guest' }
];
<SelectField<UserCommand>
value={c => c.role}
title="User Role"
options={roles}
optionIdField="value"
optionLabelField="display"
/>