Skip to content

Commit

Permalink
[Tooltip] Add undefined, null or false in title (mui#34289)
Browse files Browse the repository at this point in the history
  • Loading branch information
abhinav-22-tech authored and alexfauquette committed Oct 14, 2022
1 parent 2d92961 commit 2d7b909
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 9 deletions.
2 changes: 1 addition & 1 deletion docs/pages/material-ui/api/tooltip.json
@@ -1,7 +1,6 @@
{
"props": {
"children": { "type": { "name": "custom", "description": "element" }, "required": true },
"title": { "type": { "name": "node" }, "required": true },
"arrow": { "type": { "name": "bool" } },
"classes": { "type": { "name": "object" } },
"components": {
Expand Down Expand Up @@ -48,6 +47,7 @@
"description": "Array&lt;func<br>&#124;&nbsp;object<br>&#124;&nbsp;bool&gt;<br>&#124;&nbsp;func<br>&#124;&nbsp;object"
}
},
"title": { "type": { "name": "node" } },
"TransitionComponent": { "type": { "name": "elementType" }, "default": "Grow" },
"TransitionProps": { "type": { "name": "object" } }
},
Expand Down
2 changes: 1 addition & 1 deletion docs/translations/api-docs/tooltip/tooltip-pt.json
Expand Up @@ -25,7 +25,7 @@
"PopperComponent": "The component used for the popper.",
"PopperProps": "Props applied to the <a href=\"/material-ui/api/popper/\"><code>Popper</code></a> element.",
"sx": "The system prop that allows defining system overrides as well as additional CSS styles. See the <a href=\"/system/getting-started/the-sx-prop/\">`sx` page</a> for more details.",
"title": "Tooltip title. Zero-length titles string are never displayed.",
"title": "Tooltip title. Zero-length titles string, undefined, null and false are never displayed.",
"TransitionComponent": "The component used for the transition. <a href=\"/material-ui/transitions/#transitioncomponent-prop\">Follow this guide</a> to learn more about the requirements for this component.",
"TransitionProps": "Props applied to the transition element. By default, the element is based on this <a href=\"http://reactcommunity.org/react-transition-group/transition/\"><code>Transition</code></a> component."
},
Expand Down
2 changes: 1 addition & 1 deletion docs/translations/api-docs/tooltip/tooltip-zh.json
Expand Up @@ -25,7 +25,7 @@
"PopperComponent": "The component used for the popper.",
"PopperProps": "Props applied to the <a href=\"/material-ui/api/popper/\"><code>Popper</code></a> element.",
"sx": "The system prop that allows defining system overrides as well as additional CSS styles. See the <a href=\"/system/getting-started/the-sx-prop/\">`sx` page</a> for more details.",
"title": "Tooltip title. Zero-length titles string are never displayed.",
"title": "Tooltip title. Zero-length titles string, undefined, null and false are never displayed.",
"TransitionComponent": "The component used for the transition. <a href=\"/material-ui/transitions/#transitioncomponent-prop\">Follow this guide</a> to learn more about the requirements for this component.",
"TransitionProps": "Props applied to the transition element. By default, the element is based on this <a href=\"http://reactcommunity.org/react-transition-group/transition/\"><code>Transition</code></a> component."
},
Expand Down
2 changes: 1 addition & 1 deletion docs/translations/api-docs/tooltip/tooltip.json
Expand Up @@ -25,7 +25,7 @@
"PopperComponent": "The component used for the popper.",
"PopperProps": "Props applied to the <a href=\"/material-ui/api/popper/\"><code>Popper</code></a> element.",
"sx": "The system prop that allows defining system overrides as well as additional CSS styles. See the <a href=\"/system/getting-started/the-sx-prop/\">`sx` page</a> for more details.",
"title": "Tooltip title. Zero-length titles string are never displayed.",
"title": "Tooltip title. Zero-length titles string, undefined, null and false are never displayed.",
"TransitionComponent": "The component used for the transition. <a href=\"/material-ui/transitions/#transitioncomponent-prop\">Follow this guide</a> to learn more about the requirements for this component.",
"TransitionProps": "Props applied to the transition element. By default, the element is based on this <a href=\"http://reactcommunity.org/react-transition-group/transition/\"><code>Transition</code></a> component."
},
Expand Down
4 changes: 2 additions & 2 deletions packages/mui-material/src/Tooltip/Tooltip.d.ts
Expand Up @@ -160,9 +160,9 @@ export interface TooltipProps extends StandardProps<React.HTMLAttributes<HTMLDiv
*/
sx?: SxProps<Theme>;
/**
* Tooltip title. Zero-length titles string are never displayed.
* Tooltip title. Zero-length titles string, undefined, null and false are never displayed.
*/
title: NonNullable<React.ReactNode>;
title: React.ReactNode;
/**
* The component used for the transition.
* [Follow this guide](/material-ui/transitions/#transitioncomponent-prop) to learn more about the requirements for this component.
Expand Down
6 changes: 3 additions & 3 deletions packages/mui-material/src/Tooltip/Tooltip.js
Expand Up @@ -498,7 +498,7 @@ const Tooltip = React.forwardRef(function Tooltip(inProps, ref) {
const handleRef = useForkRef(children.ref, handleFocusRef);

// There is no point in displaying an empty tooltip.
if (title === '') {
if (typeof title !== 'number' && !title) {
open = false;
}

Expand Down Expand Up @@ -872,9 +872,9 @@ Tooltip.propTypes /* remove-proptypes */ = {
PropTypes.object,
]),
/**
* Tooltip title. Zero-length titles string are never displayed.
* Tooltip title. Zero-length titles string, undefined, null and false are never displayed.
*/
title: PropTypes /* @typescript-to-proptypes-ignore */.node.isRequired,
title: PropTypes.node,
/**
* The component used for the transition.
* [Follow this guide](/material-ui/transitions/#transitioncomponent-prop) to learn more about the requirements for this component.
Expand Down
33 changes: 33 additions & 0 deletions packages/mui-material/src/Tooltip/Tooltip.test.js
Expand Up @@ -89,6 +89,39 @@ describe('<Tooltip />', () => {
expect(queryByRole('tooltip')).to.equal(null);
});

it('should not display if the title is a false', () => {
const { queryByRole } = render(
<Tooltip title={false} open>
<button id="testChild" type="submit">
Hello World
</button>
</Tooltip>,
);
expect(queryByRole('tooltip')).to.equal(null);
});

it('should not display if the title is a null', () => {
const { queryByRole } = render(
<Tooltip title={null} open>
<button id="testChild" type="submit">
Hello World
</button>
</Tooltip>,
);
expect(queryByRole('tooltip')).to.equal(null);
});

it('should not display if the title is an undefined', () => {
const { queryByRole } = render(
<Tooltip title={undefined} open>
<button id="testChild" type="submit">
Hello World
</button>
</Tooltip>,
);
expect(queryByRole('tooltip')).to.equal(null);
});

it('should label the child when closed', () => {
render(
<Tooltip title="the title">
Expand Down

0 comments on commit 2d7b909

Please sign in to comment.