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

Dismissing all toasts in a single container clears all toasts everywhere #1068

Closed
simgar98 opened this issue Feb 21, 2024 · 1 comment
Closed

Comments

@simgar98
Copy link
Contributor

Do you want to request a feature or report a bug?
Bug 🐛

What is the current behavior?
When dismissing all toasts from a single container it will simply clear all toasts everywhere.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn't have dependencies other than React. Paste the link to your CodeSandbox (https://codesandbox.io/s/new) example below:

Created a test for toast.cy.tsx:

it('remove all toasts for a given container', () => {
    const toastId = '123';

    toast('first container', {
      toastId,
      containerId: Containers.First
    });
    toast('third container', {
      toastId,
      containerId: Containers.Third
    });
    toast('third container second toast', {
      containerId: Containers.Third
    });

    cy.resolveEntranceAnimation();

    cy.findByText('first container').should('exist');
    cy.findByText('third container second toast').should('exist');
    cy.findByText('third container')
      .should('exist')
      .then(() => {
        toast.dismiss({
          containerId: Containers.Third,
        });

        cy.resolveEntranceAnimation();

        cy.findByText('first container').should('exist');
        cy.findByText('third container').should('not.exist');
        cy.findByText('third container second toast').should('not.exist');
        cy.findByText('first container').should('exist');
      });
  });

The fix is fairly easy, store.ts line ~70 should be something like:

    const container = containers.get(params.containerId);
    container ? container.removeToast(params.id) :
      containers.forEach(c => {
        c.removeToast(params.id);
      });

I will try to create a pull request for this, however I am new to contributing, so... lets see how this goes!

What is the expected behavior?
Remove all toasts from the provided container, leave all other toasts alone.

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
All

@simgar98
Copy link
Contributor Author

The Third Container in the test is simply a new container that has a higher limit, as all current containers in the current tests had a limit of 1 for queue testing (I think?)

const Containers = {
    First: 'first',
    Second: 'second',
    Third: 'third'
  };

  beforeEach(() => {
    cy.mount(
      <>
        <ToastContainer
          autoClose={false}
          position="top-left"
          limit={1}
          containerId={Containers.First}
          closeOnClick
        />
        <ToastContainer
          autoClose={false}
          position="top-right"
          limit={1}
          containerId={Containers.Second}
          closeOnClick
        />
        <ToastContainer
          autoClose={false}
          position="bottom-right"
          limit={10}
          containerId={Containers.Third}
          closeOnClick
        />
      </>
    );
  });

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