Skip to content

Commit

Permalink
fix: preferer color may unexpected when using auto mode (#1989)
Browse files Browse the repository at this point in the history
  • Loading branch information
kiner-tang authored Dec 18, 2023
1 parent 4246aff commit 0fa9f9c
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/client/theme-api/usePrefersColor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ class ColorChanger {
* listen color change
* @param cb callback
*/
listen(cb: typeof this.callbacks[number]) {
listen(cb: (typeof this.callbacks)[number]) {
this.callbacks.push(cb);
}

/**
* unlisten color change
* @param cb callback
*/
unlisten(cb: typeof this.callbacks[number]) {
unlisten(cb: (typeof this.callbacks)[number]) {
this.callbacks.splice(this.callbacks.indexOf(cb), 1);
}

Expand All @@ -108,7 +108,7 @@ class ColorChanger {
this.prefersColor = color;
this.color =
color === 'auto' ? (this.isColorMode('dark') ? 'dark' : 'light') : color;
document.documentElement.setAttribute(PREFERS_COLOR_ATTR, color);
document.documentElement.setAttribute(PREFERS_COLOR_ATTR, this.color);
this.applyCallbacks();

return color;
Expand Down

0 comments on commit 0fa9f9c

Please sign in to comment.