Skip to content

Commit

Permalink
fix: respond to media query change events when theme is auto (#1731)
Browse files Browse the repository at this point in the history
Co-authored-by: Chris Swithinbank <swithinbank@gmail.com>
  • Loading branch information
techfg and delucis committed Apr 10, 2024
1 parent f264730 commit f08b0df
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/swift-files-wave.md
@@ -0,0 +1,5 @@
---
'@astrojs/starlight': patch
---

Fixes responding to system color scheme changes when theme is `auto`
3 changes: 3 additions & 0 deletions packages/starlight/components/ThemeSelect.astro
Expand Up @@ -42,6 +42,9 @@ const { labels } = Astro.props;
this.#onThemeChange(this.#parseTheme(e.currentTarget.value));
}
});
matchMedia(`(prefers-color-scheme: light)`).addEventListener('change', () => {
if (this.#loadTheme() === 'auto') this.#onThemeChange('auto');
});
}
}

Expand Down

0 comments on commit f08b0df

Please sign in to comment.