最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - overriding default hover on react-pro-sidebar - Stack Overflow

programmeradmin1浏览0评论

I'm working with react-pro-sidebar for making a sidebar for my project react web app. Based on mockup, sidebar must hover item like this.

Then, I'm using styled-ponent for hovering.

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

and also my code goes like this.

 <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>

But it doesn't affect hovering item. It's still default hover by react-sidebar-pro

So, is there any way for overriding default hover for react-sidebar-pro ? Any help will be appreciated. Thank you.

I'm working with react-pro-sidebar for making a sidebar for my project react web app. Based on mockup, sidebar must hover item like this.

Then, I'm using styled-ponent for hovering.

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

and also my code goes like this.

 <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>

But it doesn't affect hovering item. It's still default hover by react-sidebar-pro

So, is there any way for overriding default hover for react-sidebar-pro ? Any help will be appreciated. Thank you.

Share Improve this question edited Dec 19, 2022 at 6:23 Osanda Gamage 5222 gold badges7 silver badges20 bronze badges asked Dec 15, 2022 at 3:41 github.ariefgithub.arief 1532 silver badges9 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 3

Not an ideal solution but I eventually downgraded to 1.0.0-alpha.7 and used the following code instead...

<Sidebar>
  <Menu
    renderMenuItemStyles={() => ({
      '.menu-anchor': {
            backgroundColor: 'red',
            '&:hover': {
              backgroundColor: 'green',
            },
        },
      })}
  >
    <MenuItem> Calendar </MenuItem>
  </Menu>
</Sidebar>
         <Menu
          menuItemStyles={{
            button: ({ level, active, disabled }) => {
              if (level === 0) {
                return {
                  color: disabled ? "#eee" : "#455A64",
                  backgroundColor: active ? "#fff" : undefined,
                  "&:hover": {
                     backgroundColor: "#335B8C !important",
                     color: "white !important",
                     borderRadius: "8px !important",
                     fontWeight: "bold !important"
                   },
                };
              }
            },
          }}
        >
The button element inside the Menu Component should be used to give the intended hovering effect.

   <Sidebar>
    <Menu
      button: {
        '&:hover': {
           backgroundColor: #335B8C !important;
           color: white !important;
           borderRadius: 8px !important;
           fontWeight: bold !important;
        }
     }
   >
    <MenuItem> Calendar </MenuItem>
  </Menu>
</Sidebar>
发布评论

评论列表(0)

  1. 暂无评论