timolins / react-hot-toast

Smoking Hot React Notifications 🔥
https://react-hot-toast.com
MIT License
9.44k stars 309 forks source link

Fix Issue #244 #334

Open wherehows opened 6 months ago

wherehows commented 6 months ago

Summary

"toast" method's toast messages, using the "error" or "success" properties, do not apply the configured "ariaProps" options in the Toaster component. Please refer to the following link for more details.

https://github.com/timolins/react-hot-toast/issues/244

Reason

When the "error" or "success" properties of the toast function are called, the createToast function is invoked. However, the issue lies in the fact that createToast defines default values for ariaProps.

const createToast = (
  message: Message,
  type: ToastType = 'blank',
  opts?: ToastOptions
): Toast => ({
  createdAt: Date.now(),
  visible: true,
  type,
  ariaProps: {
    role: 'status',
    'aria-live': 'polite',
  },
  message,
  pauseDuration: 0,
  ...opts,
  id: opts?.id || genId(),
});

This value is causing an issue by overriding the globally set ariaProps option

Solution

Firstly, I made ariaProps an optional property for the Toast type. (62df748)

Secondly, within the createToast, I removed the ariaProps that were initially defined. (7f85f4e)

Lastly, within the store, I created a variable named 'defaultAriaProps' to ensure default values are applied to ariaProps. (https://github.com/timolins/react-hot-toast/pull/334/commits/2949993d97926c892693d119accf7c71bd81bca9)

vercel[bot] commented 6 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
react-hot-toast ❌ Failed (Inspect) Jan 14, 2024 4:42am
wherehows commented 5 months ago

@timolins I encountered an error on Vercel with this pull request, even though there were no issues during local testing and build. It's challenging to identify the cause of the problem. Could you please help me understand the reason for this error? If modifications are necessary, your guidance would be greatly appreciated.