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