Adding wrapper class around navigation to implement scroll styles/logic (https://github.com/woocommerce/woocommerce-admin/pull/5570)

This commit is contained in:
Joel Thiessen 2020-11-12 09:10:42 -08:00 committed by GitHub
parent aebd120a16
commit b8238d91dc
2 changed files with 87 additions and 73 deletions

View File

@ -2,7 +2,7 @@
* External dependencies * External dependencies
*/ */
import { __ } from '@wordpress/i18n'; import { __ } from '@wordpress/i18n';
import { useEffect, useMemo, useState } from '@wordpress/element'; import { useEffect, useMemo, useState, useRef } from '@wordpress/element';
import { compose } from '@wordpress/compose'; import { compose } from '@wordpress/compose';
import { import {
__experimentalNavigation as Navigation, __experimentalNavigation as Navigation,
@ -85,19 +85,18 @@ const Container = ( { menuItems } ) => {
[ menuItems ] [ menuItems ]
); );
const navDomRef = useRef( null );
return ( return (
<div className="woocommerce-navigation"> <div className="woocommerce-navigation">
<Header /> <Header />
<div className="woocommerce-navigation__wrapper" ref={ navDomRef }>
<Navigation <Navigation
activeItem={ activeItem ? activeItem.id : null } activeItem={ activeItem ? activeItem.id : null }
activeMenu={ activeLevel } activeMenu={ activeLevel }
onActivateMenu={ ( ...args ) => { onActivateMenu={ ( ...args ) => {
const navDomRef = document.querySelector( if ( navDomRef && navDomRef.current ) {
'.components-navigation' navDomRef.current.scrollTop = 0;
);
if ( navDomRef ) {
navDomRef.scrollTop = 0;
} }
setActiveLevel( ...args ); setActiveLevel( ...args );
@ -125,12 +124,17 @@ const Container = ( { menuItems } ) => {
title={ category.title } title={ category.title }
menu={ category.id } menu={ category.id }
parentMenu={ category.parent } parentMenu={ category.parent }
backButtonLabel={ category.backButtonLabel || null } backButtonLabel={
category.backButtonLabel || null
}
> >
{ !! primaryItems.length && ( { !! primaryItems.length && (
<NavigationGroup> <NavigationGroup>
{ primaryItems.map( ( item ) => ( { primaryItems.map( ( item ) => (
<Item key={ item.id } item={ item } /> <Item
key={ item.id }
item={ item }
/>
) ) } ) ) }
</NavigationGroup> </NavigationGroup>
) } ) }
@ -146,14 +150,20 @@ const Container = ( { menuItems } ) => {
} }
> >
{ pluginItems.map( ( item ) => ( { pluginItems.map( ( item ) => (
<Item key={ item.id } item={ item } /> <Item
key={ item.id }
item={ item }
/>
) ) } ) ) }
</NavigationGroup> </NavigationGroup>
) } ) }
{ !! secondaryItems.length && ( { !! secondaryItems.length && (
<NavigationGroup> <NavigationGroup>
{ secondaryItems.map( ( item ) => ( { secondaryItems.map( ( item ) => (
<Item key={ item.id } item={ item } /> <Item
key={ item.id }
item={ item }
/>
) ) } ) ) }
</NavigationGroup> </NavigationGroup>
) } ) }
@ -162,6 +172,7 @@ const Container = ( { menuItems } ) => {
} ) } } ) }
</Navigation> </Navigation>
</div> </div>
</div>
); );
}; };

View File

@ -22,9 +22,12 @@
z-index: 1100; //Must be greater than z-index on .woocommerce-layout__header z-index: 1100; //Must be greater than z-index on .woocommerce-layout__header
} }
.components-navigation { .woocommerce-navigation__wrapper {
overflow-y: auto; overflow-y: auto;
height: calc(100vh - #{$header-height}); height: calc(100vh - #{$header-height});
}
.components-navigation {
box-sizing: border-box; box-sizing: border-box;
} }