Skip to content

Commit

Permalink
feat(FormRenderer): Render radio button description (#365)
Browse files Browse the repository at this point in the history
  • Loading branch information
abrenaut authored Sep 22, 2021
1 parent 801d4d8 commit aba7e19
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/components/FormRenderer/components/Radio/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ import { getErrorText } from '../../utils/getErrorText';
interface RadioButtonMappingProps {
option: Option;
name: string;
description?: string;
}

const RadioButtonMapping: FunctionComponent<RadioButtonMappingProps> = ({ option, name }) => {
const { input } = useFieldApi({ name, type: 'radio', value: option.value });
const RadioButtonMapping: FunctionComponent<RadioButtonMappingProps> = ({ option, name, description }) => {
const { input } = useFieldApi({ description, name, type: 'radio', value: option.value });
return (
<RadioButton {...input} value={option.value} name={name}>
<RadioButton {...input} value={option.value} name={name} description={description}>
{option.label}
</RadioButton>
);
Expand Down Expand Up @@ -61,7 +62,12 @@ const RadioGroupMapping: FunctionComponent<UseFieldApiConfig> = (props) => {
<RadioGroup
{...input}
items={options.map((option: Option) => (
<RadioButtonMapping option={option} name={input.name} key={option.value} />
<RadioButtonMapping
option={option}
name={input.name}
description={option.description}
key={option.value}
/>
))}
/>
</FormField>
Expand Down
1 change: 1 addition & 0 deletions src/components/FormRenderer/index.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ const baseSchema = {
options: [
{
label: 'Option 1',
description: 'Description 1',
value: '1',
},
{
Expand Down
2 changes: 2 additions & 0 deletions src/components/FormRenderer/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,7 @@ describe('FormRenderer', () => {
options: [
{
label: 'Option 1',
description: 'Description 1',
value: '1',
},
{
Expand Down Expand Up @@ -783,6 +784,7 @@ describe('FormRenderer', () => {

expect(getByText('Radio')).toBeVisible();
expect(getAllByRole('radio')).toHaveLength(3);
expect(getByText('Description 1')).toBeVisible();

fireEvent.click(getByLabelText('Option 3'));
fireEvent.click(getByText('Submit'));
Expand Down
1 change: 1 addition & 0 deletions src/components/FormRenderer/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { FormTemplateRenderProps } from '@data-driven-forms/react-form-renderer/
export interface Option {
label: string;
value: string;
description: string;
disabled?: boolean;
}

Expand Down

0 comments on commit aba7e19

Please sign in to comment.