Skip to content
Snippets Groups Projects
Unverified Commit 58663c0a authored by github-automation-metabase's avatar github-automation-metabase Committed by GitHub
Browse files

Handle touch start capture as well as mouse down for popover (#49465) (#49736)


* Handle touch start capture as well as mouse down for popover

* Also stop event propagation for touch events on menu item

Co-authored-by: default avatarRomeo Van Snick <romeo@romeovansnick.be>
parent b53b62b0
No related branches found
No related tags found
No related merge requests found
import type { MenuItemProps as MantineMenuItemProps } from "@mantine/core";
import { Menu } from "@mantine/core";
import type { ButtonHTMLAttributes, MouseEvent } from "react";
import type { ButtonHTMLAttributes, MouseEvent, TouchEvent } from "react";
type MenuItemProps = MantineMenuItemProps &
ButtonHTMLAttributes<HTMLButtonElement>;
......@@ -11,6 +11,15 @@ export function MenuItem(props: MenuItemProps) {
const handleMouseDownCapture = (event: MouseEvent) => {
event.nativeEvent.stopImmediatePropagation();
};
const handleTouchStartCapture = (event: TouchEvent) => {
event.nativeEvent.stopImmediatePropagation();
};
return <Menu.Item {...props} onMouseDownCapture={handleMouseDownCapture} />;
return (
<Menu.Item
{...props}
onMouseDownCapture={handleMouseDownCapture}
onTouchStartCapture={handleTouchStartCapture}
/>
);
}
......@@ -30,6 +30,12 @@ export const getPopoverOverrides = (): MantineThemeOverride["components"] => ({
const target = event.target as HTMLElement;
target.setAttribute("data-ignore-outside-clicks", "true");
},
onTouchStartCapture: (event: SyntheticEvent) => {
// prevent nested popovers from closing each other
// see useClickOutside in @mantine/hooks for the reference
const target = event.target as HTMLElement;
target.setAttribute("data-ignore-outside-clicks", "true");
},
},
},
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment