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

Why close notistack will also close modal? #613

Open
tjx666 opened this issue Nov 3, 2024 · 0 comments
Open

Why close notistack will also close modal? #613

tjx666 opened this issue Nov 3, 2024 · 0 comments

Comments

@tjx666
Copy link

tjx666 commented Nov 3, 2024

Expected Behavior

If I open a modal by the button in snackbar:

Close snackbar should not affect the opened modal

default.mov

Current Behavior

Close snackbar will also close the modal.

Steps to Reproduce

Link: https://stackblitz.com/edit/github-nmphsn-91r7az?file=components%2FWarning.tsx

  1. click button with text notify, you will see a warning snackbar message
  2. click the button in the snackbar message with text Open Modal
  3. will open the modal, but will close the modal imedially
export const Warning = forwardRef<HTMLDivElement, Props>(function Warning( { id }, ref ) {
  const { closeSnackbar } = useSnackbar();
  const { showModal } = useModal();

  const handleUpgrade = useCallback(
    (e: MouseEvent) => {
      // !: why close snackbar will close modal?
      closeSnackbar(id);
      showModal(Modal);
    },
    [showModal, closeSnackbar, id]
  );

  return (
    <SnackbarContent ref={ref}>
      <Card sx={{ width: 400, height: 100, bgcolor: 'yellow' }}>
        warning message
        <br />
        <Button variant="contained" onClick={handleUpgrade} sx={{ textTransform: 'none', }} > Open Modal </Button>
      </Card>
    </SnackbarContent>
  );
});

Versions

"notistack": "^3.0.1",
"react": "^18.3.1",
"@mui/material": "^5.16.1",
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant