Skip to content

Commit

Permalink
Revert Tooltip updates to close on child enter/space key interactions (
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronccasanova committed Mar 28, 2024
1 parent eda60b0 commit 0c26884
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 83 deletions.
2 changes: 1 addition & 1 deletion .changeset/flat-eagles-press.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
'@shopify/polaris': minor
---

Added `useCopyToClipboard` hook for building copy actions matching common actions guidelines. Updated `Tooltip` to dismiss on child enter/space key interactions.
Added `useCopyToClipboard` hook for building copy actions matching common actions guidelines
1 change: 1 addition & 0 deletions polaris-react/src/components/Button/Button.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,7 @@ export function CopyToClipboard() {
hoverDelay={500}
preferredPosition="above"
content="Copy"
active={status === 'copied' ? false : undefined}
>
<Button
variant="tertiary"
Expand Down
18 changes: 4 additions & 14 deletions polaris-react/src/components/Tooltip/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,10 @@ export function Tooltip({

const handleKeyUp = useCallback(
(event: React.KeyboardEvent) => {
const isChildInteraction =
event.target !== activatorContainer.current &&
(event.key === 'Enter' || event.key === ' ');

if (event.key === 'Escape' || isChildInteraction) {
handleClose?.();
handleBlur();
persistOnClick && togglePersisting();
}
if (event.key !== 'Escape') return;
handleClose?.();
handleBlur();
persistOnClick && togglePersisting();
},
[handleBlur, handleClose, persistOnClick, togglePersisting],
);
Expand Down Expand Up @@ -214,11 +209,6 @@ export function Tooltip({
handleFocus();
}}
onBlur={() => {
if (hoverDelayTimeout.current) {
clearTimeout(hoverDelayTimeout.current);
hoverDelayTimeout.current = null;
}

handleClose();
handleBlur();

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

it('does not close when enter is pressed on keyup of the activatorContainer', () => {
const tooltip = mountWithApp(
<Tooltip active content="This order has shipping labels.">
<div>Order #1001</div>
</Tooltip>,
);

findWrapperComponent(tooltip)!.trigger('onKeyUp', {
target: tooltip.domNode,
key: 'Enter',
});

expect(tooltip).toContainReactComponent(TooltipOverlay, {
active: true,
});
});

it('does not close when space is pressed on keyup of the activatorContainer', () => {
const tooltip = mountWithApp(
<Tooltip active content="This order has shipping labels.">
<div>Order #1001</div>
</Tooltip>,
);

findWrapperComponent(tooltip)!.trigger('onKeyUp', {
target: tooltip.domNode,
key: ' ',
});

expect(tooltip).toContainReactComponent(TooltipOverlay, {
active: true,
});
});

it('closes itself when enter is pressed on keyup of child elements', () => {
const tooltip = mountWithApp(
<Tooltip active content="This order has shipping labels.">
<button>Order #1001</button>
</Tooltip>,
);

findWrapperComponent(tooltip)!.trigger('onKeyUp', {
target: tooltip.find('button')!.domNode,
key: 'Enter',
});

expect(tooltip).toContainReactComponent(TooltipOverlay, {
active: false,
});
});

it('closes itself when space is pressed on keyup of child elements', () => {
const tooltip = mountWithApp(
<Tooltip active content="This order has shipping labels.">
<button>Order #1001</button>
</Tooltip>,
);

findWrapperComponent(tooltip)!.trigger('onKeyUp', {
target: tooltip.find('button')!.domNode,
key: ' ',
});

expect(tooltip).toContainReactComponent(TooltipOverlay, {
active: false,
});
});

it('does not call onOpen when initially activated', () => {
const openSpy = jest.fn();
const tooltip = mountWithApp(
Expand Down

0 comments on commit 0c26884

Please sign in to comment.