Skip to content
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

disableBackdropClick #66

Closed
John0x opened this issue Nov 16, 2022 · 2 comments
Closed

disableBackdropClick #66

John0x opened this issue Nov 16, 2022 · 2 comments
Labels
question Further information is requested

Comments

@John0x
Copy link

John0x commented Nov 16, 2022

Hey, is there a way to disable the closing of an dialog, when clicked outside the dialog?
Unfortunately disableBackdropClick has been removed

@Quernest
Copy link
Owner

Hey, is there a way to disable the closing of an dialog, when clicked outside the dialog? Unfortunately disableBackdropClick has been removed

Hey, sure! It depends on the configuration of your Dialog so you can handle the closing events however you want. The @mui provides the reason for closing in the onClose callback.

const DialogWithoutBackdropClick: React.FC<DialogProps> = ({ onClose, ...otherProps }) => {
  const handleClose = (
    event: {},
    reason: 'backdropClick' | 'escapeKeyDown'
  ) => {
    // Backdrop click is blocked. Don't forget to make a workaround to close the Dialog :)
    if (reason !== 'backdropClick') {
      onClose?.(event, reason);
    }
  };

  return (
    <Dialog onClose={handleClose} {...otherProps}>
      <DialogTitle>Simple Dialog</DialogTitle>
    </Dialog>
  );
};

// Somewhere else
<Button
  variant="contained"
  onClick={() => showModal(DialogWithoutBackdropClick)}
  color="primary"
>
  Click to open
</Button>

@Quernest Quernest added the question Further information is requested label Nov 17, 2022
@John0x
Copy link
Author

John0x commented Nov 20, 2022

Perfect, thank you :)

@John0x John0x closed this as completed Nov 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants