flowbite-react icon indicating copy to clipboard operation
flowbite-react copied to clipboard

Collapse Sidebar on small screens

Open magixus opened this issue 3 years ago • 5 comments

Describe the bug When the screen is on "xs sm md", sidebar needs to collapse

To Reproduce

  1. Add a sidebar with all its items
  2. Change the browser width to small screen
  3. Sidebar does not collapse

Expected behavior Sidebar to collapse on small screens

Screenshots sidebar

Project information:

  • Tailwind: 3.1.8
  • Flowbite: 1.4.7
  • Flowbite React: 0.0.22
  • Type: CRA

magixus avatar Aug 13 '22 19:08 magixus

@magixus Please, upgrade it to the latest flowbite-react and see it the issue still happening.

rluders avatar Aug 18 '22 14:08 rluders

@rluders I did, but still not collapsing on small screen.

{
    "flowbite": "^1.4.5",
    "flowbite-react": "0.1.10",
}

Maybe my approach is not the most sophisticated one

...
const [collapsed, setCollapsed] = useState(true)

...
{/* Navication top bar */}
<Navbar
	fluid
	rounded
	className="border-b border-gray-200 dark:border-gray-600 bg-slate-50"
>
	<div className="flex items-center">
		{/* Toggle Sidebar */}
		{collapsed ? (
			<div
				type="button"
				className="top-navigation-icon !mr-6"
				onClick={() => setCollapsed(!collapsed)}
			>
				<span className="sr-only"> Toggle sidebar</span>
				<FaOutdent size={24} />
			</div>
		) : (
			<div
				className="top-navigation-icon !mr-6"
				onClick={() => setCollapsed(!collapsed)}
			>
				<span className="sr-only"> Toggle sidebar</span>
				<FaIndent size={24} />
			</div>
		)}

...
{/* Sidebar */}
<div className="flex h-full overflow-hidden bg-white dark:bg-gray-900">
<Sidebar collapsed={collapsed} className={`shadow bg-slate-50`}>
	<Sidebar.Items>
		<Sidebar.ItemGroup>
			{routes.map(({ href, icon, title }, key) => (
				<Sidebar.Item
					key={key}
					icon={icon}
					as={Link}
					to={href}
					active={href === pathname}
					onClick={() => mainRef.current?.scrollTo({ top: 0 })}
				>
					{title}
				</Sidebar.Item>
			))}
		</Sidebar.ItemGroup>
	</Sidebar.Items>
</Sidebar>
<main>...</main>
</div>

magixus avatar Aug 27 '22 15:08 magixus

can i word on this?

Drex72 avatar Oct 10 '22 15:10 Drex72

can i work on this

Drex72 avatar Oct 10 '22 15:10 Drex72

@Drex72 sure, go ahead

rluders avatar Oct 10 '22 16:10 rluders

@rluders Screenshot 2022-10-17 200120

How is the collapsed prop in the sidebar being toggled in the index.tsx Screenshot 2022-10-17 200323

And what is the underlined code below doing.is it setting an intital state for the collapsed prop??

Drex72 avatar Oct 17 '22 18:10 Drex72

https://github.com/themesberg/flowbite-react/blob/37644b7247a35ce15df0379425139585bc8ae27f/src/lib/components/Sidebar/index.tsx#L21

Well, yep... This is definitely a bug.

rluders avatar Oct 17 '22 19:10 rluders

Anyway, basically, you will have to check how it is being declared at the SidebarContext and understand how that thing works. We pass the value to the Context so it can be changed and also be accessed from other components.

https://github.com/themesberg/flowbite-react/blob/37644b7247a35ce15df0379425139585bc8ae27f/src/lib/components/Sidebar/index.tsx#L32

Also, the same collapsed property is used to manipulate the classes (from the application theme) and add the correct ones when the collapsed is true or false.

https://github.com/themesberg/flowbite-react/blob/37644b7247a35ce15df0379425139585bc8ae27f/src/lib/theme/default.ts#L672

rluders avatar Oct 17 '22 19:10 rluders

I've made the changes and its working.The issue now is committing. I followed the contributing guide but i'm still getting an error Screenshot (40) Screenshot (41) Screenshot (42)

Drex72 avatar Oct 19 '22 01:10 Drex72

@Drex72 is it possible that you are not using the conventionalcommits rules at your commit message?

rluders avatar Oct 19 '22 06:10 rluders

I'm not familiar with it, can you give me an idea on what it is

Drex72 avatar Oct 19 '22 08:10 Drex72

@Drex72 there is the link from my previous commend and as well this video: https://www.youtube.com/watch?v=OJqUWvmf4gg

rluders avatar Oct 19 '22 11:10 rluders

I was investigating this one today, and I'm not sure that it is a bug. I mean, OK, it isn't collapsing, but I think that it would be very arbitrary from the component perspective if we add this functionality directly to it.

So, my suggestion is to add this control to your own application and change the isCollapsed property of the sidebar according to your desired behavior.

rluders avatar Nov 06 '22 10:11 rluders