Skip to content

[ BUG ] Clicking outside the Dialog modal on mobile web doesn't close dialog #338

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
ferntheplant opened this issue Feb 5, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@ferntheplant
Copy link

Describe the bug
Clicking outside the Dialog modal on mobile web doesn't close dialog

To Reproduce
Go to the showcase and set your screen size to iPhone 14 Pro Max. Open the "edit profie" dialong and try to close it by clicking outside the modal

Expected behavior
Clicking outside the modal should close it - see shadcn on the same mobile sized screen

Platform (please complete the following information):

  • Type: desktop
  • OS: MacOS
  • Browser Chrome, Firefox
@ferntheplant ferntheplant added the bug Something isn't working label Feb 5, 2025
@muneer-abdulsattar
Copy link

muneer-abdulsattar commented Apr 24, 2025

this is correct and it's annoying i kept trying stuff but for now i will be using this approache

const DialogOverlayWeb = React.forwardRef<
	React.ElementRef<typeof DialogPrimitive.Overlay>,
	React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay>
>(({ className, ...props }, ref) => {
	const { open, onOpenChange } = DialogPrimitive.useRootContext();

	// Function to handle press events on the overlay
	const handlePress = (event: GestureResponderEvent) => {
		// Get the target element from the event
		const target = event.target;
		const currentTarget = event.currentTarget;

		// If target === currentTarget, the press was directly on the overlay
		// If they're different, the press was on a child element
		if (target === currentTarget) {
			// Close the dialog
			onOpenChange(false);
		}
	};

	return (
		<DialogPrimitive.Overlay
			style={StyleSheet.absoluteFill}
			className={cn(
				"z-50 bg-black/80 flex justify-center items-center p-2",
				open
					? "web:animate-in web:fade-in-0"
					: "web:animate-out web:fade-out-0",
				className,
			)}
			{...props}
			ref={ref}
			onPress={handlePress}
		/>
	);
});

hopefully they fix it same thing happens with select but the select has been solved but can't use the same solution for the dialog dialog

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants