Skip to content

Commit

Permalink
fix(Popover): links inside tooltips inside content are now clickable
Browse files Browse the repository at this point in the history
  • Loading branch information
DSil committed Dec 1, 2023
1 parent 0fd1642 commit b7114a6
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
35 changes: 35 additions & 0 deletions packages/orbit-components/src/Popover/__tests__/index.test.tsx
Expand Up @@ -107,4 +107,39 @@ describe("Popover", () => {
if (overlay) await user.click(overlay);
expect(screen.queryByTestId("dialog")).not.toBeInTheDocument();
});

it("should allow interacting with nested elements", async () => {
const nestedOnClick = jest.fn();
const contentOnClick = jest.fn();

render(
<Popover
content={
<>
<Tooltip
content={
<Button dataTest="nested-button" onClick={nestedOnClick}>
Nested button
</Button>
}
>
<span data-test="tooltip-trigger">Hover me</span>
</Tooltip>
<Button dataTest="content-button" onClick={contentOnClick}>
Content button
</Button>
</>
}
>
<Button dataTest="popover-trigger">Open popover</Button>
</Popover>,
);

await user.click(screen.getByTestId("popover-trigger"));
await user.click(screen.getByTestId("tooltip-trigger"));
await user.click(screen.getByTestId("nested-button"));
expect(nestedOnClick).toHaveBeenCalled();
await user.click(screen.getByTestId("content-button"));
expect(contentOnClick).toHaveBeenCalled();
});
});
Expand Up @@ -116,9 +116,13 @@ const PopoverContentWrapper = ({
};
}, [update, actions, setActionsHeight, onClose]);

useClickOutside(content, ev => {
if (isLargeMobile) onClose(ev);
});
useClickOutside(
content,
ev => {
if (isLargeMobile) onClose(ev);
},
"click",
);

const cssVars = {
"--popper-top": popper.top,
Expand Down
Expand Up @@ -5,7 +5,7 @@ import useEventListener from "../useEventListener";
const useClickOutside = <T extends HTMLElement>(
ref: React.RefObject<T>,
handler: (ev: MouseEvent) => void,
mouseEvent: "mousedown" | "mouseup" = "mousedown",
mouseEvent: "mousedown" | "mouseup" | "click" = "mousedown",
): void => {
useEventListener(mouseEvent, event => {
const el = ref?.current;
Expand Down

0 comments on commit b7114a6

Please sign in to comment.