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

Query filters: Fix scrollbar overlaying dropdown menu #473

Merged
merged 2 commits into from
Oct 16, 2023
Merged
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
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();
adamwoodnz marked this conversation as resolved.
Show resolved Hide resolved
}

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();
}
adamwoodnz marked this conversation as resolved.
Show resolved Hide resolved
},
handleKeydown: ( store ) => {
Expand Down