Skip to content
Snippets Groups Projects

#3225621: Use media query event listener instead of a listener on the resize event

Closed #3225621: Use media query event listener instead of a listener on the resize event
Closed alextran requested to merge issue/drupal-3225621:drupal-3225621-3225621-11.x into 11.x
1 file
+ 5
6
Compare changes
  • Side-by-side
  • Inline
@@ -39,8 +39,8 @@
}
};
const toggleCollapsed = () => {
if (window.matchMedia('(min-width: 48em)').matches) {
const toggleCollapsed = ({ matches }) => {
if (matches) {
if ($tab.hasClass('is-horizontal') && !$tab.attr('data-width')) {
let width = 0;
@@ -68,10 +68,9 @@
});
$tab.on('click.tabs', '[data-drupal-nav-tabs-trigger]', openMenu);
$(window)
// @todo use a media query event listener https://www.drupal.org/project/drupal/issues/3225621
.on('resize.tabs', Drupal.debounce(toggleCollapsed, 150))
.trigger('resize.tabs');
const mql = window.matchMedia('(min-width: 48em)');
mql.addEventListener('change', toggleCollapsed);
toggleCollapsed(mql);
}
/**
* Initialize the tabs JS.
Loading