Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sidebar.Item does not show correct active background color #1354

Open
wwills2 opened this issue Apr 3, 2024 · 1 comment
Open

Sidebar.Item does not show correct active background color #1354

wwills2 opened this issue Apr 3, 2024 · 1 comment

Comments

@wwills2
Copy link

wwills2 commented Apr 3, 2024

Describe the bug
The Sidebar.Item component does not display custom tailwind css active background color after mouse click has been released, and displays the default bg-gray-100.

example:

<Sidebar.Item
  active={true}
  className={'active:bg-green-500 dark:active:bg-green-500'}
>
    This is a test item
</Sidebar.Item>

the background color of this item should be bg-green-500 because the active prop is true, but the displayed color is bg-gray-100. the bg-green-500 only shows when a mouse click is held on the item, and returns to gray as soon as the click is released

To Reproduce

  • declare a Sidebar with a Sidebar.Item
  • set the Sidebar.Item active prop to true
  • use the tailwind css className to set a custom active bg color.

Expected behavior
that the active color enumerated in the tailwind css classname should be displayed when the active prop is true regardless of whether or not there is an active mouse click event

Desktop (please complete the following information):

  • OS: Ubuntu 20.04 and MacOs Ventura 13.6.1
  • Browsers: Chromium 123.0, Firefox 124.0
@zoltanszogyenyi zoltanszogyenyi transferred this issue from themesberg/flowbite Apr 8, 2024
@dhavalveera
Copy link
Contributor

dhavalveera commented May 2, 2024

Hey @wwills2 ,

currently the className you're passing to the Sidebar.Item is being to the div element and it's not being used on the active item.

For this you can use Sidebar Theme in order to change the default bg color to your custom one. Below is a code snippet which can help you to change the bg-color of the active item.

import type { CustomFlowbiteTheme } from "flowbite-react" // this is only required if you're using TypeScript in your React/Nextjs/Remix project

// if TypeScript then use below code snippet
const customSidebarTheme: CustomFlowbiteTheme['sidebar'] = {
     // other Sidebar Theme Options based on themes link shared above,
     item: {
      active: "active:bg-green-500 dark:active:bg-green-500"
   }
}

// use below if you're using jsx
const customSidebarTheme = {
   // other Sidebar Theme Options based on themes link shared above,
   item: {
      active: "active:bg-green-500 dark:active:bg-green-500"
   }
}

return (
   <Sidebar theme={customSidebarTheme}>
       <Sidebar.Item active={true}>
            This is a test item
       </Sidebar.Item>
   </Sidebar>
)

this way you can change the default bg color to the one which you required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants