Skip to content

feat(Toast): add placement prop to ToastContainer - #7609

Merged
reidbarber merged 2 commits into
mainfrom
toast-placement
Jan 15, 2025
Merged

reidbarber merged 2 commits into
mainfrom
toast-placement

Conversation

@reidbarber

@reidbarber reidbarber commented Jan 14, 2025 •

Copy link
Copy Markdown
Member

✅ Pull Request Checklist:

  • Included link to corresponding React Spectrum GitHub Issue.
  • Added/updated unit tests and storybook for this change (for new code or code which already has tests).
  • Filled out test instructions.
  • Updated documentation (if it already exists for this component).
  • Looked at the Accessibility Practices for this feature - Aria Practices

📝 Test Instructions:

Check storybook, and use controls to try different placements in LTR and RTL locales

🧢 Your Project:

@rspbot

rspbot commented Jan 14, 2025

Copy link
Copy Markdown


## Placement

By default, toasts are displayed at the bottom center of the screen. This can be changed by setting the `placement` prop on the `ToastContainer` to `'top start'`, `'top'`, `'top end'`, `'bottom start'`, `'bottom'`, or `'bottom end'`.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

How does the team feel about a blurb for mfe's that may have multiple ToastContainers?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Good catch! I checked and we currently don't talk about multiple ToastContainers in the docs. Do we need a general section on that or continue not documenting it?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Going to be editing more docs soon, so I'll do this in a follow up!

@rspbot

rspbot commented Jan 15, 2025

Copy link
Copy Markdown

@rspbot

rspbot commented Jan 15, 2025

Copy link
Copy Markdown
## API Changes

@react-spectrum/toast

/@react-spectrum/toast:ToastContainer

 ToastContainer {
   aria-describedby?: string
   aria-details?: string
   aria-label?: string = "Notifications"
   aria-labelledby?: string
+  placement?: ToastPlacement
 }

/@react-spectrum/toast:SpectrumToastContainerProps

 SpectrumToastContainerProps {
   aria-describedby?: string
   aria-details?: string
   aria-label?: string = "Notifications"
   aria-labelledby?: string
+  placement?: ToastPlacement
 }


## Placement

By default, toasts are displayed at the bottom center of the screen. This can be changed by setting the `placement` prop on the `ToastContainer` to `'top start'`, `'top'`, `'top end'`, `'bottom start'`, `'bottom'`, or `'bottom end'`.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Good catch! I checked and we currently don't talk about multiple ToastContainers in the docs. Do we need a general section on that or continue not documenting it?

import {useSyncExternalStore} from 'use-sync-external-store/shim/index.js';

export interface SpectrumToastContainerProps extends AriaToastRegionProps {}
export type ToastPlacement = 'top start' | 'top' | 'top end' | 'bottom start' | 'bottom' | 'bottom end';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I know that we specified in the ticket that we'd only support this set of placement, but it just occurred to me that we support left and right in additional to start and end in our other placement props. I don't quite remember if there was a use case for that or if it was carryover from v2 or not...

@reidbarber
reidbarber added this pull request to the merge queue Jan 15, 2025
Merged via the queue into main with commit 78683ee Jan 15, 2025
@reidbarber
reidbarber deleted the toast-placement branch January 15, 2025 22:26
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.

5 participants