Skip to content

Commit

Permalink
Navigation Component: Semantically create nested lists (#25280)
Browse files Browse the repository at this point in the history
* Add ul and li in groups and menus

* update readme

* update tests
  • Loading branch information
psealock authored Sep 14, 2020
1 parent 8d05ce8 commit fa04050
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 72 deletions.
10 changes: 2 additions & 8 deletions packages/components/src/navigation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,8 @@ const MyNavigation = () => (
parentMenu="root"
title="Category"
>
<ul>
<NavigationItem
badge="1"
item="child-1"
title="Child 1"
/>
<NavigationItem item="child-2" title="Child 2" />
</ul>
<NavigationItem badge="1" item="child-1" title="Child 1" />
<NavigationItem item="child-2" title="Child 2" />
</NavigationMenu>
</Navigation>
);
Expand Down
4 changes: 2 additions & 2 deletions packages/components/src/navigation/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default function NavigationGroup( { children, className, title } ) {
const classes = classnames( 'components-navigation__group', className );

return (
<div className={ classes }>
<li className={ classes }>
{ title && (
<GroupTitleUI
as="h3"
Expand All @@ -23,6 +23,6 @@ export default function NavigationGroup( { children, className, title } ) {
</GroupTitleUI>
) }
<ul>{ children }</ul>
</div>
</li>
);
}
26 changes: 12 additions & 14 deletions packages/components/src/navigation/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default function NavigationMenu( {
const classes = classnames( 'components-navigation__menu', className );

return (
<div className={ classes }>
<MenuUI className={ classes }>
{ parentMenu && (
<MenuBackButtonUI
className="components-navigation__back-button"
Expand All @@ -48,18 +48,16 @@ export default function NavigationMenu( {
{ backButtonLabel || __( 'Back' ) }
</MenuBackButtonUI>
) }
<MenuUI>
{ title && (
<MenuTitleUI
as="h2"
className="components-navigation__menu-title"
variant="subtitle"
>
{ title }
</MenuTitleUI>
) }
{ children }
</MenuUI>
</div>
{ title && (
<MenuTitleUI
as="h2"
className="components-navigation__menu-title"
variant="subtitle"
>
{ title }
</MenuTitleUI>
) }
<ul>{ children }</ul>
</MenuUI>
);
}
32 changes: 9 additions & 23 deletions packages/components/src/navigation/stories/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,13 @@ function Example() {
parentMenu="root"
title="Category"
>
<ul>
<NavigationItem
badge="1"
item="child-1"
title="Child 1"
/>
<NavigationItem item="child-2" title="Child 2" />
<NavigationItem
navigateToMenu="nested-category"
item="child-3"
title="Nested Category"
/>
</ul>
<NavigationItem badge="1" item="child-1" title="Child 1" />
<NavigationItem item="child-2" title="Child 2" />
<NavigationItem
navigateToMenu="nested-category"
item="child-3"
title="Nested Category"
/>
</NavigationMenu>

<NavigationMenu
Expand All @@ -93,16 +87,8 @@ function Example() {
parentMenu="category"
title="Nested Category"
>
<ul>
<NavigationItem
item="sub-child-1"
title="Sub Child 1"
/>
<NavigationItem
item="sub-child-2"
title="Sub Child 2"
/>
</ul>
<NavigationItem item="sub-child-1" title="Sub Child 1" />
<NavigationItem item="sub-child-2" title="Sub Child 2" />
</NavigationMenu>
</Navigation>

Expand Down
46 changes: 21 additions & 25 deletions packages/components/src/navigation/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,34 @@ import NavigationMenu from '../menu';
const testNavigation = ( { activeItem, rootTitle, showBadge } = {} ) => (
<Navigation activeItem={ activeItem }>
<NavigationMenu title={ rootTitle }>
<ul>
<NavigationItem
badge={ showBadge && 21 }
item="item-1"
title="Item 1"
/>
<NavigationItem
href="http://example.com"
item="item-2"
target="_blank"
title="Item 2"
/>
<NavigationItem
navigateToMenu="category"
item="category"
title="Category"
/>
<NavigationItem item="item-3">
<span>customize me</span>
</NavigationItem>
</ul>
<NavigationItem
badge={ showBadge && 21 }
item="item-1"
title="Item 1"
/>
<NavigationItem
href="http://example.com"
item="item-2"
target="_blank"
title="Item 2"
/>
<NavigationItem
navigateToMenu="category"
item="category"
title="Category"
/>
<NavigationItem item="item-3">
<span>customize me</span>
</NavigationItem>
</NavigationMenu>
<NavigationMenu
backButtonLabel="Home"
menu="category"
parentMenu="root"
title="Category"
>
<ul>
<NavigationItem item="child-1" title="Child 1" />
<NavigationItem item="child-2" title="Child 2" />
</ul>
<NavigationItem item="child-1" title="Child 1" />
<NavigationItem item="child-2" title="Child 2" />
</NavigationMenu>
</Navigation>
);
Expand Down

0 comments on commit fa04050

Please sign in to comment.