Skip to content

Commit

Permalink
refactor(hooks): mark system as key for system theme
Browse files Browse the repository at this point in the history
  • Loading branch information
wingkwong committed Oct 9, 2024
1 parent 721f279 commit b7db3d3
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/hooks/use-theme/__tests__/use-theme.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ describe("useTheme hook", () => {
getByText("Set System").click();
});
expect(getByTestId("theme-display").textContent).toBe(ThemeProps.SYSTEM);
expect(localStorage.getItem(ThemeProps.KEY)).toBe(ThemeProps.LIGHT);
expect(localStorage.getItem(ThemeProps.KEY)).toBe(ThemeProps.SYSTEM);
expect(document.documentElement.classList.contains(ThemeProps.LIGHT)).toBe(true);
});

Expand All @@ -141,7 +141,7 @@ describe("useTheme hook", () => {
getByText("Set System").click();
});
expect(getByTestId("theme-display").textContent).toBe(ThemeProps.SYSTEM);
expect(localStorage.getItem(ThemeProps.KEY)).toBe(ThemeProps.DARK);
expect(localStorage.getItem(ThemeProps.KEY)).toBe(ThemeProps.SYSTEM);
expect(document.documentElement.classList.contains(ThemeProps.DARK)).toBe(true);
});
});
2 changes: 1 addition & 1 deletion packages/hooks/use-theme/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export function useTheme(defaultTheme: Theme = ThemeProps.SYSTEM) {
: ThemeProps.LIGHT
: newTheme;

localStorage.setItem(ThemeProps.KEY, targetTheme);
localStorage.setItem(ThemeProps.KEY, newTheme);

document.documentElement.classList.remove(theme);
document.documentElement.classList.add(targetTheme);
Expand Down

0 comments on commit b7db3d3

Please sign in to comment.