Skip to content

Commit

Permalink
fix: make closeButton option in toast take precedence over Toaster (#309
Browse files Browse the repository at this point in the history
)
  • Loading branch information
jzxhuang authored Jan 24, 2024
1 parent 30b18d8 commit d1b6619
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
10 changes: 7 additions & 3 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const Toast = (props: ToastProps) => {
toasts,
expanded,
removeToast,
closeButton,
closeButton: closeButtonFromToaster,
style,
cancelButtonStyle,
actionButtonStyle,
Expand Down Expand Up @@ -77,6 +77,10 @@ const Toast = (props: ToastProps) => {
() => heights.findIndex((height) => height.toastId === toast.id) || 0,
[heights, toast.id],
);
const closeButton = React.useMemo(
() => toast.closeButton ?? closeButtonFromToaster,
[toast.closeButton, closeButtonFromToaster],
);
const duration = React.useMemo(
() => toast.duration || durationFromToaster || TOAST_LIFETIME,
[toast.duration, durationFromToaster],
Expand Down Expand Up @@ -295,7 +299,7 @@ const Toast = (props: ToastProps) => {
}
}}
>
{(closeButton || toast.closeButton) && !toast.jsx ? (
{closeButton && !toast.jsx ? (
<button
aria-label={closeButtonAriaLabel}
data-disabled={disabled}
Expand Down Expand Up @@ -628,7 +632,7 @@ const Toaster = (props: ToasterProps) => {
descriptionClassName={toastOptions?.descriptionClassName}
invert={invert}
visibleToasts={visibleToasts}
closeButton={closeButton}
closeButton={toastOptions?.closeButton ?? closeButton}
interacting={interacting}
position={position}
style={toastOptions?.style}
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export interface HeightT {

interface ToastOptions {
className?: string;
closeButton?: boolean;
descriptionClassName?: string;
style?: React.CSSProperties;
cancelButtonStyle?: React.CSSProperties;
Expand Down
2 changes: 1 addition & 1 deletion website/src/pages/toast.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ toast.dismiss();
| Property | Description | Default |
| :----------------- | :----------------------------------------------------------------------------------------------------: | -------------: |
| description | Toast's description, renders underneath the title. | `-` |
| closeButton | Adds a close button which shows on hover. | `false` |
| closeButton | Adds a close button. | `false` |
| invert | Dark toast in light mode and vice versa. | `false` |
| important | Control the sensitivity of the toast for screen readers | `false` |
| duration | Time in milliseconds that should elapse before automatically closing the toast. | `4000` |
Expand Down
2 changes: 1 addition & 1 deletion website/src/pages/toaster.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Changes the directionality of the toast's text.
| expand | Toasts will be expanded by default | `false` |
| visibleToasts | Amount of visible toasts | `3` |
| position | Place where the toasts will be rendered | `bottom-right` |
| closeButton | Adds a close button to all toasts, shows on hover | `false` |
| closeButton | Adds a close button to all toasts | `false` |
| offset | Offset from the edges of the screen. | `32px` |
| dir | Directionality of toast's text | `ltr` |
| hotkey | Keyboard shortcut that will move focus to the toaster area. | `⌥/alt + T` |
Expand Down

1 comment on commit d1b6619

@vercel
Copy link

@vercel vercel bot commented on d1b6619 Jan 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.