)
}
diff --git a/packages/ui-components/src/components/SideNavigationGroup/SideNavigationGroup.stories.tsx b/packages/ui-components/src/components/SideNavigationGroup/SideNavigationGroup.stories.tsx
index ef85f5892e..d3bbb44443 100644
--- a/packages/ui-components/src/components/SideNavigationGroup/SideNavigationGroup.stories.tsx
+++ b/packages/ui-components/src/components/SideNavigationGroup/SideNavigationGroup.stories.tsx
@@ -35,11 +35,16 @@ type Story = StoryObj
export const Default: Story = {
args: {
label: "Group",
+ children: [
+ ,
+ ,
+ ,
+ ],
},
parameters: {
docs: {
description: {
- story: "Displays a simple SideNavigationGroup without children, useful for organizing items.",
+ story: "Displays a simple SideNavigationGroup with a few items, useful for organizing items.",
},
},
},
@@ -50,11 +55,11 @@ export const Expandable: Story = {
label: "Expandable Group",
children: (
<>
-
-
-
-
-
+
+
+
+
+
>
diff --git a/packages/ui-components/src/components/SideNavigationGroup/SideNavigationGroup.test.tsx b/packages/ui-components/src/components/SideNavigationGroup/SideNavigationGroup.test.tsx
index 31345887e8..cb9d2bf733 100644
--- a/packages/ui-components/src/components/SideNavigationGroup/SideNavigationGroup.test.tsx
+++ b/packages/ui-components/src/components/SideNavigationGroup/SideNavigationGroup.test.tsx
@@ -103,31 +103,52 @@ describe("SideNavigationGroup", () => {
expect(group).not.toHaveAttribute("title")
})
- test("indents the group label based on its nesting level", () => {
+ test("does not apply a level-* class to the group label", () => {
render(
-
-
-
-
-
+
)
- expect(screen.getByText("Top")).toHaveClass("level-1")
- expect(screen.getByText("Middle")).toHaveClass("level-2")
- expect(screen.getByText("Inner")).toHaveClass("level-3")
+ const label = screen.getByText("Top")
+ expect(label.className).not.toMatch(/\blevel-\d+\b/)
})
- test("propagates its level so child SideNavigationItems indent correctly", () => {
+ test("does not increment the level for its children (groups are top-level only)", () => {
render(
-
-
-
+
)
- expect(screen.getByText("Leaf")).toHaveClass("level-3")
+ expect(screen.getByText("Leaf")).toHaveClass("level-1")
+ })
+
+ test("renders as a
so it is a valid direct child of a
", () => {
+ const { container } = render()
+ const root = container.firstElementChild
+ expect(root?.tagName).toBe("LI")
+ })
+
+ test("wraps expanded children in a nested
with only
direct children", () => {
+ const { container } = render(
+
+
+
+
+ )
+
+ const nestedUls = container.querySelectorAll("ul")
+ expect(nestedUls.length).toBe(1)
+ for (const ul of nestedUls) {
+ for (const child of Array.from(ul.children)) {
+ expect(child.tagName).toBe("LI")
+ }
+ }
+ })
+
+ test("does not render a nested
when the group has no children", () => {
+ const { container } = render()
+ expect(container.querySelector("ul")).toBeNull()
})
})
diff --git a/packages/ui-components/src/components/SideNavigationItem/SideNavigationItem.component.tsx b/packages/ui-components/src/components/SideNavigationItem/SideNavigationItem.component.tsx
index b80f50b3cb..2e841b02ac 100644
--- a/packages/ui-components/src/components/SideNavigationItem/SideNavigationItem.component.tsx
+++ b/packages/ui-components/src/components/SideNavigationItem/SideNavigationItem.component.tsx
@@ -42,7 +42,7 @@ const disabledStyles = `
export interface SideNavigationItemProps extends HTMLAttributes {
/** Provides an accessibility label for the navigation item. */
ariaLabel?: string
- /** Represents nested components. If a string is passed, it will be treated as a label.*/
+ /** Nested SideNavigationItem components rendered as a sub-list when expanded. A string may be passed instead and will be treated as a label. */
children?: ReactElement | ReactElement[] | string
/** Marks the item as non-interactive if set to true. */
disabled?: boolean
@@ -149,38 +149,40 @@ export const SideNavigationItem = ({
return (
-