-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Markdown in descriptions #4405
base: main
Are you sure you want to change the base?
Markdown in descriptions #4405
Conversation
When 'enableMarkdownInDescription' flag is set to true markdown will be rendered in the description
When 'enableMarkdownInDescription' flag is set to true markdown will be rendered in the description
Updated to the proper release
Fixed Type
const richDescription = uiOptions.enableMarkdownInDescription ? ( | ||
<Markdown options={{ disableParsingRawHTML: true }}>{description || ''}</Markdown> | ||
) : ( | ||
description || '' | ||
); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dejanbelusic after looking around it turns out that every theme's CheckboxWidget
has a similar description rendering logic in it. We suggest creating a new component in the @rjsf/utils
package that wraps this logic as follows and then updating every FieldDescriptionTemplate
to use it:
export interface RichDescriptionProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> {
/** The description of the field being rendered */
description: ReactNode;
/** The uiSchema that was passed to field */
uiSchema?: UiSchema<T, S, F>;
/** The `registry` object */
registry: Registry<T, S, F>;
}
export default function RichDescription<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>({ description, registry, uiSchema = {}}: RichDescriptionProps<T,S,F>) {
const { globalUiOptions } = registry;
const uiOptions = getUiOptions<T, S, F>(uiSchema, globalUiOptions);
if (uiOptions.enableMarkdownInDescription) {
return <Markdown options={{ disableParsingRawHTML: true }}>{description || ''}</Markdown>
}
return description;
}
With all the FieldDescriptionTemplates
calling it similarly to the change that would be made in @rjsf/core
's implementation:
export default function DescriptionField<
T = any,
S extends StrictRJSFSchema = RJSFSchema,
F extends FormContextType = any
>(props: DescriptionFieldProps<T, S, F>) {
const { id, description, uiSchema, registry } = props;
if (!description) {
return null;
}
return (
<div id={id} className='field-description'>
<RichDescription<T,S,F> description={description} uiSchema={uiSchema} registry={registry} />
</div>
);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @heath-freenome, I see your point and I agree. I can create a new component RichDescription
as suggested, place it in the @rjsf/utils
, and then use it in every DescriptionField
component.
When looking into DescriptionField
components, I can see that one in @rjsf/antd
packages is wrapped in a span
, the one in @rjsf/bootstrap-4
is wrapped in two div
s, the one in @rjsf/chakra-ui
package is wrapped in Text
component... What I'm saying is every theme has similar, but different implementation. Do I leave them as is?
Update the feature to render markdown in the field description.
In the fields of type
object
and typeboolean
, markdown will be rendered in the description whenenableMarkdownInDescription
is set totrue
.Issue reporting this bug: #3975
Previous PR to add the feature: #3665
The result:
Checklist
npx nx run-many --target=build --exclude=@rjsf/docs && npm run test:update
to update snapshots, if needed.