Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(Toast): reset the UA popover width so an end toast lands on the end edge (#5822)

freddymeta864e66d241a5
diff --git a/.changeset/toast-viewport-popover-width.md b/.changeset/toast-viewport-popover-width.md
new file mode 100644
index 0000000000..38669f21ff
--- /dev/null
+++ b/.changeset/toast-viewport-popover-width.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] `ToastViewport` resets the UA popover `width`, so an end-positioned toast lands on the end edge again. The viewport reaches the top layer through `popover="manual"`, and the UA stylesheet gives every popover `width: fit-content`. Since the placement rework the viewport is positioned by spanning the inline axis and aligning within itself, and a shrink-wrapped box cannot span — both inset edges cannot be honoured, so the box resolves against the start edge and `align-items: flex-end` aligns the toast to the right of a box sitting on the left. Measured in Chromium at 1200px: a 438px viewport at x=0, with the default `bottomEnd` toast at x=19 instead of x=781. The reset block already neutralised `inset`, `margin`, `border` and `background`; `width` belongs with them.
+
+@freddymeta
diff --git a/packages/core/src/Toast/ToastViewport.test.tsx b/packages/core/src/Toast/ToastViewport.test.tsx
index 57eec29b9b..d45ae9b1e4 100644
--- a/packages/core/src/Toast/ToastViewport.test.tsx
+++ b/packages/core/src/Toast/ToastViewport.test.tsx
@@ -291,6 +291,23 @@ describe('ToastViewport placement', () => {
expect(getComputedStyle(viewport).width).not.toBe('100%');
});
+ // The viewport is positioned by spanning the inline axis and aligning within
+ // itself, which only works if the box actually spans. `popover` makes that
+ // conditional: the UA stylesheet gives every popover `width: fit-content`,
+ // and a shrink-wrapped box cannot honour both inset edges — it resolves
+ // against the start edge, and an end-aligned toast lands on the LEFT
+ // (measured in Chromium at 1200px: a 438px box at x=0, toast at x=19).
+ //
+ // jsdom resolves no UA popover styles and no cascade, so it cannot reproduce
+ // that. What it CAN hold is the reset itself: the declaration is what stops
+ // the UA rule applying, so its absence is the regression. The rendered
+ // behaviour is covered by the placement matrix in the PR.
+ it('resets the UA popover width so the viewport can span the inline axis', () => {
+ const {viewport} = renderPlacement();
+
+ expect(getComputedStyle(viewport).width).toBe('auto');
+ });
+
it('maps explicit top and bottom placements to their configured edge', () => {
const top = renderPlacement({position: 'topEnd'});
expect(getComputedStyle(top.viewport).top).toBe('0px');
diff --git a/packages/core/src/Toast/ToastViewport.tsx b/packages/core/src/Toast/ToastViewport.tsx
index 8281d206cc..cb121c7d6c 100644
--- a/packages/core/src/Toast/ToastViewport.tsx
+++ b/packages/core/src/Toast/ToastViewport.tsx
@@ -63,6 +63,16 @@ const styles = stylex.create({
// layer (above dialogs), but we don't want its default styles.
// UA stylesheet applies background-color: Canvas, margin: auto, etc.
inset: 'unset',
+ // `width` is part of that reset: the UA gives every popover
+ // `width: fit-content`, and this element is positioned by spanning the
+ // inline axis (`viewportInlineSpan` sets both inset-inline edges to 0) and
+ // then aligning within itself. A shrink-wrapped box cannot span, so both
+ // edges cannot be honoured — the box resolves against the start edge at
+ // its content width, and `align-items: flex-end` then aligns the toast to
+ // the right of a box that is itself sitting on the left. Measured in
+ // Chromium at 1200px wide: 438px box at x=0, end-positioned toast landing
+ // at x=19.
+ width: 'auto',
margin: 0,
border: 'none',
background: 'none',