Skip to content

Commit 03287fd

Browse files
use user prefers-color-schema setting instead of author default
fixes #1470 use static tests for user default color scheme since we do not support dynamic change of prefers-color-scheme yet
1 parent 11ffb94 commit 03287fd

File tree

5 files changed

+60
-21
lines changed

5 files changed

+60
-21
lines changed

news/changelog-1.7.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ All changes included in 1.7:
6161
- ([#12277](https://github.com/quarto-dev/quarto-cli/pull/12277)): Provide light and dark plot and table renderings with `renderings: [light,dark]`
6262
- ([#11860](https://github.com/quarto-dev/quarto-cli/issues/11860)): ES6 modules that import other local JS modules in documents with `embed-resources: true` are now correctly embedded.
6363
- ([#1325](https://github.com/quarto-dev/quarto-cli/issues/1325)): Dark Mode pages should not flash light on reload. (Nor should Light Mode pages flash dark.)
64+
- ([#1470](https://github.com/quarto-dev/quarto-cli/issues/1470)): User preference for `prefers-color-scheme` is respected, although only on page load, not dynamically. Author preference still influences stylesheet order and therefore NoJS experience.
6465
- ([#12307](https://github.com/quarto-dev/quarto-cli/issues/12307)): Tabsets using `tabby.js` in non-boostrap html (`theme: pandoc`, `theme: none` or `minimal: true`) now correctly render reactive content when `server: shiny` is used.
6566
- ([#12356](https://github.com/quarto-dev/quarto-cli/issues/12356)): Remove duplicate id in HTML document when using `#lst-` prefix label for using Quarto crossref.
6667

src/resources/formats/html/templates/quarto-html-before-body.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@
128128
return localAlternateSentinel;
129129
}
130130
}
131-
const darkModeDefault = <%= darkModeDefault %>;
131+
const darkModeDefault = window.matchMedia('(prefers-color-scheme: dark)').matches;
132132
let localAlternateSentinel = darkModeDefault ? 'alternate' : 'default';
133133
134134
// Dark / light mode switch
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { test, expect } from '@playwright/test';
2+
3+
async function check_red_blue(page) {
4+
const locatr = await page.locator('body').first();
5+
await expect(locatr).toHaveClass('fullcontent quarto-dark');
6+
await expect(locatr).toHaveCSS('background-color', 'rgb(66, 7, 11)');
7+
await page.locator("a.quarto-color-scheme-toggle").click();
8+
const locatr2 = await page.locator('body').first();
9+
await expect(locatr2).toHaveCSS('background-color', 'rgb(204, 221, 255)');
10+
}
11+
12+
test.use({
13+
colorScheme: 'dark'
14+
});
15+
16+
// brands used in these documents have background colors
17+
18+
test('Dark and light brand after user themes', async ({ page }) => {
19+
// brand overrides theme background color
20+
await page.goto('./html/dark-brand/brand-after-theme.html');
21+
await check_red_blue(page);
22+
});
23+
24+
// project tests
25+
26+
test('Project specifies dark and light brands', async ({ page }) => {
27+
await page.goto('./html/dark-brand/project-light-dark/simple.html');
28+
await check_red_blue(page);
29+
});
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { test, expect } from '@playwright/test';
2+
3+
async function check_blue_red(page) {
4+
const locatr = await page.locator('body').first();
5+
await expect(locatr).toHaveClass('fullcontent quarto-light');
6+
await expect(locatr).toHaveCSS('background-color', 'rgb(204, 221, 255)');
7+
await page.locator("a.quarto-color-scheme-toggle").click();
8+
const locatr2 = await page.locator('body').first();
9+
await expect(locatr2).toHaveCSS('background-color', 'rgb(66, 7, 11)');
10+
}
11+
12+
test.use({
13+
colorScheme: 'light'
14+
});
15+
16+
// brands used in these documents have background colors
17+
18+
test('Dark and light brand after user themes', async ({ page }) => {
19+
// brand overrides theme background color
20+
await page.goto('./html/dark-brand/brand-after-theme.html');
21+
await check_blue_red(page);
22+
});
23+
24+
// project tests
25+
26+
test('Project specifies dark and light brands', async ({ page }) => {
27+
await page.goto('./html/dark-brand/project-light-dark/simple.html');
28+
await check_blue_red(page);
29+
});

tests/integration/playwright/tests/html-dark-mode.spec.ts

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
import { test, expect } from '@playwright/test';
22

3-
async function check_red_blue(page) {
4-
const locatr = await page.locator('body').first();
5-
await expect(locatr).toHaveClass('fullcontent quarto-dark');
6-
await expect(locatr).toHaveCSS('background-color', 'rgb(66, 7, 11)');
7-
await page.locator("a.quarto-color-scheme-toggle").click();
8-
const locatr2 = await page.locator('body').first();
9-
await expect(locatr2).toHaveCSS('background-color', 'rgb(204, 221, 255)');
10-
}
11-
123
async function check_theme_overrides(page) {
134
const locatr = await page.locator('body').first();
145
await expect(locatr).toHaveClass('fullcontent quarto-light');
@@ -19,12 +10,6 @@ async function check_theme_overrides(page) {
1910
}
2011
// themes used in these documents have background colors
2112

22-
test('Dark and light brand after user themes', async ({ page }) => {
23-
// brand overrides theme background color
24-
await page.goto('./html/dark-brand/brand-after-theme.html');
25-
await check_red_blue(page);
26-
});
27-
2813
test('Dark and light brand before user themes', async ({ page }) => {
2914
// theme will override brand
3015
await page.goto('./html/dark-brand/brand-before-theme.html');
@@ -33,11 +18,6 @@ test('Dark and light brand before user themes', async ({ page }) => {
3318

3419
// project tests
3520

36-
test('Project specifies dark and light brands', async ({ page }) => {
37-
await page.goto('./html/dark-brand/project-light-dark/simple.html');
38-
await check_red_blue(page);
39-
});
40-
4121
test('Project brand before user themes', async ({ page }) => {
4222
// theme will override brand
4323
await page.goto('./html/dark-brand/project-light-dark/brand-under-theme.html');

0 commit comments

Comments
 (0)