Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions source/_base.css
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@

@media print, (prefers-reduced-motion: reduce) {
.animated {
animation-delay: 0s !important;
animation-duration: 1ms !important;
transition-duration: 1ms !important;
animation-iteration-count: 1 !important;
Expand Down
14 changes: 14 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Reduced-motion regression

Build the CSS with `npm install` and `npm start`. Install the optional browser
runner with `npm install --no-save --package-lock=false @playwright/test`, then
run `npx playwright install chromium firefox webkit` and
`node tests/reduced-motion.js`.

The check covers all three distribution builds, normal/reduced-motion/print
media, visible entrance content, and delivery of `animationend`.
An optional CSS filename can be passed to test a previous build.

For a manual reproduction, open `tests/reduced-motion.html` after building and
toggle the operating system's reduced-motion preference (or emulate it in
browser developer tools), then reload. Check print preview as well.
21 changes: 21 additions & 0 deletions tests/reduced-motion.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8" />
<title>Reduced motion delay regression</title>
<link rel="stylesheet" href="../animate.css" />
<h1>Delayed entrance</h1>
<p>
Build with npm start. With reduced motion enabled, the message below should appear immediately
and report animationend. With no preference, it should retain its five-second delay. Also check
print preview.
</p>
<p id="status" role="status">Waiting for animationend...</p>
<p id="message" class="animate__animated animate__fadeIn animate__delay-5s">
This content should not remain hidden for five seconds under reduced motion.
</p>
<script>
document.getElementById('message').addEventListener('animationend', function () {
document.getElementById('status').textContent = 'animationend received';
});
</script>
</html>
70 changes: 70 additions & 0 deletions tests/reduced-motion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Build with `npm start`, install @playwright/test locally, then run this file with Node.
// Optional argument: a built CSS file (defaults to all three distribution builds).
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const {chromium, firefox, webkit} = require('@playwright/test');

(async () => {
const files = process.argv.slice(2);
if (!files.length) files.push('animate.css', 'animate.min.css', 'animate.compat.css');
for (const engine of [chromium, firefox, webkit]) {
const browser = await engine.launch();
try {
for (const file of files) {
const css = fs.readFileSync(path.resolve(file), 'utf8');
const prefix = file.includes('compat') ? '' : 'animate__';
const page = await browser.newPage();
try {
for (const mode of ['normal', 'reduce', 'print']) {
await page.emulateMedia({
media: mode === 'print' ? 'print' : 'screen',
reducedMotion: mode === 'reduce' ? 'reduce' : 'no-preference',
});
await page.setContent(`<style>${css}</style>`);
const result = await page.evaluate(
async ({prefix, mode}) => {
const el = document.createElement('div');
el.textContent = 'Delayed content';
el.className = `${prefix}animated ${prefix}fadeIn ${prefix}delay-5s`;
let ended = false;
el.addEventListener('animationend', () => {
ended = true;
});
document.body.appendChild(el);
const delay = getComputedStyle(el).animationDelay;
if (mode !== 'normal') {
await Promise.race([
new Promise((resolve) =>
el.addEventListener('animationend', resolve, {once: true}),
),
new Promise((resolve) => setTimeout(resolve, 1500)),
]);
}
return {delay, ended, opacity: getComputedStyle(el).opacity};
},
{prefix, mode},
);
assert.strictEqual(
result.delay,
mode === 'normal' ? '5s' : '0s',
`${engine.name()} ${file} ${mode}`,
);
if (mode !== 'normal') {
assert(result.ended, 'animationend should still fire promptly');
assert.strictEqual(result.opacity, '1', 'Content should be visible');
}
}
} finally {
await page.close();
}
}
console.log(`PASS: ${engine.name()} normal/reduced/print delays and completion`);
} finally {
await browser.close();
}
}
})().catch((error) => {
console.error(error);
process.exitCode = 1;
});