Skip to content

Commit

Permalink
Fix: Dismiss all toasts in a single container
Browse files Browse the repository at this point in the history
Fix: Dismiss all toasts in a single container (re-apply)
  • Loading branch information
simgar98 authored and fkhadra committed Mar 2, 2024
1 parent edb231d commit 09cf0fb
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 5 deletions.
10 changes: 6 additions & 4 deletions src/core/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,12 @@ export function removeToast(params?: Id | RemoveParams) {
c.removeToast(params as Id);
});
} else if (params && ('containerId' in params || 'id' in params)) {
containers.get(params.containerId)?.removeToast(params.id) ||
containers.forEach(c => {
c.removeToast(params.id);
});
const container = containers.get(params.containerId);
container
? container.removeToast(params.id)
: containers.forEach(c => {
c.removeToast(params.id);
});
}
}

Expand Down
45 changes: 44 additions & 1 deletion src/core/toast.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,8 @@ describe('with container', () => {
describe('with multi containers', () => {
const Containers = {
First: 'first',
Second: 'second'
Second: 'second',
Third: 'third'
};

beforeEach(() => {
Expand All @@ -354,6 +355,13 @@ describe('with multi containers', () => {
containerId={Containers.Second}
closeOnClick
/>
<ToastContainer
autoClose={false}
position="bottom-right"
limit={10}
containerId={Containers.Third}
closeOnClick
/>
</>
);
});
Expand Down Expand Up @@ -409,6 +417,41 @@ describe('with multi containers', () => {
});
});

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');
});
});

it('clear waiting queue for a given container', () => {
toast('msg1-c1', {
containerId: Containers.First
Expand Down

0 comments on commit 09cf0fb

Please sign in to comment.