Skip to content

Commit

Permalink
Revert "Navigation: Refactor mobile overlay breakpoints to JS (#57520)"
Browse files Browse the repository at this point in the history
This reverts commit 1b75cf6.
  • Loading branch information
cbravobernal committed Feb 19, 2024
1 parent 280c5d7 commit cd4e8da
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 58 deletions.
2 changes: 0 additions & 2 deletions packages/block-library/src/navigation/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,3 @@ export const SELECT_NAVIGATION_MENUS_ARGS = [
'wp_navigation',
PRELOADED_NAVIGATION_MENUS_QUERY,
];

export const NAVIGATION_MOBILE_COLLAPSE = '600px';
12 changes: 1 addition & 11 deletions packages/block-library/src/navigation/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import {
import { __, sprintf } from '@wordpress/i18n';
import { speak } from '@wordpress/a11y';
import { close, Icon } from '@wordpress/icons';
import { useInstanceId, useMediaQuery } from '@wordpress/compose';
import { useInstanceId } from '@wordpress/compose';

/**
* Internal dependencies
Expand Down Expand Up @@ -71,7 +71,6 @@ import MenuInspectorControls from './menu-inspector-controls';
import DeletedNavigationWarning from './deleted-navigation-warning';
import AccessibleDescription from './accessible-description';
import AccessibleMenuDescription from './accessible-menu-description';
import { NAVIGATION_MOBILE_COLLAPSE } from '../constants';
import { unlock } from '../../lock-unlock';

function Navigation( {
Expand Down Expand Up @@ -298,14 +297,6 @@ function Navigation( {
[ clientId ]
);
const isResponsive = 'never' !== overlayMenu;
const isMobileBreakPoint = useMediaQuery(
`(max-width: ${ NAVIGATION_MOBILE_COLLAPSE })`
);

const isCollapsed =
( 'mobile' === overlayMenu && isMobileBreakPoint ) ||
'always' === overlayMenu;

const blockProps = useBlockProps( {
ref: navRef,
className: classnames(
Expand All @@ -319,7 +310,6 @@ function Navigation( {
'is-vertical': orientation === 'vertical',
'no-wrap': flexWrap === 'nowrap',
'is-responsive': isResponsive,
'is-collapsed': isCollapsed,
'has-text-color': !! textColor.color || !! textColor?.class,
[ getColorClassName( 'color', textColor?.slug ) ]:
!! textColor?.slug,
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/navigation/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ $color-control-label-height: 20px;
// These needs extra specificity in the editor.
.wp-block-navigation__responsive-container:not(.is-menu-open) {
.components-button.wp-block-navigation__responsive-container-close {
.is-collapsed & {
@include break-small {
display: none;
}
}
Expand Down
34 changes: 16 additions & 18 deletions packages/block-library/src/navigation/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -611,19 +611,18 @@ button.wp-block-navigation-item__content {
}
}

// When the menu is collapsed, the menu button is visible.
// We are using the > selector combined with the :not(is-collapsed) selector
// as a way to target the class being added to the parent nav element.
:not(.is-collapsed) > & {
&:not(.is-menu-open) {
display: block;
width: 100%;
position: relative;
z-index: auto;
background-color: inherit;

.wp-block-navigation__responsive-container-close {
display: none;
@include break-small() {
&:not(.hidden-by-default) {
&:not(.is-menu-open) {
display: block;
width: 100%;
position: relative;
z-index: auto;
background-color: inherit;

.wp-block-navigation__responsive-container-close {
display: none;
}
}
}

Expand Down Expand Up @@ -687,11 +686,10 @@ button.wp-block-navigation-item__content {
font-size: inherit;
}

// When the menu is collapsed, the menu button is visible.
// We are using the > selector combined with the :not(is-collapsed) selector
// as a way to target the class being added to the parent nav element.
:not(.is-collapsed) > & {
display: none;
&:not(.always-shown) {
@include break-small {
display: none;
}
}
}

Expand Down
26 changes: 0 additions & 26 deletions packages/block-library/src/navigation/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
*/
import { store, getContext, getElement } from '@wordpress/interactivity';

/**
* Internal dependencies
*/
import { NAVIGATION_MOBILE_COLLAPSE } from './constants';

const focusableSelectors = [
'a[href]',
'input:not([disabled]):not([type="hidden"]):not([aria-hidden])',
Expand Down Expand Up @@ -201,27 +196,6 @@ const { state, actions } = store(
focusableElements?.[ 0 ]?.focus();
}
},
initNav() {
const context = getContext();
const mediaQuery = window.matchMedia(
`(max-width: ${ NAVIGATION_MOBILE_COLLAPSE })`
);

// Run once to set the initial state.
context.isCollapsed = mediaQuery.matches;

function handleCollapse( event ) {
context.isCollapsed = event.matches;
}

// Run on resize to update the state.
mediaQuery.addEventListener( 'change', handleCollapse );

// Remove the listener when the component is unmounted.
return () => {
mediaQuery.removeEventListener( 'change', handleCollapse );
};
},
},
},
{ lock: true }
Expand Down

0 comments on commit cd4e8da

Please sign in to comment.