Skip to content

Commit df49387

Browse files
committed
refactor: update the sidebar to show scrollbar properly
1 parent 14d9d2d commit df49387

File tree

2 files changed

+19
-33
lines changed

2 files changed

+19
-33
lines changed

src/components/AppSidebar.js

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
CSidebarBrand,
88
CSidebarFooter,
99
CSidebarHeader,
10-
CSidebarNav,
1110
CSidebarToggler,
1211
} from '@coreui/react'
1312
import CIcon from '@coreui/icons-react'
@@ -17,9 +16,6 @@ import { AppSidebarNav } from './AppSidebarNav'
1716
import { logo } from 'src/assets/brand/logo'
1817
import { sygnet } from 'src/assets/brand/sygnet'
1918

20-
import SimpleBar from 'simplebar-react'
21-
import 'simplebar-react/dist/simplebar.min.css'
22-
2319
// sidebar nav config
2420
import navigation from '../_nav'
2521

@@ -31,7 +27,7 @@ const AppSidebar = () => {
3127
return (
3228
<CSidebar
3329
className="border-end"
34-
colorScheme="dark"
30+
colorScheme="light"
3531
position="fixed"
3632
unfoldable={unfoldable}
3733
visible={sidebarShow}
@@ -50,12 +46,7 @@ const AppSidebar = () => {
5046
onClick={() => dispatch({ type: 'set', sidebarShow: false })}
5147
/>
5248
</CSidebarHeader>
53-
54-
<CSidebarNav>
55-
<SimpleBar>
56-
<AppSidebarNav items={navigation} />
57-
</SimpleBar>
58-
</CSidebarNav>
49+
<AppSidebarNav items={navigation} />
5950
<CSidebarFooter className="border-top d-none d-lg-flex">
6051
<CSidebarToggler
6152
onClick={() => dispatch({ type: 'set', sidebarUnfoldable: !unfoldable })}

src/components/AppSidebarNav.js

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import React from 'react'
2-
import { NavLink, useLocation } from 'react-router-dom'
2+
import { NavLink } from 'react-router-dom'
33
import PropTypes from 'prop-types'
44

5-
import { CBadge } from '@coreui/react'
5+
import SimpleBar from 'simplebar-react'
6+
import 'simplebar-react/dist/simplebar.min.css'
7+
8+
import { CBadge, CNavLink, CSidebarNav } from '@coreui/react'
69

710
export const AppSidebarNav = ({ items }) => {
8-
const location = useLocation()
911
const navLink = (name, icon, badge, indent = false) => {
1012
return (
1113
<>
@@ -30,30 +32,23 @@ export const AppSidebarNav = ({ items }) => {
3032
const { component, name, badge, icon, ...rest } = item
3133
const Component = component
3234
return (
33-
<Component
34-
{...(rest.to &&
35-
!rest.items && {
36-
component: NavLink,
37-
})}
38-
key={index}
39-
{...rest}
40-
>
41-
{navLink(name, icon, badge, indent)}
35+
<Component as="div" key={index}>
36+
{rest.to || rest.href ? (
37+
<CNavLink {...(rest.to && { as: NavLink })} {...rest}>
38+
{navLink(name, icon, badge, indent)}
39+
</CNavLink>
40+
) : (
41+
navLink(name, icon, badge, indent)
42+
)}
4243
</Component>
4344
)
4445
}
46+
4547
const navGroup = (item, index) => {
4648
const { component, name, icon, items, to, ...rest } = item
4749
const Component = component
4850
return (
49-
<Component
50-
compact
51-
idx={String(index)}
52-
key={index}
53-
toggler={navLink(name, icon)}
54-
visible={location.pathname.startsWith(to)}
55-
{...rest}
56-
>
51+
<Component compact as="div" key={index} toggler={navLink(name, icon)} {...rest}>
5752
{item.items?.map((item, index) =>
5853
item.items ? navGroup(item, index) : navItem(item, index, true),
5954
)}
@@ -62,10 +57,10 @@ export const AppSidebarNav = ({ items }) => {
6257
}
6358

6459
return (
65-
<React.Fragment>
60+
<CSidebarNav as={SimpleBar}>
6661
{items &&
6762
items.map((item, index) => (item.items ? navGroup(item, index) : navItem(item, index)))}
68-
</React.Fragment>
63+
</CSidebarNav>
6964
)
7065
}
7166

0 commit comments

Comments
 (0)