Skip to content

feat: Add enterFrom prop to control toast entry direction (#671)#721

Open
dosAnjosGustavo wants to merge 1 commit intoemilkowalski:mainfrom
dosAnjosGustavo:fix/issue-671-enter-from
Open

feat: Add enterFrom prop to control toast entry direction (#671)#721
dosAnjosGustavo wants to merge 1 commit intoemilkowalski:mainfrom
dosAnjosGustavo:fix/issue-671-enter-from

Conversation

@dosAnjosGustavo
Copy link
Copy Markdown

Closes #671.

This PR adds a way to control which horizontal side a toast should enter from, without changing the existing default behavior.

What’s new

  • Introduces an EnterFromDirection type:

    export type EnterFromDirection = 'left' | 'right';
  • Adds an optional enterFrom?: EnterFromDirection prop to:

    • ToastT
    • ToastProps
    • ToastOptions
    • ToasterProps

Behaviour & precedence

  • enterFrom can be set:

    • Per toast: toast('Message', { enterFrom: 'left' })
    • On the Toaster: <Toaster enterFrom="left" />
    • In toastOptions on the Toaster
  • Precedence:

    1. Per-toast enterFrom
    2. Toaster enterFrom prop
    3. toastOptions.enterFrom
  • When enterFrom is not provided, the current behaviour is preserved.

Implementation details

  • Each toast now has a data-enter-from attribute so the entry direction can be styled in CSS.

  • The base transform is split into two parts:

    • --initial-x (horizontal offset)
    • --y (existing vertical stacking)
  • Updated CSS to:

    • Slide toasts in from the configured side (left or right)
    • Make the front toast exit horizontally in the same direction instead of using the default vertical animation.

Testing

  • Added a Playwright test to assert that enterFrom is rendered on the toast when set via query string in the test app:

    • applies enterFrom attribute to toast when set
  • Ran pnpm test locally:

    • All existing tests pass except for the known flaky cancel button dismisses the custom toast with empty id case, which is already failing on the current main build as well (so it should be unrelated to this change).

…lski#671)

- Introduce an `EnterFromDirection` type and `enterFrom` prop on `ToastT`, `ToastProps`, `ToastOptions` and `ToasterProps` to control the horizontal entry side (left or right) of a toast.
- Define `enterFrom` precedence so per-toast settings override the Toaster-level prop, which in turn overrides `toastOptions`, keeping existing behavior unchanged when `enterFrom` is not provided.
- Add a `data-enter-from` attribute to each toast and split the base transform into `--initial-x` and `--y` so horizontal entry can be configured without affecting the vertical stacking logic.
- Update the CSS so toasts slide in from the configured side and, when removed as the front toast, exit horizontally instead of using the default vertical animation.
- Update the test app to accept `enterFrom` via query string and add a Playwright test to assert that the attribute is rendered correctly.
@vercel
Copy link
Copy Markdown

vercel bot commented Dec 12, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
sonner Ready Ready Preview Comment Dec 12, 2025 4:03am

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.

Toast appearance direction

1 participant