javascript - 覆盖react-pro-sidebar上的默认悬停

标签 javascript reactjs react-hooks web-frontend react-sidebar

我正在使用react-pro-sidebar为我的项目react web应用程序制作侧边栏。基于模型,侧边栏必须像这样悬停项目。

enter image description here

然后,我使用 styled-component 进行悬停。

const Menuitem = styled(MenuItem)`
    :hover  {
        background-color: #335B8C !important;
        color: white !important;
        border-radius: 8px !important;
        font-weight: bold !important;
    }
`;

我的代码也是这样的。

 <SidebarWrapper>
      <SidebarBrand>
        <img src={Logo} width="150" />
      </SidebarBrand>
      <ProSidebarProvider>
        <Menu
          menuItemStyles={{
            button: ({ level, active, disabled }) => {
              if (level === 0) {
                return {
                  color: disabled ? "#eee" : "#455A64",
                  backgroundColor: active ? "#fff" : undefined,
                };
              }
            },
          }}
        >
          <Menuitem
            routerLink={
              <Link to="/" className="sidebar-link txt-blue-grey-800" />
            }
          >
            <FontAwesomeIcon icon={faHome} />
            Dashboard
          </Menuitem>
          <p
            className="text-uppercase txt-blue-grey-700 text-bold base-sm"
            style={{ marginRight: 5 }}
          >
            Layanan Pasien
          </p>
          <Menuitem
            routerLink={
              <Link to="/antrian-pasien" className="txt-blue-grey-800" />
            }
          >
            <FontAwesomeIcon icon={faHome} />
            Antrian Pasien
          </Menuitem>

但它不影响悬停项目。它仍然是react-sidebar-pro的默认悬停

enter image description here

那么,有什么方法可以覆盖react-sidebar-pro的默认悬停吗?任何帮助将不胜感激。谢谢。

最佳答案

这不是一个理想的解决方案,但我最终降级到 1.0.0-alpha.7 并使用以下代码......

<Sidebar>
  <Menu
    renderMenuItemStyles={() => ({
      '.menu-anchor': {
            backgroundColor: 'red',
            '&:hover': {
              backgroundColor: 'green',
            },
        },
      })}
  >
    <MenuItem> Calendar </MenuItem>
  </Menu>
</Sidebar>

关于javascript - 覆盖react-pro-sidebar上的默认悬停,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74806596/

相关文章:

javascript - 如何在 HighChart 中添加系列

javascript - JS获取一个字符串经过表达式替换几次

reactjs - React 网页和 Azure API 之间的 CORS 问题

reactjs - 在 react 中从两个连接的api形成一个数组

reactjs - 如何使用 React Hooks 将焦点集中在下一个渲染上

reactjs - 将对象添加到数组(使用 React 中的 Hooks)

javascript - setTimeout() 目标函数永远不会触发

reactjs - react : declaration merging for react-table types doesn't work. 类型 'TableInstance' 上不存在属性

javascript - 如何在 React useEffect hook 中获取更新的状态值

javascript - 在小窗口或移动设备上查看时,我的 Bootstrap 固定顶部导航栏不会显示所有下拉元素