Skip to content
Snippets Groups Projects
Unverified Commit cd68d42d authored by Romeo Van Snick's avatar Romeo Van Snick Committed by GitHub
Browse files

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

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

* Also stop event propagation for touch events on menu item
parent f340a3ae
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