fix(lightDarkSwitch): set colorScheme and data-theme attributes #569
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
问题描述
通过侧边栏按钮切换明暗主题时没有设置
color-scheme和data-theme,导致切换后如果不刷新页面部分文字不会自动根据主题切换颜色,从而显示不清楚。截图说明
从 light mode 切换到 dark mode
从 dark mode 切换到 light mode
相关 issues
#563
解决方案
在
lightDarkSwitch.js中设置color-scheme和data-theme属性enableLightMode() { document.body.classList.remove("dark-mode"); document.documentElement.classList.remove("dark"); document.body.classList.add("light-mode"); document.documentElement.classList.add("light"); +document.documentElement.style.colorScheme = "light"; +document.documentElement.setAttribute("data-theme", "light"); this.iconDom.className = "fa-regular fa-moon"; main.styleStatus.isDark = false; main.setStyleStatus(); this.mermaidInit(this.mermaidLightTheme); this.setGiscusTheme(); }, enableDarkMode() { document.body.classList.remove("light-mode"); document.documentElement.classList.remove("light"); document.body.classList.add("dark-mode"); document.documentElement.classList.add("dark"); +document.documentElement.style.colorScheme = "dark"; +document.documentElement.setAttribute("data-theme", "dark"); this.iconDom.className = "fa-regular fa-brightness"; main.styleStatus.isDark = true; main.setStyleStatus(); this.mermaidInit(this.mermaidDarkTheme); this.setGiscusTheme(); },