Support HTML in checkbox-control tooltip (#42926)

* Support HTML in checkbox-control tooltip

* Add HTML support for tooltip in label
This commit is contained in:
Nathan Silveira 2023-12-19 14:44:42 -03:00 committed by GitHub
parent 3faedf24d9
commit 1cf4b20fdd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 2 deletions

View File

@ -0,0 +1,4 @@
Significance: minor
Type: add
Support HTML in checkbox-control tooltip and Label tooltip

View File

@ -8,6 +8,7 @@ import { Icon, help } from '@wordpress/icons';
/**
* Internal dependencies
*/
import { sanitizeHTML } from '../../utils/sanitize-html';
export type CheckboxProps = {
label: string;
@ -56,7 +57,13 @@ export const Checkbox: React.FC< CheckboxProps > = ( {
/>
{ tooltip && (
<Tooltip
text={ <span>{ tooltip }</span> }
text={
<span
dangerouslySetInnerHTML={ sanitizeHTML(
tooltip
) }
></span>
}
position="top center"
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore Incorrect types.

View File

@ -6,6 +6,11 @@ import { __ } from '@wordpress/i18n';
import { Icon, help as helpIcon } from '@wordpress/icons';
import { Tooltip } from '@wordpress/components';
/**
* Internal dependencies
*/
import { sanitizeHTML } from '../../utils/sanitize-html';
export interface LabelProps {
label: string;
required?: boolean;
@ -36,7 +41,11 @@ export const Label: React.FC< LabelProps > = ( {
{ tooltip && (
<Tooltip
text={ <span>{ tooltip }</span> }
text={
<span
dangerouslySetInnerHTML={ sanitizeHTML( tooltip ) }
></span>
}
position="top center"
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore Incorrect types.