Skip to content

Show flash alerts to users who prefer reduced motion - #374

Merged
Natalie-B-Wiese merged 2 commits into
mainfrom
fix-flash-reduced-motion
Nov 5, 2026
Merged

Natalie-B-Wiese merged 2 commits into
mainfrom
fix-flash-reduced-motion

Conversation

@Natalie-B-Wiese

@Natalie-B-Wiese Natalie-B-Wiese commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Task

[OP-XXX](link to ticket) No ticket. Upstream fix for the workaround in RoleModel/property-intel#4042.

Why?

Users who turn on "reduce motion" never see a flash alert (.alert--flash).

  • The flash animation (rm-slide-in-out-flash) starts off screen, slides in, holds, then slides back off screen, and forwards keeps that last off-screen frame.
  • Optics' reset shortens every animation to 0.01ms !important under prefers-reduced-motion: reduce. So the flash animation ends right away and the alert sits off screen for good.

With this change, those users get the alert in place with no sliding, and it goes away after the same 5 seconds. The default (motion) behavior is unchanged.

RoleModel/property-intel#4042 works around this in the app with the same approach. Once a release includes this fix, that override can be removed.

What Changed

  • Override --op-animation-flash under prefers-reduced-motion: reduce as rm-slide-in-out-flash 0.01ms 5s forwards. The reset forces only animation-duration, not animation-delay, so the 5s goes in the delay. During the delay forwards applies no keyframe, so the alert sits at its own inset-inline-end; at 5s it jumps to the off-screen last keyframe. (Thanks to @Jeremy-Walton for this simpler approach.)
  • Add a @tokens-end comment before that override, so the Storybook token addon doesn't list it under Input Focus
  • Note the reduced-motion behavior on the Alert docs page, including how to override the token for reduced motion

dist/tokens/tokens.json reports the reduced-motion value for --op-animation-flash, because build_token_json.js keeps the last declaration. The dark shadow tokens already work this way.

Quality Assurance

  • Have you tagged the PR with the correct labels?
  • Have you validated the changes?
    • Have you run linters? (yarn lint:css, yarn test)
    • Have you run prettier?
    • Have you tried building the css?
    • Have you tried building storybook?
  • [ ] Have you updated any usage of changed tokens? Only .alert--flash uses it.
  • [ ] Did you add a component?
    • [ ] Have you added it to the dependency graph?
    • [ ] Have you added it to the docs?
  • [ ] Did you update a component? Token change only; alert.css is unchanged.
    • [ ] Have you updated the dependency graph?
    • Have you updated the docs? (Alert page)
  • [ ] Do you need to update the package version? Left for the release PR.
    • [ ] Did you update the example pages in .storybook/assets?
  • [ ] Were any changes made to the top level optics.css file?
    • [ ] Were those changes reflected in the other top level files?

Verification

Built dist/css/optics.css from main and from this branch, loaded a page with one .alert.alert--flash in Playwright (Chromium, 1000px wide), and sampled its position:

Build Reduced motion 100ms 1.5s 3s 4.9s 5.1s 5.6s
main reduce off screen off screen off screen off screen off screen off screen
this branch reduce in view in view in view in view off screen off screen
main no preference sliding in in view in view sliding out off screen off screen
this branch no preference sliding in in view in view sliding out off screen off screen

Under reduced motion the alert held the same position at every sample until it went off screen (no slide). The Storybook build shows --op-animation-flash only on the Animation token page, with its normal value.

Screenshots

With prefers-reduced-motion: reduce (Playwright, Chromium): the alert appears in place at 1s with no slide and goes away 5s later. Recorded with the first version of this fix; the delay version looks the same. The motion version looks the same as before.

reduced-motion-flash.webm

🤖 Generated with Claude Code

@Natalie-B-Wiese Natalie-B-Wiese added documentation Improvements or additions to documentation Base Tokens Changes to the base tokens Components Changes to a component labels Nov 5, 2026
@Natalie-B-Wiese Natalie-B-Wiese self-assigned this Nov 5, 2026
@Natalie-B-Wiese
Natalie-B-Wiese marked this pull request as ready for review November 5, 2026 16:33
@Jeremy-Walton

Jeremy-Walton commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

Suggestion: I think this can be a token-only fix.

The reset only forces animation-duration (and animation-iteration-count). It does not touch animation-delay. So we can override the token under reduced motion and put the 5s in the delay:

/* shared_tokens.css */
@media (prefers-reduced-motion: reduce) {
  :root {
    /* modern-css-reset forces animation-duration to 0.01ms, so the 5s goes in the delay */
    --op-animation-flash: rm-slide-in-out-flash 0.01ms 5s forwards;
  }
}

During the delay, forwards does not apply any keyframe, so the alert uses its own inset-inline-end and sits in view. At 5s it jumps to the 100% keyframe (off screen), and forwards holds it there.

This lets us drop:

  • the .alert--flash override and its !important
  • the new --op-animation-reduced-motion-flash token (and the naming workaround)
  • the rm-hide-flash keyframes

I tested it in Chromium with the reset rule applied: the alert is in place from 0s to 5s, then off screen, with no positions in between (no slide).

Docs: I'd replace the added line in Alert.mdx with something like:

For users who prefer reduced motion, the flash appears in place without sliding and hides after 5 seconds. If you override --op-animation-flash, also override it inside @media (prefers-reduced-motion: reduce). Put the time in the delay, not the duration, because the reset shortens every animation duration to 0.01ms.

@Natalie-B-Wiese
Natalie-B-Wiese removed the request for review from theojluciano November 5, 2026 17:13
@Natalie-B-Wiese
Natalie-B-Wiese force-pushed the fix-flash-reduced-motion branch from 3059dcd to f2ab0ca Compare November 5, 2026 17:52
@Natalie-B-Wiese
Natalie-B-Wiese merged commit fae3060 into main Nov 5, 2026
4 checks passed
@Natalie-B-Wiese
Natalie-B-Wiese deleted the fix-flash-reduced-motion branch November 5, 2026 17:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Base Tokens Changes to the base tokens Components Changes to a component documentation Improvements or additions to documentation

Development

Successfully merging this pull request may close these issues.

2 participants