Skip to content

Commit 98a1c4c

Browse files
fix(elements): respect reduced motion preferences (#3980)
1 parent 5cf987e commit 98a1c4c

13 files changed

+21
-5
lines changed

packages/elements/playwright.config.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,22 @@ export default defineConfig({
3131
},
3232
/* Configure projects for major browsers */
3333
projects: [
34-
{ name: 'chromium', use: { ...devices['Desktop Chrome'], viewport: { width: 1400, height: 1000 } } },
34+
{
35+
name: 'chromium',
36+
use: {
37+
...devices['Desktop Chrome'],
38+
viewport: { width: 1400, height: 1000 },
39+
contextOptions: { reducedMotion: 'reduce' },
40+
},
41+
},
3542

36-
{ name: 'firefox', use: { ...devices['Desktop Firefox'] } },
43+
{
44+
name: 'firefox',
45+
use: {
46+
...devices['Desktop Firefox'],
47+
contextOptions: { reducedMotion: 'reduce' },
48+
},
49+
},
3750

3851
// {
3952
// name: 'webkit',

packages/elements/src/components/result-status-bar/result-status-bar.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export class ResultStatusBar extends BaseElement {
8383
style="width: ${this.#calculatePercentage(metric.amount)}%"
8484
class="${this.#colorFromMetric(metric.type)} ${metric.amount === 0
8585
? 'opacity-0'
86-
: 'opacity-100'} relative flex items-center overflow-hidden transition-width"
86+
: 'opacity-100'} relative flex items-center overflow-hidden motion-safe:transition-width"
8787
>${shouldBeSmall ? nothing : html`<span class="ms-3 font-bold text-gray-800">${metric.amount}</span>`}
8888
</div>`,
8989
);

packages/elements/src/lib/html-helpers.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,10 @@ export function describeLocation({ fileName, location }: { fileName: string; loc
121121

122122
export function scrollToCodeFragmentIfNeeded(el: Element | null) {
123123
if (el && !isElementInViewport(el)) {
124-
el.scrollIntoView({ block: 'center', behavior: 'smooth' });
124+
el.scrollIntoView({
125+
block: 'center',
126+
behavior: window.matchMedia('(prefers-reduced-motion: reduce)').matches ? 'instant' : 'smooth',
127+
});
125128
}
126129
}
127130

Loading
Loading
Loading
-31.5 KB
Loading
Loading

0 commit comments

Comments
 (0)