Skip to content

fix(react-toast): keep the Toaster inside narrow viewports - #36962

Open
Jake Salvesen (jakesalvesen) wants to merge 8 commits into
microsoft:masterfrom
jakesalvesen:fix/toast-narrow-viewport
Open

Jake Salvesen (jakesalvesen) wants to merge 8 commits into
microsoft:masterfrom
jakesalvesen:fix/toast-narrow-viewport

Conversation

@jakesalvesen

@jakesalvesen Jake Salvesen (jakesalvesen) commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Previous Behavior

The Toaster is position: fixed with a fixed width: 292px and no maximum width. With the default 20px horizontal offset it needs 312px, so in a narrower viewport it runs past the edge. At 280px a bottom-end toast starts 32px outside the left edge. The part that is still on screen also sits on top of the page gutter and takes the pointer events there. A custom offset.horizontal changes the width at which this starts.

New Behavior

getPositionStyles now returns a width cap with the position styles, as the custom property --fui-Toaster--max-width. The width of the Toaster is min(292px, var(--fui-Toaster--max-width, 100%)).

  • A start or end Toaster keeps its configured offset at its own edge and the default 20px gutter at the far edge. The cap is calc(100% - (offset + 20px)).
  • A centered Toaster is moved by its offset, which moves both of its edges. It keeps the 20px gutter and the distance it moved free on both sides. The cap is calc(100% - 2 * (|offset| + 20px)).

100% resolves against the same containing block as the offsets. That is the viewport without the scrollbar for the default Toaster, and the positioned ancestor for an inline Toaster.

The cap is on width and not on max-width. A max-width that the caller sets through style or className stays a declaration of its own, and the stricter of the two limits applies.

Each position of the Toaster also gets its own style object. The position slots are created from the same root props, so on master they share the object that is passed as style, and the position styles are written into that object. With a style prop the styles of one position, and now its cap, would end up on the others. In a development build the Toaster also throws on its next render, because React freezes a style object once it has rendered it. That is #37209. Each slot now gets a new object: the caller's styles with the styles of its own position on top.

A bottom-end toast with the default offset in a 280px wide viewport:

master This PR
On master the toast is cut off at the left edge of a 280px viewport With this change the toast fits with a 20px gutter on both sides

Measured in Electron 130 at 280px wide. Each cell is the left gutter, the right gutter and the width of the Toaster in px. A negative gutter is an overflow.

Position Horizontal offset master This PR
bottom-end default -32, 20, 292 20, 20, 240
bottom-end 60 -72, 60, 292 20, 60, 200
bottom-start default 20, -32, 292 20, 20, 240
bottom-start 0 0, -12, 292 0, 20, 260
top-end 32 -44, 32, 292 20, 32, 228
top-start 60 60, -72, 292 60, 20, 200
bottom default -6, -6, 292 20, 20, 240
bottom 32 26, -38, 292 84, 20, 176
top -32 -38, 26, 292 20, 84, 176

A bottom-end Toaster with its own limit, measured the same way. Each cell is the width in px.

The caller sets Viewport master This PR
maxWidth: 200 in style, or max-width: 200px through className 600px 200 200
the same 280px 200 200
the same 180px 200, starts 40px outside the left edge 140
width: 400px in style or through className 280px 400, starts 140px outside the left edge 400, starts 140px outside the left edge

Behavior changes to be aware of

  • With the default offset the cap applies below 332px, not only below 312px where the overflow starts. Between 312px and 331px the toast used to stay 292px wide and move closer to the far edge. It now narrows and keeps the 20px gutter. At 320px that is a 280px toast with 20px on both sides, where master shows a 292px toast with 8px and 20px.
  • An inline Toaster in a container narrower than 332px narrows in the same way.
  • A Toaster with a max-width from the caller keeps it, and the cap applies only where it is stricter. A Toaster whose width is overridden keeps that width and is not capped, as on master.
  • The Toaster no longer changes the object that is passed as style.
  • The width uses min() with a custom property, as the thumb position of Slider uses clamp(). Firefox 69 to 74 and Opera 64 and 65, which are only in the partial support matrix, do not support min(). By the CSS rules for custom properties the width declaration is then invalid at computed-value time, so the Toaster takes its width from its content. I did not test those browsers.

Tests

  • Toaster.cy.tsx is new. In a 280px viewport it mounts a toast for the nine combinations in the first table and checks, for both the Toaster and the toast inside it, that the near edge keeps the configured offset and the far edge keeps the 20px gutter. A tenth case uses elementFromPoint to check that the toast no longer covers the page gutter. These ten fail on master.
  • Four more cases cover a limit from the caller: a maxWidth of 200px from style and from className stays 200px in a 600px viewport, the cap applies when it is stricter than a maxWidth from style, and the 200px from className applies in the 280px viewport.
  • A fifteenth case has toasts in bottom-start and bottom-end with different offsets and a style prop, and checks that each keeps its own position and its own cap.
  • Toaster.test.tsx gains a case that shows two toasts in a Toaster with a style prop and checks that the object of the caller is not changed. It throws on master.
  • getPositionStyles.test.ts covers the expected cap for start, end and centered positions, negative offsets, and per-position offsets.

Run on this branch:

  • react-toast unit suite: 224 tests pass, also under React 17 and React 18. Lint, type-check and format:check pass.
  • Toaster.cy.tsx: 15 of 15 pass, and 20 runs in a row passed without a retry. The react-toast Cypress suite also passes under React 17 and React 18.

How to test

Open a Toast story, for example Offset, narrow the browser to 280px and dispatch a toast. Then try 320px, a horizontal offset of 0, 32 and 60, and the bottom position. Add style={{ maxWidth: 200 }} to the Toaster to see a caller's limit kept.

Related Issue(s)

@jakesalvesen

Jake Salvesen (jakesalvesen) commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor Author

Test evidence from a clean Linux VM (Debian 13, Node 22.23.5), running the committed test file through Jest and ts-jest:

PASS src/vanilla/getPositionStyles.test.ts
  getPositionStyles
    ✓ should return default styles for bottom with text direction ltr
    ✓ should return default styles for bottom-end with text direction ltr
    ✓ should return default styles for bottom-start with text direction ltr
    ✓ should return default styles for top with text direction ltr
    ✓ should return default styles for top-end with text direction ltr
    ✓ should return default styles for top-start with text direction ltr
    ✓ should return default styles for bottom with text direction rtl
    ✓ should return default styles for bottom-end with text direction rtl
    ✓ should return default styles for bottom-start with text direction rtl
    ✓ should return default styles for top with text direction rtl
    ✓ should return default styles for top-end with text direction rtl
    ✓ should return default styles for top-start with text direction rtl
    ✓ should handle offset shorthand
    ✓ should handle offset long hand
    ✓ should handle offset for centered positions
    ✓ should cap the width against a bottom-end offset of 32
    ✓ should cap the width against a bottom-start offset of 32
    ✓ should cap the width against a top-end offset of 32
    ✓ should cap the width against a bottom offset of 32
    ✓ should cap the width against a bottom-end offset of 60
    ✓ should cap the width against a bottom offset of 60
    ✓ should cap the width against a bottom-end offset of -32
    ✓ should cap the width against a bottom offset of -32
    ✓ should cap the width against a bottom-end offset of 10

Tests:       24 passed, 24 total

Separately, the formula was checked against a layout model of the offset arithmetic across 5 viewport widths, 6 positions and 8 non-negative offsets (240 combinations). No case overflows on either edge. Negative offsets are excluded: they position the element outside the viewport by design, and a width cap cannot correct that.

The Cypress cases were run as well, and they are a clean red-green. Full output is in a later comment on this PR: 3 passing with the change, and 2 failing against this PR's original implementation, with expected -20 to be at least 0 and expected 292 to be at most 280.

@jakesalvesen

Copy link
Copy Markdown
Contributor Author

Cypress component tests now run on the VM, so the earlier "not run locally" caveat is closed. The result is a clean red-green.

With the change applied:

  Toaster
    ✓ fits inside a viewport narrower than the toast (137ms)
    ✓ fits inside a narrow viewport with a horizontal offset wider than the default gutter (102ms)
    ✓ fits inside a narrow viewport for a centered toast with a horizontal offset (100ms)

  Tests:        3
  Passing:      3
  Failing:      0

Against this PR's original implementation (getPositionStyles from master plus the hardcoded maxWidth: 'calc(100vw - 40px)' in the reset class):

  Toaster
    ✓ fits inside a viewport narrower than the toast (138ms)
    ✕ fits inside a narrow viewport with a horizontal offset wider than the default gutter
    ✕ fits inside a narrow viewport for a centered toast with a horizontal offset

  1 passing
  2 failing

  AssertionError: Timed out retrying after 8000ms: the toaster does not start before the left edge:
    expected -20 to be at least 0
  AssertionError: Timed out retrying after 8000ms: the toaster does not end after the right edge:
    expected 292 to be at most 280

Both failures land on the numbers in the table above: bottom-end with a 60px offset puts the left edge at -20, and a centered toast with a 32px offset puts the right edge at 292 in a 280px viewport. The default-offset case passes either way, which is why it stays as the baseline rather than as the regression guard.

Environment: Debian 13, Node 22.23.5, Cypress 14.4.1 (the version this repo pins), headless Electron via xvfb-run, yarn install --mode=skip-build plus a build of scripts-cypress.

Separately, the CSS was checked in Chromium against a layout model of 32 combinations (4 viewport widths x 8 position/offset cases): no overflow with the change, 16 overflows without it. That check used a hand-copied transcription of getPositionStyles, so the Cypress run above is the authoritative result.

@jakesalvesen Jake Salvesen (jakesalvesen) changed the title fix(react-toast): keep the Toaster inside viewports narrower than the toast fix(react-toast): keep the Toaster inside narrow viewports Nov 20, 2026
@jakesalvesen

Copy link
Copy Markdown
Contributor Author

Paul Mardling (@PaulGMardling), I pushed an update and rewrote the description to match. I also owe you a correction on the test point from your review.

Correction. In Cypress component tests the spec runs in the same frame as the mounted component. I checked it in this repo: after cy.viewport(280, 400), window.innerWidth in the spec is 280, and element.ownerDocument.defaultView === window is true. So the first version of the assertion was already reading the application viewport, and my reply saying it had hidden two overflow cases was wrong about the cause. Those cases were missed because the spec only tested the default offset. The spec now reads documentElement.clientWidth, which also leaves out a scrollbar.

What changed since your review.

  • The cap keeps the configured offset at the near edge and the default 20px gutter at the far edge. A centered Toaster keeps the gutter on both sides. Before this update a centered toast with an offset of 20px or more ended flush with the edge it moved toward.
  • Toaster.cy.tsx now checks nine combinations of position and offset, measures the toast as well as the Toaster, and has a case for the pointer events in the gutter. All ten cases fail on master.
  • I reverted an unrelated import change in useToasterStyles.styles.ts, so that file is no longer part of the diff.
  • The branch is rebased onto current master.

The description has the measurements, a before and after screenshot, and the three behavior changes worth knowing about.

@jakesalvesen

Copy link
Copy Markdown
Contributor Author

Paul Mardling (@PaulGMardling), thanks for approving the workflows. Neither failure comes from this change, so I rebased onto current master to get a clean run.

  • bundle-size built the merge commit GitHub created when I pushed, ed1f38bb plus this branch, which is from before feat(v9): compile v9 packages to ES2020 #37159 compiled the v9 packages to ES2020. The baseline it compared against is 03e93661, which includes feat(v9): compile v9 packages to ES2020 #37159. So almost every fixture looked larger, and headless fixtures this PR does not touch, such as Breadcrumb and Checkbox, went over the threshold. A re-run would build the same merge commit.
  • Generate screenshots stopped on a 30 second page.waitForLoadState timeout in the Image Fluid story, before it reached any Toast story.

The code is the same as on the head you approved. The workflows on the new head need approval again. Sorry for the extra step.

@github-actions

Copy link
Copy Markdown

📊 Bundle size report

Package & Exports Baseline (minified/GZIP) PR Change
react-components
react-components: all base hooks
241.103 kB
76.203 kB
241.045 kB
76.178 kB
-58 B
-25 B
react-components
react-components: entire library
1.267 MB
318.426 kB
1.267 MB
318.468 kB
120 B
42 B
react-headless-components-preview
react-headless-components-preview: entire library
292.603 kB
90.729 kB
292.545 kB
90.708 kB
-58 B
-21 B
react-headless-components-preview
@fluentui/react-headless-components-preview/badge
7.212 kB
3.151 kB
7.154 kB
3.125 kB
-58 B
-26 B
react-toast
Toast (including Toaster)
87.483 kB
27.744 kB
87.629 kB
27.803 kB
146 B
59 B
Unchanged fixtures
Package & Exports Size (minified/GZIP)
react-components
react-components: Button, FluentProvider & webLightTheme
66.794 kB
19.555 kB
react-components
react-components: Accordion, Button, FluentProvider, Image, Menu, Popover
218.826 kB
66.296 kB
react-components
react-components: FluentProvider & webLightTheme
40.22 kB
13.67 kB
react-headless-components-preview
@fluentui/react-headless-components-preview/accordion
9.189 kB
3.314 kB
react-headless-components-preview
@fluentui/react-headless-components-preview/avatar
9.827 kB
4.204 kB
react-headless-components-preview
@fluentui/react-headless-components-preview/avatar-group
39.234 kB
13.902 kB
react-headless-components-preview
@fluentui/react-headless-components-preview/breadcrumb
8.754 kB
3.629 kB
react-headless-components-preview
@fluentui/react-headless-components-preview/button
4.918 kB
1.988 kB
react-headless-components-preview
react-headless-components-preview: Calendar
27.6 kB
10.414 kB
react-headless-components-preview
@fluentui/react-headless-components-preview/card
10.96 kB
4.297 kB
react-headless-components-preview
@fluentui/react-headless-components-preview/checkbox
8.884 kB
3.785 kB
react-headless-components-preview
@fluentui/react-headless-components-preview/color-picker
15.125 kB
5.794 kB
react-headless-components-preview
@fluentui/react-headless-components-preview/combobox
42.924 kB
14.938 kB
react-headless-components-preview
@fluentui/react-headless-components-preview/compound-button
5.371 kB
2.081 kB
react-headless-components-preview
react-headless-components-preview: DatePicker
44.979 kB
16.306 kB
react-headless-components-preview
@fluentui/react-headless-components-preview/dialog
18.552 kB
7.165 kB
react-headless-components-preview
@fluentui/react-headless-components-preview/divider
3.535 kB
1.504 kB
react-headless-components-preview
@fluentui/react-headless-components-preview/drawer
22.013 kB
8.192 kB
react-headless-components-preview
@fluentui/react-headless-components-preview/dropdown
41.133 kB
14.303 kB
react-headless-components-preview
@fluentui/react-headless-components-preview/field
8.169 kB
3.434 kB
react-headless-components-preview
@fluentui/react-headless-components-preview/image
5.63 kB
2.518 kB
react-headless-components-preview
@fluentui/react-headless-components-preview/info-label
26.998 kB
9.897 kB
react-headless-components-preview
@fluentui/react-headless-components-preview/input
8.066 kB
3.479 kB
react-headless-components-preview
@fluentui/react-headless-components-preview/interaction-tag
9.775 kB
3.838 kB
react-headless-components-preview
@fluentui/react-headless-components-preview/label
6.15 kB
2.703 kB
react-headless-components-preview
@fluentui/react-headless-components-preview/link
6.742 kB
2.955 kB
react-headless-components-preview
@fluentui/react-headless-components-preview/list
18.811 kB
6.992 kB
react-headless-components-preview
@fluentui/react-headless-components-preview/menu
34.922 kB
11.603 kB
react-headless-components-preview
@fluentui/react-headless-components-preview/menu-button
5.156 kB
2.029 kB
react-headless-components-preview
@fluentui/react-headless-components-preview/message-bar
10.095 kB
4.073 kB
react-headless-components-preview
@fluentui/react-headless-components-preview/nav
28.236 kB
9.897 kB
react-headless-components-preview
@fluentui/react-headless-components-preview/overflow
12.72 kB
4.517 kB
react-headless-components-preview
@fluentui/react-headless-components-preview/persona
10.883 kB
4.51 kB
react-headless-components-preview
@fluentui/react-headless-components-preview/popover
21.231 kB
7.705 kB
react-headless-components-preview
@fluentui/react-headless-components-preview/positioning
7.24 kB
2.74 kB
react-headless-components-preview
@fluentui/react-headless-components-preview/progress-bar
6.523 kB
2.899 kB
react-headless-components-preview
@fluentui/react-headless-components-preview/provider
3.47 kB
1.448 kB
react-headless-components-preview
@fluentui/react-headless-components-preview/radio-group
9.411 kB
4.001 kB
react-headless-components-preview
@fluentui/react-headless-components-preview/range-slider
14.19 kB
5.521 kB
react-headless-components-preview
@fluentui/react-headless-components-preview/rating
9.251 kB
3.79 kB
react-headless-components-preview
@fluentui/react-headless-components-preview/rating-display
8.865 kB
3.635 kB
react-headless-components-preview
@fluentui/react-headless-components-preview/search-box
9.66 kB
4.068 kB
react-headless-components-preview
@fluentui/react-headless-components-preview/select
7.531 kB
3.317 kB
react-headless-components-preview
@fluentui/react-headless-components-preview/skeleton
6.102 kB
2.698 kB
react-headless-components-preview
@fluentui/react-headless-components-preview/slider
9.43 kB
4.058 kB
react-headless-components-preview
@fluentui/react-headless-components-preview/spin-button
12.311 kB
4.826 kB
react-headless-components-preview
@fluentui/react-headless-components-preview/spinner
7.461 kB
3.226 kB
react-headless-components-preview
@fluentui/react-headless-components-preview/split-button
7.167 kB
2.566 kB
react-headless-components-preview
@fluentui/react-headless-components-preview/swatch-picker
11.316 kB
4.532 kB
react-headless-components-preview
@fluentui/react-headless-components-preview/switch
8.892 kB
3.759 kB
react-headless-components-preview
@fluentui/react-headless-components-preview/tab-list
7.447 kB
2.877 kB
react-headless-components-preview
@fluentui/react-headless-components-preview/tag
8.089 kB
3.453 kB
react-headless-components-preview
@fluentui/react-headless-components-preview/tag-group
7.513 kB
3.217 kB
react-headless-components-preview
@fluentui/react-headless-components-preview/tag-picker
49.24 kB
16.51 kB
react-headless-components-preview
@fluentui/react-headless-components-preview/teaching-popover
34.392 kB
12.026 kB
react-headless-components-preview
@fluentui/react-headless-components-preview/textarea
7.853 kB
3.413 kB
react-headless-components-preview
@fluentui/react-headless-components-preview/toast
23.37 kB
8.533 kB
react-headless-components-preview
@fluentui/react-headless-components-preview/toggle-button
5.821 kB
2.289 kB
react-headless-components-preview
@fluentui/react-headless-components-preview/toolbar
13.436 kB
4.988 kB
react-headless-components-preview
@fluentui/react-headless-components-preview/tooltip
22.008 kB
8.02 kB
react-headless-components-preview
@fluentui/react-headless-components-preview/tree
28.364 kB
9.661 kB
react-headless-components-preview
@fluentui/react-headless-components-preview/utils
126 B
124 B
react-portal-compat
PortalCompatProvider
5.028 kB
2.043 kB
react-timepicker-compat
TimePicker
135.912 kB
44.725 kB
🤖 This report was generated against 254b9070079c073dce2b65530e800386b3d4c47d

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

One issue to look at in getPositionStyles.ts

Object.assign(positionStyles, {
bottom: vertical,
[end]: horizontal,
maxWidth,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could we preserve stricter caller-provided width limits when applying this cap? For example, <Toaster style={{ maxWidth: 200 }} /> previously stayed 200px wide, but the existing Object.assign now replaces that limit, expanding it to 292px on desktop. Could we combine the limits and add a regression test so viewport protection doesn’t widen existing customized toasters?

@jakesalvesen Jake Salvesen (jakesalvesen) Nov 23, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch, thank you. Fixed in cde8856, with a different approach, so that the caller's limit is not touched at all.

  • The cap is no longer an inline max-width. getPositionStyles returns it as a custom property, and the width of the Toaster is min(292px, var(--fui-Toaster--max-width, 100%)).
  • max-width belongs to the caller again. <Toaster style={{ maxWidth: 200 }} /> stays 200px wide on desktop. So does a max-width from className, which the inline cap also overrode.
  • In a narrow viewport the stricter of the two limits applies. At 180px that Toaster is 140px wide, with the 20px gutter on both sides.
  • A Toaster whose width is overridden keeps that width, as on master.

Toaster.cy.tsx has four new cases for this. Three of them fail on the previous head. The description has the measurements and the browser support note for min().

Edited on November 23, 2026: updated the commit id after the branch was rebased onto master.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Position slots share the caller’s style object, causing width caps to overwrite one another and potentially allowing toasts to overflow when multiple positions are used.

1 open issue
What changed in this PR

This PR addresses #37124 by making Fluent UI’s Toaster shrink in narrow viewports, preserving page gutters and preventing toasts from capturing pointer events there.

Changes:

  • Derives position-specific width caps from horizontal offsets and applies them through a CSS custom property.
  • Preserves caller-provided max-width limits while leaving explicit width overrides unchanged.
  • Adds unit and Cypress coverage for offsets, narrow viewports, gutter hit testing, and caller limits.
File Description
packages/​react-components/​react-toast/​library/​src/​state/​vanilla/​index.ts Re-exports the width-cap custom property name.
packages/​react-components/​react-toast/​library/​src/​state/​vanilla/​getPositionStyles.ts Calculates width caps for each position and offset.
packages/​react-components/​react-toast/​library/​src/​state/​vanilla/​getPositionStyles.test.ts Tests width caps and per-position offsets.
packages/​react-components/​react-toast/​library/​src/​state/​index.ts Exposes the custom property to component styles.
packages/​react-components/​react-toast/​library/​src/​components/​Toaster/​useToasterStyles.styles.ts Applies the cap to the Toaster’s width.
packages/​react-components/​react-toast/​library/​src/​components/​Toaster/​Toaster.cy.tsx Adds browser coverage for sizing and gutter behavior.
change/​@fluentui-react-toast-0e392a43-5fbd-4cec-8da6-5a1af31ffeab.json Records the patch release change.

Review effort: Balanced

… toast

The Toaster root is position fixed with width 292px and no viewport clamp, so on a
viewport narrower than the toast plus its 20px edge offset the root starts at a
negative left offset. The toast then covers the left edge of the screen and takes
pointer events over the content beneath it.

max-width: calc(100vw - 40px) keeps the default offset on both sides at any width.
…ange

Follow the repository's contributing documentation: generate the change file
with `yarn beachball change` and the `fix(react-toast): ...` message format
instead of a hand-written file.

No code change.
…fset


The cap was a hardcoded calc(100vw - 40px), which assumed the default 20px offset
and ignored Toaster.offset. It also used 100vw, which includes the scrollbar, so it
could still overflow by the scrollbar width.

Move the cap into getPositionStyles, where the offset is already resolved, and
compute it as calc(100% - max(2 * abs(horizontal), 40)px). The floor keeps the
default 20px gutter, so the default offset produces the same 40px as before. A
centered toast is shifted by the offset and keeps its own width, so it needs the
same 2x term on one side.

100% replaces 100vw: on a fixed element it resolves against the viewport minus the
scrollbar, and in inline mode against the positioned ancestor, which is the intended
bound in both cases.

The Cypress assertion compared against window.innerWidth, which in a spec is the
runner window rather than the application viewport that cy.viewport resizes, so it
could pass while the toast was outside the application viewport. It now reads
ownerDocument.defaultView.

Two cases are added alongside the existing one, chosen so the old hardcoded cap
fails: a bottom-end toast with a 60px offset, which put the left edge 20px outside
the viewport, and a centered toast with a 32px offset, which put the right edge
12px outside.
These files were written on Windows and committed with CRLF, which the repository's Prettier configuration rejects (endOfLine defaults to lf). No content changes.
No behaviour change. The repository's Prettier configuration (printWidth 120) wants one assertion collapsed to a single line and two table rows expanded.
…Toaster is capped

A centered Toaster with a horizontal offset of 20px or more ended flush with the edge it moved toward, and a start or end Toaster with a small offset was narrower than it had to be. The cap now keeps the configured offset at the near edge and the default gutter at the far edge, and a centered Toaster keeps the gutter at both edges.

The Cypress spec measures the toast as well as the Toaster, covers every kind of position, and checks that the gutter stays free for pointer events. An unrelated import change in useToasterStyles.styles.ts is reverted.
…rom the caller still applies

The width cap was an inline max-width. It replaced a maxWidth from the style prop and won over a
max-width from className, so a Toaster that was limited to 200px grew back to 292px.

The position styles now set the cap as a custom property, and the width of the Toaster is
min(292px, cap). A max-width from the caller is a separate declaration again, so the stricter of
the two limits applies.
The position slots are created from the same root props, so they share the style object of the
caller, and the position styles were written into that object. With a style prop the width cap
and the position styles of one position ended up on the others. React also freezes a style
object in development once it has rendered it, so the next render of the Toaster threw.

Each position slot now gets a new object: the style of the caller with its own position styles
on top.

Fixes microsoft#37209

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are reported for the changes addressing Toaster overflow and shared style mutations.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants