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

Nested dialog bug #36

Closed
sm2017 opened this issue Jun 23, 2021 · 1 comment · Fixed by #38
Closed

Nested dialog bug #36

sm2017 opened this issue Jun 23, 2021 · 1 comment · Fixed by #38
Assignees
Labels
bug Something isn't working

Comments

@sm2017
Copy link

sm2017 commented Jun 23, 2021

I upgraded mui-modal-provider from 1.3.2 to latest version
If you run the following code, you can see it works well on version 1.3.2 but we have error on latest version

If you clock on Simple dialog twice you can see

Cannot read property 'props' of undefined

import React from "react";
import ModalProvider, { useModal } from "mui-modal-provider";
import Dialog from "@material-ui/core/Dialog";
import DialogTitle from "@material-ui/core/DialogTitle";
import Button from "@material-ui/core/Button";

// ✔️ create the dialog you want to use
const SimpleDialog = ({ title, ...props }) => (
  <Dialog {...props}>
    <DialogTitle>{title}</DialogTitle>
  </Dialog>
);

const Test = ({ onClick, title = "Simple dialog" }) => {
  const { showModal, hideModal } = useModal();

  return (
    <Button
      variant="contained"
      onClick={() => {
        if (onClick) {
          onClick(hideModal);
        }
        showModal(SimpleDialog, { title });
      }}
      color="primary"
    >
      simple dialog
    </Button>
  );
};

const App = () => {
  const title = <Test onClick={(hideModal) => hideModal()} />;

  return (
    <ModalProvider>
      <Test title={title} />
    </ModalProvider>
  );
};

export default App;
@Quernest Quernest self-assigned this Jun 24, 2021
@Quernest Quernest added the bug Something isn't working label Jun 24, 2021
Quernest added a commit that referenced this issue Jun 24, 2021
@Quernest Quernest linked a pull request Jun 24, 2021 that will close this issue
Quernest added a commit that referenced this issue Jun 24, 2021
#36 handle missed modal id scenario
@Quernest
Copy link
Owner

Thanks for this comment! I just published a new version of the package. Now this code works as expected (error is handled), but don't forget to provide the modal ID argument to the hideModal(id) function - this is mandatory.

The ID is optional if you call the hide function on a modal instance.

For example:

const modal = showModal(SimpleModal, { title: 'text' });

modal.hide();

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

Successfully merging a pull request may close this issue.

2 participants