Skip to content

RadioGroupField

RadioGroupField renders a group of PrimeReact RadioButton components from an options array, allowing the user to select a single value.

import { CommandDialog } from '@cratis/components/CommandDialog';
import { RadioGroupField } from '@cratis/components/CommandForm';
const sizeOptions = [
{ id: 'small', label: 'Small' },
{ id: 'medium', label: 'Medium' },
{ id: 'large', label: 'Large' },
];
<CommandDialog command={MyCommand} visible={visible} onCancel={() => setVisible(false)}>
<RadioGroupField<MyCommand>
value={c => c.size}
options={sizeOptions}
optionLabel="label"
optionValue="id"
title="Size"
/>
</CommandDialog>

With horizontal layout:

<RadioGroupField<MyCommand>
value={c => c.priority}
options={priorityOptions}
optionLabel="label"
optionValue="id"
title="Priority"
layout="horizontal"
/>
PropTypeDefaultDescription
value(instance: TCommand) => unknownRequired. Accessor function that returns the bound property from the command instance. Pass the command type as the generic parameter for full type safety.
optionsArray<Record<string, unknown>>Required. Array of option objects.
optionLabelstringRequired. Key in each option object to use as the display label.
optionValuestringRequired. Key in each option object to use as the submitted value.
layout'horizontal' | 'vertical''vertical'Controls whether the radio buttons are stacked vertically or laid out in a horizontal row.
  • Default value is an empty string.
  • A radio button is checked when the current field value equals its optionValue.
  • Validation state is reflected via the PrimeReact invalid flag on all radio buttons.