Skip to content

Commit 3740287

Browse files
committed
refactor Navbar children to render as a semantic list
1 parent bc8398c commit 3740287

3 files changed

Lines changed: 33 additions & 10 deletions

File tree

packages/react-components/src/components/Navbar/Navbar.css

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,37 @@
1414
.bcds-react-aria-Navbar--Container {
1515
box-sizing: border-box;
1616
display: flex;
17+
flex-direction: row;
1718
flex-grow: 1;
19+
max-width: 1100px;
20+
}
21+
22+
.bcds-react-aria-Navbar--List {
23+
display: flex;
1824
flex-wrap: wrap;
1925
white-space: normal;
2026
align-items: center;
21-
max-width: 1100px;
27+
list-style: none;
28+
margin: unset;
29+
padding: unset;
30+
}
31+
32+
.bcds-react-aria-Navbar--Separator {
33+
display: flex;
34+
align-self: stretch;
35+
}
36+
37+
.bcds-react-aria-Navbar--Separator
38+
> .bcds-react-aria-Separator[aria-orientation="vertical"] {
39+
height: 100%;
2240
}
2341

2442
/* Sizing */
25-
.bcds-react-aria-Navbar--Container.small {
43+
.bcds-react-aria-Navbar--Container.small > .bcds-react-aria-Navbar--List {
2644
padding: var(--layout-padding-xsmall) var(--layout-padding-none);
2745
gap: var(--layout-margin-xsmall);
2846
}
29-
.bcds-react-aria-Navbar--Container.medium {
47+
.bcds-react-aria-Navbar--Container.medium > .bcds-react-aria-Navbar--List {
3048
padding: var(--layout-padding-small) var(--layout-padding-none);
3149
gap: var(--layout-margin-small);
3250
}

packages/react-components/src/components/Navbar/Navbar.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ describe("Navbar", () => {
2222
const navbar = screen.getByTestId("navbar");
2323
const button = screen.getByRole("button", { name: /button/i });
2424
const link = screen.getByRole("link", { name: /link/i });
25-
const separators = screen.getAllByRole("separator");
25+
const separators = screen.getAllByRole("separator", { hidden: true });
2626
const customChild = screen.getByTestId("custom-child");
2727

2828
it("renders the navigation container", () => {

packages/react-components/src/components/Navbar/Navbar.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,19 @@ export default function Navbar({
5151
/* Add separator between each child item */
5252
const childrenArray = React.Children.toArray(children);
5353
childrenToRender = childrenArray.flatMap((child, index) => [
54-
injectSizeToKnownChild(child, size),
54+
<li className="bcds-react-aria-Navbar--Item" key={`item-${index}`}>
55+
{injectSizeToKnownChild(child, size)}
56+
</li>,
5557
...(index < childrenArray.length - 1
5658
? [
57-
<Separator
58-
orientation="vertical"
59-
size="small"
59+
<li
60+
className="bcds-react-aria-Navbar--Separator"
6061
key={`sep-${index}`}
61-
/>,
62+
role="presentation"
63+
aria-hidden="true"
64+
>
65+
<Separator orientation="vertical" size="small" />
66+
</li>,
6267
]
6368
: []),
6469
]);
@@ -67,7 +72,7 @@ export default function Navbar({
6772
return (
6873
<div className="bcds-react-aria-Navbar">
6974
<nav className={`bcds-react-aria-Navbar--Container ${size}`} {...props}>
70-
{childrenToRender}
75+
<ul className="bcds-react-aria-Navbar--List">{childrenToRender}</ul>
7176
</nav>
7277
</div>
7378
);

0 commit comments

Comments
 (0)