fix(ui): harden theme toggle accessibility
This commit is contained in:
parent
cdb269e505
commit
b923ac8947
8 changed files with 75 additions and 9 deletions
12
src/App.tsx
12
src/App.tsx
|
|
@ -93,7 +93,7 @@ export default function App() {
|
|||
const [theme, setTheme] = useState<UiTheme>(() => {
|
||||
if (typeof window === "undefined") return "dark";
|
||||
|
||||
return resolveInitialUiTheme(window.localStorage);
|
||||
return resolveInitialUiTheme(getThemeStorage());
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
|
|
@ -113,7 +113,7 @@ export default function App() {
|
|||
|
||||
useEffect(() => {
|
||||
document.documentElement.dataset.uiTheme = theme;
|
||||
persistUiTheme(theme, window.localStorage);
|
||||
persistUiTheme(theme, getThemeStorage());
|
||||
}, [theme]);
|
||||
|
||||
useEffect(() => {
|
||||
|
|
@ -173,3 +173,11 @@ function stateIcon(state: DashboardRuntimeState["state"]): string {
|
|||
if (state === "loading") return "mdi:progress-clock";
|
||||
return "mdi:tray";
|
||||
}
|
||||
|
||||
function getThemeStorage(): Storage | undefined {
|
||||
try {
|
||||
return window.localStorage;
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue