Skip to content

Fix(sidebar): remove items attribute from li element #404

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/components/AppSidebarNav.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const AppSidebarNav = ({ items }) => {
)
}
const navGroup = (item, index) => {
const { component, name, icon, to, ...rest } = item
const { component, name, icon, to, items, ...rest } = item
const Component = component
return (
<Component
Expand All @@ -47,8 +47,8 @@ export const AppSidebarNav = ({ items }) => {
visible={___location.pathname.startsWith(to)}
{...rest}
>
{item.items?.map((item, index) =>
item.items ? navGroup(item, index) : navItem(item, index),
{items?.map((item, index) =>
items ? navGroup(item, index) : navItem(item, index),
)}
</Component>
)
Expand Down
36 changes: 36 additions & 0 deletions src/components/AppSidebarNav.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React from 'react'
import { CNavGroup, CNavItem } from '@coreui/react'
import { AppSidebarNav } from './AppSidebarNav'
import { HashRouter, Route, Routes } from 'react-router-dom'
import { render } from '@testing-library/react'

test('renders nav group without items attribute', () => {
const navigation = [
{
component: CNavGroup,
name: 'Base',
to: '/base',
items: [
{
component: CNavItem,
name: 'Item',
to: '/base/item',
},
],
},
]

const { container } = render(
<HashRouter>
<Routes>
<Route path="/" element={<AppSidebarNav items={navigation} />} />
</Routes>
</HashRouter>,
)

/* eslint-disable testing-library/no-container */
/* eslint-disable testing-library/no-node-access */
const groupElement = container.querySelector('.nav-group')
expect(groupElement).toBeInTheDocument()
expect(groupElement.hasAttribute('items')).toBeFalsy()
})