Skip to content

Why close notistack will also close modal? #613

@tjx666

Description

@tjx666

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",

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions