Skip to content

fix updating existing toast notifications - #707

Open
dharamdan01 wants to merge 1 commit into
CodeSeven:masterfrom
dharamdan01:fix/701-update-existing-toast
Open

dharamdan01 wants to merge 1 commit into
CodeSeven:masterfrom
dharamdan01:fix/701-update-existing-toast

Conversation

@dharamdan01

Copy link
Copy Markdown

Closes #701
This PR changes the toast behavior when a toast is already visible.

  • The first notification creates a normal toast.
  • If another notification occurs while the toast is visible, a new toast is not created.
  • Instead, the existing toast message is updated with the new notification content.
  • Further notifications continue updating the same visible toast rather than creating additional toast elements.

This prevents multiple visible toasts from accumulating while still allowing new notification content to be displayed. This is different from preventDuplicates, which prevents duplicate notifications; this change updates the existing toast instead.

🛠️ How Was This Implemented?

  • Check whether an existing .toast element is present in the container.
  • If an existing toast is found, update its .toast-message content.
  • Return early to prevent creation of another toast.
  • If no existing toast is present, continue with the normal toast creation flow.
  • Preserve the existing preventDuplicates behavior.

📸 Visuals (If applicable)

contribute- 2 contribute-2

🧪 Testing Instructions

  1. Run npm install.
  2. Start the project/demo.
  3. Trigger a toast notification and verify that one toast is created.
  4. Trigger another notification while the first toast is visible.
  5. Verify that the existing toast message is updated instead of creating another toast.
  6. Trigger multiple notifications while the toast remains visible.
  7. Verify that only one toast remains visible and its message is updated with the latest notification.
  8. Verify that preventDuplicates continues to behave as expected.

✅ Checklist

  • My code follows the repository style guidelines
  • I have performed a self-review of my own code
  • New and existing unit tests pass locally
  • I have updated the documentation accordingly

This branch has not been deployed

No deployments
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

Successfully merging this pull request may close these issues.

Update a toast message if a toast is already visible

1 participant