Skip to content

Commit

Permalink
Query filters: Fix scrollbar overlaying dropdown menu (#473)
Browse files Browse the repository at this point in the history
  • Loading branch information
renintw authored Oct 16, 2023
1 parent 17f932d commit 2f37a46
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions mu-plugins/blocks/query-filter/src/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,30 @@ const focusableSelectors = [
'[tabindex]:not([tabindex^="-"])',
];

/**
* Toggles the overflow-x style of the query filter between 'hidden' and 'scroll'.
*
* In certain themes (e.g., showcase), an 'overflow-x: scroll' is added on mobile screens to always display
* the horizontal scrollbar, indicating to users that there's more content to the right.
* However, this persistent display feature causes the dropdown menu to be overlaid by the scrollbar
* when opened (See issue https://github.com/WordPress/wporg-mu-plugins/issues/467#issuecomment-1754349676).
* This function serves to address that issue.
*
*/
function toggleOverflowX() {
const filtersElement = document.querySelector( '.wporg-query-filters' );

if ( filtersElement ) {
const currentOverflowX = window.getComputedStyle( filtersElement ).overflowX;

if ( 'hidden' === currentOverflowX ) {
filtersElement.style.overflowX = 'scroll';
} else if ( 'scroll' === currentOverflowX || 'auto' === currentOverflowX ) {
filtersElement.style.overflowX = 'hidden';
}
}
}

function closeDropdown( store ) {
const { context } = store;
context.wporg.queryFilter.isOpen = false;
Expand All @@ -23,6 +47,8 @@ function closeDropdown( store ) {
const count = context.wporg.queryFilter.form?.querySelectorAll( 'input:checked' ).length;
updateButtons( store, count );
document.documentElement.classList.remove( 'is-query-filter-open' );

toggleOverflowX();
}

function updateButtons( store, count ) {
Expand Down Expand Up @@ -58,6 +84,7 @@ wpStore( {
} else {
context.wporg.queryFilter.isOpen = true;
document.documentElement.classList.add( 'is-query-filter-open' );
toggleOverflowX();
}
},
handleKeydown: ( store ) => {
Expand Down

0 comments on commit 2f37a46

Please sign in to comment.