themesberg / flowbite-react

Official React components built for Flowbite and Tailwind CSS
https://flowbite-react.com
MIT License
1.77k stars 395 forks source link

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

Open wwills2 opened 3 months ago

wwills2 commented 3 months ago

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

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

dhavalveera commented 2 months ago

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.