【问题标题】:Darkmode not working on tailwind headless UI暗模式不适用于顺风无头 UI
【发布时间】:2022-12-07 11:53:40
【问题描述】:

Darkmode 在我的 React 应用程序中无处不在,除了无头 ui 组合框。我将样式化的 h1 放在同一个组件中并应用 dark:bg-red-200(和任何其他样式)没问题。组合框接受所有其他顺风实用程序,包括 hover: 之类的属性,但不接受 dark: 属性。

【问题讨论】:

    标签: reactjs tailwind-css headless-ui


    【解决方案1】:

    对于其他人(比如我)绊倒了这个:

    • 例如Dialog-component(我假设还有其他组件)在 body 标签中呈现(source
    • 如果您使用"the class strategy" 来处理暗模式(即向包装器添加“暗”类),这将是一个问题,因为该类不再是Dialog 的父类

    我最终使用的解决方案:

    我最终将 useEffect 用于add the dark class to the body

    useEffect(() => {
      if(darkMode){
        document.body.classList.add('dark')
      }else{
        document.body.classList.remove('dark')
      }
    }, [darkMode])
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-08
      • 2021-07-27
      • 2021-07-06
      • 2021-06-05
      • 2021-08-31
      • 2023-01-13
      • 2023-01-14
      • 2023-01-17
      相关资源
      最近更新 更多