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

Navigation component: Ensure setActiveMenu target exist #25367

Merged
merged 4 commits into from
Sep 18, 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
4 changes: 4 additions & 0 deletions packages/components/src/navigation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ export default function Navigation( {
const navigationTree = useCreateNavigationTree();

const setActiveMenu = ( menuId, slideInOrigin = 'left' ) => {
if ( ! navigationTree.getMenu( menuId ) ) {
return;
}

setSlideOrigin( slideInOrigin );
setMenu( menuId );
onActivateMenu( menuId );
Expand Down
5 changes: 5 additions & 0 deletions packages/components/src/navigation/stories/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ function Example() {
navigateToMenu="category"
title="Category"
/>
<NavigationItem
item="item-pointing-non-existing-menu"
title="Navigate to a non existing menu"
navigateToMenu="non-existing-menu"
/>
</NavigationGroup>
<NavigationGroup title="Group 2">
<NavigationItem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,5 @@ export const ItemBadgeUI = styled.span`

export const ItemTitleUI = styled( Text )`
margin-right: auto;
text-align: left;
`;