Skip to content

Commit 1fd6d32

Browse files
authored
NavList: Fix group dividers (#3328)
* Fix NavLIst.Group dividers * Use first-of-type instead of first-child * Update snapshots and stories
1 parent b1395e9 commit 1fd6d32

File tree

3 files changed

+27
-20
lines changed

3 files changed

+27
-20
lines changed

src/NavList/NavList.stories.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,18 @@ export const Simple: Story = () => (
2828

2929
export const WithGroup: Story = () => (
3030
<NavList>
31-
<NavList.Group title="Group title">
31+
<NavList.Group title="Group 1">
3232
<NavList.Item href="#" aria-current="page">
3333
Item 1
3434
</NavList.Item>
3535
<NavList.Item href="#">Item 2</NavList.Item>
3636
<NavList.Item href="#">Item 3</NavList.Item>
3737
</NavList.Group>
38+
<NavList.Group title="Group 2">
39+
<NavList.Item href="#">Item 4</NavList.Item>
40+
<NavList.Item href="#">Item 5</NavList.Item>
41+
<NavList.Item href="#">Item 6</NavList.Item>
42+
</NavList.Group>
3843
</NavList>
3944
)
4045

src/NavList/NavList.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -246,14 +246,16 @@ const defaultSx = {}
246246
// TODO: ref prop
247247
const Group: React.FC<NavListGroupProps> = ({title, children, sx: sxProp = defaultSx, ...props}) => {
248248
return (
249-
<Box as="li" sx={sxProp} {...props}>
249+
<>
250250
{/* Hide divider if the group is the first item in the list */}
251-
<ActionList.Divider as="div" sx={{'&:first-child': {display: 'none'}}} />
252-
{title && <ActionList.Heading title={title} />}
253-
<Box as="ul" sx={{paddingInlineStart: 0}}>
254-
{children}
251+
<ActionList.Divider sx={{'&:first-of-type': {display: 'none'}}} />
252+
<Box as="li" sx={sxProp} {...props}>
253+
{title && <ActionList.Heading title={title} />}
254+
<Box as="ul" sx={{paddingInlineStart: 0}}>
255+
{children}
256+
</Box>
255257
</Box>
256-
</Box>
258+
</>
257259
)
258260
}
259261

src/NavList/__snapshots__/NavList.test.tsx.snap

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ exports[`NavList renders with groups 1`] = `
407407
list-style: none;
408408
}
409409
410-
.c2:first-child {
410+
.c2:first-of-type {
411411
display: none;
412412
}
413413
@@ -701,15 +701,15 @@ exports[`NavList renders with groups 1`] = `
701701
<ul
702702
class="c1"
703703
>
704+
<li
705+
aria-hidden="true"
706+
class="c2"
707+
data-component="ActionList.Divider"
708+
role="separator"
709+
/>
704710
<li
705711
class=""
706712
>
707-
<div
708-
aria-hidden="true"
709-
class="c2"
710-
data-component="ActionList.Divider"
711-
role="separator"
712-
/>
713713
<div
714714
class="c3"
715715
>
@@ -748,15 +748,15 @@ exports[`NavList renders with groups 1`] = `
748748
</li>
749749
</ul>
750750
</li>
751+
<li
752+
aria-hidden="true"
753+
class="c2"
754+
data-component="ActionList.Divider"
755+
role="separator"
756+
/>
751757
<li
752758
class=""
753759
>
754-
<div
755-
aria-hidden="true"
756-
class="c2"
757-
data-component="ActionList.Divider"
758-
role="separator"
759-
/>
760760
<div
761761
class="c3"
762762
>

0 commit comments

Comments
 (0)