Skip to content

Commit

Permalink
Navigation Component: Handle the no search results state (#27160)
Browse files Browse the repository at this point in the history
  • Loading branch information
Copons authored Nov 24, 2020
1 parent c10f11a commit eff9304
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/components/src/navigation/menu/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { useNavigationContext } from '../context';
import { useNavigationTreeMenu } from './use-navigation-tree-menu';
import NavigationBackButton from '../back-button';
import NavigationMenuTitle from './menu-title';
import NavigationSearchNoResultsFound from './search-no-results-found';
import { NavigableMenu } from '../../navigable-container';
import { MenuUI } from '../styles/navigation-styles';

Expand Down Expand Up @@ -81,7 +82,12 @@ export default function NavigationMenu( props ) {
/>

<NavigableMenu>
<ul aria-labelledby={ menuTitleId }>{ children }</ul>
<ul aria-labelledby={ menuTitleId }>
{ children }
{ search && (
<NavigationSearchNoResultsFound search={ search } />
) }
</ul>
</NavigableMenu>
</MenuUI>
</NavigationMenuContext.Provider>
Expand Down
33 changes: 33 additions & 0 deletions packages/components/src/navigation/menu/search-no-results-found.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* External dependencies
*/
import { filter } from 'lodash';

/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import { useNavigationContext } from '../context';
import { ItemBaseUI, ItemUI } from '../styles/navigation-styles';

export default function NavigationSearchNoResultsFound( { search } ) {
const {
navigationTree: { items },
} = useNavigationContext();

const resultsCount = filter( items, '_isVisible' ).length;

if ( ! search || !! resultsCount ) {
return null;
}

return (
<ItemBaseUI>
<ItemUI>{ __( 'No results found.' ) } </ItemUI>
</ItemBaseUI>
);
}

0 comments on commit eff9304

Please sign in to comment.