Skip to content

Commit 3bb4c67

Browse files
committed
fix: prevent duplicate checkbox description rendering across themes (#4742)
1 parent 3965c5a commit 3bb4c67

File tree

12 files changed

+78
-20
lines changed

12 files changed

+78
-20
lines changed

CHANGELOG.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,51 @@ it according to semantic versioning. For example, if your PR adds a breaking cha
1515
should change the heading of the (upcoming) version to include a major version bump.
1616
1717
-->
18+
# 6.0.2
19+
20+
## @rjsf/shadcn
21+
22+
- Updated `FieldTemplate` to skip label and description rendering for checkbox widgets, fixing ([#4742](https://github.com/rjsf-team/react-jsonschema-form/issues/4742))
23+
24+
## @rjsf/semantic-ui
25+
26+
- Updated `FieldTemplate` to skip label and description rendering for checkbox widgets, fixing ([#4742](https://github.com/rjsf-team/react-jsonschema-form/issues/4742))
27+
28+
## @rjsf/react-bootstrap
29+
30+
- Updated `FieldTemplate` to skip label and description rendering for checkbox widgets, fixing ([#4742](https://github.com/rjsf-team/react-jsonschema-form/issues/4742))
31+
32+
## @rjsf/primereact
33+
34+
- Updated `FieldTemplate` to skip label and description rendering for checkbox widgets, fixing ([#4742](https://github.com/rjsf-team/react-jsonschema-form/issues/4742))
35+
36+
## @rjsf/mui
37+
38+
- Updated `FieldTemplate` to skip label and description rendering for checkbox widgets, fixing ([#4742](https://github.com/rjsf-team/react-jsonschema-form/issues/4742))
39+
40+
## @rjsf/mantine
41+
42+
- Updated `CheckboxWidget` to handle label and description rendering consistently, fixing ([#4742](https://github.com/rjsf-team/react-jsonschema-form/issues/4742))
43+
44+
## @rjsf/fluentui-rc
45+
46+
- Updated `FieldTemplate` to skip label and description rendering for checkbox widgets, fixing ([#4742](https://github.com/rjsf-team/react-jsonschema-form/issues/4742))
47+
48+
## @rjsf/antd
49+
50+
- Updated `FieldTemplate` to skip label and description rendering for checkbox widgets, fixing ([#4742](https://github.com/rjsf-team/react-jsonschema-form/issues/4742))
51+
52+
53+
## @rjsf/chakra-ui
54+
55+
- Updated `CheckboxWidget` to handle label and description rendering consistently, fixing ([#4742](https://github.com/rjsf-team/react-jsonschema-form/issues/4742))
56+
57+
## @rjsf/core
58+
59+
- Fixed duplicate label and description rendering in `CheckboxWidget` by conditionally rendering them based on widget type
60+
- Updated `CheckboxWidget` to handle label and description rendering consistently
61+
- Modified `FieldTemplate` to skip label and description rendering for checkbox widgets, fixing ([#4742](https://github.com/rjsf-team/react-jsonschema-form/issues/4742))
62+
1863
# 6.0.1
1964

2065
## Dev / docs / playground

packages/antd/src/templates/FieldTemplate/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export default function FieldTemplate<
5656
} = formContext as GenericObjectType;
5757

5858
const uiOptions = getUiOptions<T, S, F>(uiSchema);
59+
5960
const WrapIfAdditionalTemplate = getTemplate<'WrapIfAdditionalTemplate', T, S, F>(
6061
'WrapIfAdditionalTemplate',
6162
registry,
@@ -79,7 +80,7 @@ export default function FieldTemplate<
7980
descriptionProps.extra = descriptionNode;
8081
break;
8182
}
82-
83+
const isCheckbox = uiOptions.widget === 'checkbox';
8384
return (
8485
<WrapIfAdditionalTemplate
8586
classNames={classNames}
@@ -101,7 +102,7 @@ export default function FieldTemplate<
101102
hasFeedback={schema.type !== 'array' && schema.type !== 'object'}
102103
help={(!!rawHelp && help) || (rawErrors?.length ? errors : undefined)}
103104
htmlFor={id}
104-
label={displayLabel && label}
105+
label={displayLabel && !isCheckbox && label}
105106
labelCol={labelCol}
106107
required={required}
107108
style={wrapperStyle}

packages/chakra-ui/src/CheckboxWidget/CheckboxWidget.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
StrictRJSFSchema,
1111
RJSFSchema,
1212
FormContextType,
13+
getUiOptions,
1314
} from '@rjsf/utils';
1415

1516
import { Field } from '../components/ui/field';
@@ -46,7 +47,9 @@ export default function CheckboxWidget<
4647
registry,
4748
options,
4849
);
49-
const description = options.description || schema.description;
50+
const uiOptions = getUiOptions(uiSchema);
51+
const isCheckbox = uiOptions.widget === 'checkbox';
52+
const description = isCheckbox ? undefined : (options.description ?? schema.description);
5053

5154
const _onChange = ({ checked }: CheckboxCheckedChangeDetails) => onChange(checked);
5255
const _onBlur = ({ target }: FocusEvent<HTMLInputElement | any>) => onBlur(id, target && target.checked);

packages/core/src/components/templates/FieldTemplate/FieldTemplate.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ export default function FieldTemplate<
2929
if (hidden) {
3030
return <div className='hidden'>{children}</div>;
3131
}
32+
const isCheckbox = uiOptions.widget === 'checkbox';
3233
return (
3334
<WrapIfAdditionalTemplate {...props}>
34-
{displayLabel && <Label label={label} required={required} id={id} />}
35+
{displayLabel && !isCheckbox && <Label label={label} required={required} id={id} />}
3536
{displayLabel && description ? description : null}
3637
{children}
3738
{errors}

packages/core/src/components/widgets/CheckboxWidget.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
RJSFSchema,
1010
StrictRJSFSchema,
1111
WidgetProps,
12+
getUiOptions,
1213
} from '@rjsf/utils';
1314

1415
/** The `CheckBoxWidget` is a widget for rendering boolean properties.
@@ -57,11 +58,13 @@ function CheckboxWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F exte
5758
(event: FocusEvent<HTMLInputElement>) => onFocus(id, event.target.checked),
5859
[onFocus, id],
5960
);
60-
const description = options.description ?? schema.description;
6161

62+
const uiOptions = getUiOptions(uiSchema);
63+
const isCheckboxWidget = uiOptions.widget === 'checkbox';
64+
const description = isCheckboxWidget ? undefined : (options.description ?? schema.description);
6265
return (
6366
<div className={`checkbox ${disabled || readonly ? 'disabled' : ''}`}>
64-
{!hideLabel && description && (
67+
{!hideLabel && description && !isCheckboxWidget && (
6568
<DescriptionFieldTemplate
6669
id={descriptionId(id)}
6770
description={description}

packages/fluentui-rc/src/FieldTemplate/FieldTemplate.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export default function FieldTemplate<
5151
if (hidden) {
5252
return <div style={{ display: 'none' }}>{children}</div>;
5353
}
54+
const isCheckbox = uiOptions.widget === 'checkbox';
5455
return (
5556
<WrapIfAdditionalTemplate
5657
classNames={classNames}
@@ -69,7 +70,7 @@ export default function FieldTemplate<
6970
>
7071
<Field validationState={rawErrors.length ? 'error' : undefined} required={required}>
7172
{children}
72-
{displayLabel && rawDescription ? (
73+
{displayLabel && rawDescription && !isCheckbox ? (
7374
<Text as='p' block style={{ marginTop: 0, marginBottom: 0 }}>
7475
{description}
7576
</Text>

packages/mantine/src/widgets/CheckboxWidget.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import {
1111
} from '@rjsf/utils';
1212
import { Checkbox } from '@mantine/core';
1313

14-
import { cleanupOptions } from '../utils';
15-
1614
/** The `CheckBoxWidget` is a widget for rendering boolean properties.
1715
* It is typically used to represent a boolean.
1816
*
@@ -44,8 +42,6 @@ export default function CheckboxWidget<
4442
uiSchema,
4543
} = props;
4644

47-
const themeProps = cleanupOptions(options);
48-
4945
const DescriptionFieldTemplate = getTemplate<'DescriptionFieldTemplate', T, S, F>(
5046
'DescriptionFieldTemplate',
5147
registry,
@@ -104,7 +100,6 @@ export default function CheckboxWidget<
104100
onFocus={handleFocus}
105101
error={rawErrors && rawErrors.length > 0 ? rawErrors.join('\n') : undefined}
106102
aria-describedby={ariaDescribedByIds(id)}
107-
{...themeProps}
108103
/>
109104
</>
110105
);

packages/mui/src/FieldTemplate/FieldTemplate.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ export default function FieldTemplate<
5252
if (hidden) {
5353
return <div style={{ display: 'none' }}>{children}</div>;
5454
}
55+
56+
const isCheckbox = uiOptions.widget === 'checkbox';
57+
5558
return (
5659
<WrapIfAdditionalTemplate
5760
classNames={classNames}
@@ -70,7 +73,7 @@ export default function FieldTemplate<
7073
>
7174
<FormControl fullWidth={true} error={rawErrors.length ? true : false} required={required}>
7275
{children}
73-
{displayLabel && rawDescription ? (
76+
{!isCheckbox && displayLabel && rawDescription ? (
7477
<Typography variant='caption' color='textSecondary'>
7578
{description}
7679
</Typography>

packages/primereact/src/FieldTemplate/FieldTemplate.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@ export default function FieldTemplate<
2626
return <div style={{ display: 'none' }}>{children}</div>;
2727
}
2828

29+
const isCheckbox = uiOptions.widget === 'checkbox';
2930
return (
3031
<WrapIfAdditionalTemplate {...props}>
3132
<div style={{ display: 'flex', flexDirection: 'column', gap: '0.5rem', marginBottom: '1rem' }}>
32-
{displayLabel && <Label id={props.id} text={props.label} required={props.required} />}
33+
{displayLabel && !isCheckbox && <Label id={props.id} text={props.label} required={props.required} />}
3334
{children}
34-
{displayLabel && rawDescription && <small>{description}</small>}
35+
{displayLabel && rawDescription && !isCheckbox && <small>{description}</small>}
3536
{errors}
3637
{help}
3738
</div>

packages/react-bootstrap/src/FieldTemplate/FieldTemplate.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ export default function FieldTemplate<
4444
if (hidden) {
4545
return <div className='hidden'>{children}</div>;
4646
}
47+
const isCheckbox = uiOptions.widget === 'checkbox';
48+
4749
return (
4850
<WrapIfAdditionalTemplate
4951
classNames={classNames}
@@ -61,14 +63,14 @@ export default function FieldTemplate<
6163
registry={registry}
6264
>
6365
<Form.Group>
64-
{displayLabel && (
66+
{displayLabel && !isCheckbox && (
6567
<Form.Label htmlFor={id} className={rawErrors.length > 0 ? 'text-danger' : ''}>
6668
{label}
6769
{required ? '*' : null}
6870
</Form.Label>
6971
)}
7072
{children}
71-
{displayLabel && rawDescription && (
73+
{displayLabel && rawDescription && !isCheckbox && (
7274
<Form.Text className={rawErrors.length > 0 ? 'text-danger' : 'text-muted'}>{description}</Form.Text>
7375
)}
7476
{errors}

0 commit comments

Comments
 (0)