Skip to content

Commit

Permalink
Fix listener
Browse files Browse the repository at this point in the history
  • Loading branch information
delucis committed Apr 10, 2024
1 parent ddcc2d3 commit 19d163f
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions packages/starlight/components/ThemeSelect.astro
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,12 @@ const { labels } = Astro.props;
this.#onThemeChange(this.#parseTheme(e.currentTarget.value));
}
});
matchMedia(`(prefers-color-scheme: light)`).addEventListener('change', this.#handleMediaQuery);
matchMedia(`(prefers-color-scheme: light)`).addEventListener('change', () => {
if (this.#loadTheme() === 'auto') this.#onThemeChange('auto');
});
}
}

#handleMediaQuery(): void {
if (this.#loadTheme() === 'auto') this.#onThemeChange('auto');
};

/** Get a typesafe theme string from any JS value (unknown values are coerced to `'auto'`). */
#parseTheme(theme: unknown): Theme {
if (theme === 'auto' || theme === 'dark' || theme === 'light') {
Expand Down

0 comments on commit 19d163f

Please sign in to comment.