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
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,12 @@

<% if (respectUserColorScheme) { %>
queryPrefersDark.addEventListener("change", e => {
if(window.localStorage.getItem("quarto-color-scheme") !== null)
return;
const alternate = e.matches
const alternate = e.matches;
if (window.localStorage.getItem("quarto-color-scheme") !== null) {
window.localStorage.removeItem("quarto-color-scheme");
}
toggleColorMode(alternate);
localAlternateSentinel = e.matches ? 'alternate' : 'default'; // this is used alongside local storage!
localAlternateSentinel = alternate ? 'alternate' : 'default';
toggleGiscusIfUsed(alternate, darkModeDefault);
});
<% } %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ test('Project specifies dark and light brands, dynamic respect-user-color-scheme
});


test('Project specifies dark and light brands, do not respect-user-color-scheme after toggling', async ({ page }) => {
test('Project specifies dark and light brands, manual override expires on system theme change', async ({ page }) => {
await page.goto('./html/dark-brand/project-dark/simple-respect-color-scheme.html');
const locatr = await page.locator('body').first();
await expect(locatr).toHaveClass(`fullcontent quarto-dark`);
Expand All @@ -100,8 +100,10 @@ test('Project specifies dark and light brands, do not respect-user-color-scheme
await check_backgrounds(page, 'quarto-light', blue, red);
await check_toggle(page, true);

// After the system theme changes, the manual override expires
// and the page follows the system again
await page.emulateMedia({ colorScheme: 'light' });
await expect(locatr).toHaveClass(`fullcontent quarto-dark`);
await expect(locatr).toHaveCSS('background-color', red);
await check_toggle(page, true);
await expect(locatr).toHaveClass(`fullcontent quarto-light`);
await expect(locatr).toHaveCSS('background-color', blue);
await check_toggle(page, false);
});
Loading