Skip to content

Commit e7391fd

Browse files
committed
added the ui:enableMarkdownInHelp flag in UiSchema
1 parent bdc063b commit e7391fd

File tree

18 files changed

+7392
-498
lines changed

18 files changed

+7392
-498
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,47 +26,61 @@ should change the heading of the (upcoming) version to include a major version b
2626

2727
- Modified `CheckboxesWidget` to render the Title, fixing ([#4840](https://github.com/rjsf-team/react-jsonschema-form/issues/4840))
2828
- Updated `CheckboxWidget` to handle label and description rendering consistently, fixing ([#4742](https://github.com/rjsf-team/react-jsonschema-form/issues/4742))
29+
- Updated `FieldHelpTemplate` to render markdown when `ui:enableMarkdownInHelp` is true
2930

3031
## @rjsf/core
3132

3233
- Fixed duplicate label and description rendering in `CheckboxWidget` by conditionally rendering them based on widget type
3334
- Updated `CheckboxWidget` to handle label and description rendering consistently
3435
- Modified `FieldTemplate` to skip label and description rendering for checkbox widgets, fixing ([#4742](https://github.com/rjsf-team/react-jsonschema-form/issues/4742))
3536
- Updated `ObjectField` to change the removal of an additional property to defer the work to the `processPendingChange()` handler in `Form`, fixing [#4850](https://github.com/rjsf-team/react-jsonschema-form/issues/4850)
37+
- Added support for rendering `ui:help` as markdown via new `ui:enableMarkdownInHelp` flag in `FieldHelpTemplate`
3638

3739
## @rjsf/fluentui-rc
3840

3941
- Updated `FieldTemplate` to skip label and description rendering for checkbox widgets, fixing ([#4742](https://github.com/rjsf-team/react-jsonschema-form/issues/4742))
42+
- Updated `FieldHelpTemplate` to render markdown when `ui:enableMarkdownInHelp` is true
43+
44+
## @rjsf/daisyui
45+
46+
- Updated `FieldHelpTemplate` to render markdown when `ui:enableMarkdownInHelp` is true
4047

4148
## @rjsf/mantine
4249

4350
- Updated `CheckboxWidget` to handle label and description rendering consistently, fixing ([#4742](https://github.com/rjsf-team/react-jsonschema-form/issues/4742))
51+
- Updated `FieldHelpTemplate` to render markdown when `ui:enableMarkdownInHelp` is true
4452

4553
## @rjsf/mui
4654

4755
- Updated `FieldTemplate` to skip label and description rendering for checkbox widgets, fixing ([#4742](https://github.com/rjsf-team/react-jsonschema-form/issues/4742))
56+
- Updated `FieldHelpTemplate` to render markdown when `ui:enableMarkdownInHelp` is true
4857

4958
## @rjsf/primereact
5059

5160
- Updated `FieldTemplate` to skip label and description rendering for checkbox widgets, fixing ([#4742](https://github.com/rjsf-team/react-jsonschema-form/issues/4742))
61+
- Updated `FieldHelpTemplate` to render markdown when `ui:enableMarkdownInHelp` is true
5262

5363
## @rjsf/react-bootstrap
5464

5565
- Updated `FieldTemplate` to skip label and description rendering for checkbox widgets, fixing ([#4742](https://github.com/rjsf-team/react-jsonschema-form/issues/4742))
66+
- Updated `FieldHelpTemplate` to render markdown when `ui:enableMarkdownInHelp` is true
5667

5768
## @rjsf/semantic-ui
5869

5970
- Updated `FieldTemplate` to skip label and description rendering for checkbox widgets, fixing ([#4742](https://github.com/rjsf-team/react-jsonschema-form/issues/4742))
71+
- Updated `FieldHelpTemplate` to render markdown when `ui:enableMarkdownInHelp` is true
6072

6173
## @rjsf/shadcn
6274

6375
- Updated `FieldTemplate` to skip label and description rendering for checkbox widgets, fixing ([#4742](https://github.com/rjsf-team/react-jsonschema-form/issues/4742))
6476
- Updated the `Command` component to properly handle `forwardRef`
77+
- Updated `FieldHelpTemplate` to render markdown when `ui:enableMarkdownInHelp` is true
6578

6679
## @rjsf/utils
6780

6881
- Updated `getDefaultFormState()` to not save an undefined field value into an object when the type is `null` and `excludeObjectChildren` is provided, fixing [#4821](https://github.com/rjsf-team/react-jsonschema-form/issues/4821)
6982
- Added new `ADDITIONAL_PROPERTY_KEY_REMOVE` constant
83+
- Added new global UI option `enableMarkdownInHelp` to control markdown rendering of `ui:help`
7084

7185
## Dev / docs / playground
7286

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export default function FieldTemplate<
3939
onRemoveProperty,
4040
rawErrors,
4141
rawDescription,
42-
rawHelp,
42+
// rawHelp,
4343
readonly,
4444
registry,
4545
required,
@@ -100,7 +100,7 @@ export default function FieldTemplate<
100100
<Form.Item
101101
colon={colon}
102102
hasFeedback={schema.type !== 'array' && schema.type !== 'object'}
103-
help={(!!rawHelp && help) || (rawErrors?.length ? errors : undefined)}
103+
help={help || (rawErrors?.length ? errors : undefined)}
104104
htmlFor={id}
105105
label={displayLabel && !isCheckbox && label}
106106
labelCol={labelCol}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { helpId, FieldHelpProps, FormContextType, RJSFSchema, StrictRJSFSchema, getUiOptions } from '@rjsf/utils';
2+
import Markdown from 'markdown-to-jsx';
3+
4+
/** The `FieldHelpTemplate` component renders any help desired for a field
5+
*
6+
* @param props - The `FieldHelpProps` to be rendered
7+
*/
8+
export default function FieldHelpTemplate<
9+
T = any,
10+
S extends StrictRJSFSchema = RJSFSchema,
11+
F extends FormContextType = any,
12+
>(props: FieldHelpProps<T, S, F>) {
13+
const { fieldPathId, help, uiSchema = {}, registry } = props;
14+
if (!help) {
15+
return null;
16+
}
17+
const id = helpId(fieldPathId);
18+
const uiOptions = getUiOptions<T, S, F>(uiSchema, registry?.globalUiOptions);
19+
if (typeof help === 'string' && uiOptions.enableMarkdownInHelp) {
20+
return (
21+
<div id={id} className='help-block'>
22+
<Markdown options={{ disableParsingRawHTML: true }}>{help}</Markdown>
23+
</div>
24+
);
25+
}
26+
if (typeof help === 'string') {
27+
return (
28+
<p id={id} className='help-block'>
29+
{help}
30+
</p>
31+
);
32+
}
33+
return (
34+
<div id={id} className='help-block'>
35+
{help}
36+
</div>
37+
);
38+
}

0 commit comments

Comments
 (0)