feat: add optional close button for toast dismissal#26
Open
lubauss wants to merge 1 commit intohiaaryan:mainfrom
Open
feat: add optional close button for toast dismissal#26lubauss wants to merge 1 commit intohiaaryan:mainfrom
lubauss wants to merge 1 commit intohiaaryan:mainfrom
Conversation
Add a `closeButton` prop to `<Toaster>` that renders an X dismiss button on each toast, visible on hover. This provides an alternative to swipe-to-dismiss for desktop users, especially useful for sticky toasts (duration: null) that don't auto-dismiss. - closeButton defaults to false (no visual change unless opted in) - Accessible: role="button", tabIndex, aria-label, keyboard support - Swipe-to-dismiss still works alongside the button
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add a
closeButtonprop to<Toaster>that renders an X dismiss button on each toast, visible on hover. This provides an alternative to swipe-to-dismiss for desktop users.Problem
Currently the only way to dismiss a toast (besides waiting for auto-dismiss) is swiping. Desktop users expect a close button, especially for sticky toasts (
duration: null) that don't auto-dismiss.Solution
New
closeButtonpropWhen enabled, each toast renders an X button (using the existing
Xicon) in the top-right corner. The button:onDismiss()on clickrole="button",tabIndex,aria-label, keyboard support (Enter/Space)CSS
Files Changed
src/toast.tsxcloseButtonprop toSileoToasterProps, pass to<Sileo>src/sileo.tsxcloseButtonprop, render X button with a11y attributessrc/styles.css[data-sileo-close]styles with hover revealBackward Compatibility
closeButtondefaults tofalse— no visual change unless opted inTesting
<Toaster closeButton />— hover over a toast, X button should fade incloseButtonprop — verify no X button appears