-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
[material-ui][Dialog] Specifying onClick prop disables backdrop clicks #41417
Comments
I agree it's a bug. |
Where to call |
Would the following fix work: --- a/packages/mui-material/src/Dialog/Dialog.js
+++ b/packages/mui-material/src/Dialog/Dialog.js
@@ -182,6 +182,7 @@ const Dialog = React.forwardRef(function Dialog(inProps, ref) {
fullWidth = false,
maxWidth = 'sm',
onBackdropClick,
+ onClick,
onClose,
open,
PaperComponent = Paper,
@@ -211,6 +212,9 @@ const Dialog = React.forwardRef(function Dialog(inProps, ref) {
backdropClick.current = event.target === event.currentTarget;
};
const handleBackdropClick = (event) => {
+ if (onClick) {
+ onClick(event);
+ }
// Ignore the events not coming from the "backdrop".
if (!backdropClick.current) {
return; However, I believe there should be a distinction between clicking the dialog root and clicking the backdrop. |
I believe so! That's pretty much what I was thinking. You don't even need to reorder
I agree and if I understand the docs correctly, that's the use case that (now deprecated) |
Correct. Updated the above diff.
I mean why is the dialog root's |
Ah I see what you're saying. Good question. Not sure of the design decision there. Found the commit that put it there though. Would an alternative be to wire this up through the |
DialogRoot is a Styled Modal and the underlying Modal component has the Pop Up(Modal) and Backdrop component with it, By passing onClick to DialogRoot eventually to Backdrop, callback is fired back when Backdrop is clicked to close it. |
Steps to reproduce
Link to live example
Steps:
onClick
prop to theDialog
component.Current behavior
The dialog does not close upon clicking the backdrop if the
onClick
prop is provided by the consumer of the dialog.Expected behavior
The dialog should close when the backdrop is clicked, even if an
onClick
prop is provided to the dialog component.Context
onClick
prop can been used to stop propagation to parent components, as mentioned in this older issue.onClick
callback also "... breaks the behavior of the 'backdrop'". I want to make sure this gets addressed.onClick
prop for v5.onClick
callback here.onClick
prop, it gets overwritten by spreading{...others}
here.onClick
fromprops
.handleBackdropClick
here (if provided inprops
) instead of grouping it with...others
.Your environment
npx @mui/envinfo
Search keywords: dialog onClick backdrop
The text was updated successfully, but these errors were encountered: