Skip to content

Commit

Permalink
Wrap Tooltip content in <div> for non string content type (#17593)
Browse files Browse the repository at this point in the history
#### 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>`
  • Loading branch information
zhigzhen authored May 17, 2021
1 parent 8f35bc7 commit 644df65
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Wrap Tooltip content in div when type is not string",
"packageName": "@fluentui/react",
"email": "[email protected]",
"dependentChangeType": "patch"
}
6 changes: 5 additions & 1 deletion packages/react/src/components/Tooltip/Tooltip.base.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ export class TooltipBase extends React.Component<ITooltipProps, any> {
}

private _onRenderContent = (props: ITooltipProps): JSX.Element => {
return <p className={this._classNames.subText}>{props.content}</p>;
if (typeof props.content === 'string') {
return <p className={this._classNames.subText}>{props.content}</p>;
} else {
return <div className={this._classNames.subText}>{props.content}</div>;
}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ exports[`Tooltip renders default Tooltip correctly 1`] = `
<div
role="tooltip"
>
<p />
<div />
</div>
</div>
</div>
Expand Down

0 comments on commit 644df65

Please sign in to comment.