Skip to content
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

fix: extends header menu to accept list props for corresponding id #188

Merged
merged 1 commit into from
May 21, 2020
Merged
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
37 changes: 31 additions & 6 deletions src/components/header/Header/Header.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ export const BasicHeader = (): React.ReactElement => {
label="Nav Label"
isCurrent={true}
/>
<Menu key="one" items={testMenuItems} isOpen={isOpen[0]} />
<Menu
key="one"
items={testMenuItems}
isOpen={isOpen[0]}
id="testDropDownOne"
/>
</>,
<a href="#two" key="two" className="usa-nav__link">
<span>Parent link</span>
Expand Down Expand Up @@ -153,18 +158,28 @@ export const BasicHeaderWithMegaMenu = (): React.ReactElement => {
label="Nav Label"
isCurrent={true}
/>
<MegaMenu key="one" items={testItemsMegaOne} isOpen={isOpen[0]} />
<MegaMenu
key="one"
items={testItemsMegaOne}
isOpen={isOpen[0]}
id="testDropDownOne"
/>
</>,
<>
<NavDropDownButton
onToggle={(): void => {
onToggle(1)
}}
menuId="testDropDownOne"
menuId="testDropDownTwo"
isOpen={isOpen[1]}
label="Nav Label"
/>
<MegaMenu key="one" items={testItemsMegaTwo} isOpen={isOpen[1]} />
<MegaMenu
key="one"
items={testItemsMegaTwo}
isOpen={isOpen[1]}
id="testDropDownTwo"
/>
</>,
<a href="#two" key="two" className="usa-nav__link">
<span>Parent link</span>
Expand Down Expand Up @@ -228,7 +243,12 @@ export const extendedHeader = (): React.ReactElement => {
label="Nav Label"
isCurrent={true}
/>
<Menu key="one" items={testMenuItems} isOpen={isOpen[0]} />
<Menu
key="one"
items={testMenuItems}
isOpen={isOpen[0]}
id="testDropDownOne"
/>
</>,
<a href="#two" key="two" className="usa-nav__link">
<span>Parent link</span>
Expand Down Expand Up @@ -310,7 +330,12 @@ export const extendedHeaderWithMegaMenu = (): React.ReactElement => {
label="Nav Label"
isCurrent={true}
/>
<MegaMenu key="one" items={testItemsMegaOne} isOpen={isOpen[0]} />
<MegaMenu
key="one"
items={testItemsMegaOne}
isOpen={isOpen[0]}
id="testDropDownOne"
/>
</>,
<a href="#two" key="two" className="usa-nav__link">
<span>Parent link</span>
Expand Down
8 changes: 5 additions & 3 deletions src/components/header/MegaMenu/MegaMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ type MegaMenuProps = {
isOpen: boolean
}

export const MegaMenu = (props: MegaMenuProps): React.ReactElement => {
const { items, isOpen } = props
export const MegaMenu = (
props: MegaMenuProps & React.HTMLAttributes<HTMLUListElement>
): React.ReactElement => {
const { items, isOpen, ...ulProps } = props
return (
<div
className="usa-nav__submenu usa-megamenu"
Expand All @@ -17,7 +19,7 @@ export const MegaMenu = (props: MegaMenuProps): React.ReactElement => {
<div className="grid-row grid-gap-4">
{items.map((listItems, i) => (
<div className="usa-col" key={`subnav_col_${i}`}>
<NavList items={listItems} megamenu={true} />
<NavList items={listItems} megamenu={true} {...ulProps} />
</div>
))}
</div>
Expand Down
8 changes: 5 additions & 3 deletions src/components/header/Menu/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ type MenuProps = {
isOpen: boolean
}

export const Menu = (props: MenuProps): React.ReactElement => {
const { items, isOpen } = props
return <NavList items={items} subnav={true} hidden={!isOpen} />
export const Menu = (
props: MenuProps & React.HTMLAttributes<HTMLUListElement>
): React.ReactElement => {
const { items, isOpen, ...listProps } = props
return <NavList items={items} subnav={true} hidden={!isOpen} {...listProps} />
}

export default Menu