Skip to content

Commit 644df65

Browse files
authored
Wrap Tooltip content in <div> for non string content type (#17593)
#### Pull request checklist - [x] Addresses an existing issue: Fixes #17344 - [x] Include a change request file using $ yarn change #### Description of changes See the issue thread for more context. If a JSX object with a `<div>` other than a string is passed into the content field of a `TooltipHost` / `Tooltip`, the browser will complain with the following error: > Warning: validateDOMnesting(...): `<div>` cannot appear as a descendant of `<p>`... To deal with this error, we should only wrap the object in `<p>` if it is type string, otherwise we can wrap it in a `<div>`
1 parent 8f35bc7 commit 644df65

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "patch",
3+
"comment": "Wrap Tooltip content in div when type is not string",
4+
"packageName": "@fluentui/react",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}

packages/react/src/components/Tooltip/Tooltip.base.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ export class TooltipBase extends React.Component<ITooltipProps, any> {
6868
}
6969

7070
private _onRenderContent = (props: ITooltipProps): JSX.Element => {
71-
return <p className={this._classNames.subText}>{props.content}</p>;
71+
if (typeof props.content === 'string') {
72+
return <p className={this._classNames.subText}>{props.content}</p>;
73+
} else {
74+
return <div className={this._classNames.subText}>{props.content}</div>;
75+
}
7276
};
7377
}

packages/react/src/components/Tooltip/__snapshots__/Tooltip.test.tsx.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ exports[`Tooltip renders default Tooltip correctly 1`] = `
120120
<div
121121
role="tooltip"
122122
>
123-
<p />
123+
<div />
124124
</div>
125125
</div>
126126
</div>

0 commit comments

Comments
 (0)