-
-
Notifications
You must be signed in to change notification settings - Fork 738
Description
Title: Restrict role prop to valid ARIA roles for toasts: "alert", "status", or "log"
Current behavior
The role prop on the <Toast> component (as defined here in types.ts) accepts string, meaning it can accept any value, including invalid or unintended roles.
role?: string;Expected behavior
To improve accessibility and developer experience, the role prop should be restricted to valid ARIA roles applicable for toasts:
"alert"(for urgent messages)"status"(for non-urgent status updates)"log"(for streaming messages/logs)
Suggested type definition:
role?: 'alert' | 'status' | 'log';This change:
- Prevents accidental use of inappropriate roles (like
"tooltip"or"dialog"). - Aligns with WAI-ARIA spec and screen reader behavior.
- Helps enforce accessible patterns by default.
Why this matters
Toasts are accessibility-critical components that announce messages to screen readers. Restricting the role ensures proper usage and improves reliability for assistive technology users.
Suggested fix
Update the ToastPosition type in [types.ts](https://github.com/fkhadra/react-toastify/blob/e1fa4760cea8adf28d5cf93cd14067a852b1f5c8/src/types.ts#L124) to:
role?: 'alert' | 'status' | 'log';Additional context
More about ARIA live regions:
Happy to contribute a PR if needed!