Skip to content
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

Expose disabled in tooltip #13139

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/giant-mayflies-sniff.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/polaris': major
---

updated Tooltip component such that when content is null only children are rendered rather than tooltip itself
8 changes: 4 additions & 4 deletions polaris-react/src/components/Tooltip/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export type BorderRadius = Extract<BorderRadiusAliasOrScale, '100' | '200'>;
export interface TooltipProps {
/** The element that will activate to tooltip */
children?: React.ReactNode;
/** The content to display within the tooltip */
content: React.ReactNode;
/** The content to display within the tooltip. If null, the tooltip will not be rendered. */
content: React.ReactNode | null;
/** Toggle whether the tooltip is visible */
active?: boolean;
/** Delay in milliseconds while hovering over an element before the tooltip is visible */
Expand Down Expand Up @@ -174,7 +174,7 @@ export function Tooltip({
}
}, [originalActive, active, handleClose, handleBlur]);

const portal = activatorNode ? (
const tooltipPortal = activatorNode ? (
<Portal idPrefix="tooltip">
<TooltipOverlay
id={id}
Expand Down Expand Up @@ -224,7 +224,7 @@ export function Tooltip({
className={wrapperClassNames}
>
{children}
{portal}
{content !== null && tooltipPortal}
</WrapperComponent>
);

Expand Down
40 changes: 40 additions & 0 deletions polaris-react/src/components/Tooltip/tests/Tooltip.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,46 @@ describe('<Tooltip />', () => {
});
});
});

describe('tooltip when content is null', () => {
it('does not render tooltip when content is null', () => {
const tooltip = mountWithApp(
<Tooltip content={null}>
<Link>link content</Link>
</Tooltip>,
);

expect(tooltip).not.toContainReactComponent(TooltipOverlay);
expect(tooltip).toContainReactComponent(Link);
});

it('renders tooltip when content changes from null to a value', () => {
const tooltip = mountWithApp(
<Tooltip content={null}>
<Link>link content</Link>
</Tooltip>,
);

tooltip.setProps({content: 'New content'});
findWrapperComponent(tooltip)!.trigger('onMouseOver');

expect(tooltip).toContainReactComponent(TooltipOverlay);
});

it('removes tooltip when content changes to null', () => {
const tooltip = mountWithApp(
<Tooltip content="Initial content">
<Link>link content</Link>
</Tooltip>,
);

findWrapperComponent(tooltip)!.trigger('onMouseOver');
expect(tooltip).toContainReactComponent(TooltipOverlay);

tooltip.setProps({content: null});
expect(tooltip).not.toContainReactComponent(TooltipOverlay);
});
});
});

function findWrapperComponent(tooltip: any) {
Expand Down