Skip to content
Snippets Groups Projects
Commit d7379c8e authored by Todd Dembrey's avatar Todd Dembrey
Browse files

Ensure that the dropdowns reset on clear

parent 35b69c40
No related branches found
No related tags found
No related merge requests found
...@@ -69,32 +69,38 @@ import MobileSearch from './components/mobile-search'; ...@@ -69,32 +69,38 @@ import MobileSearch from './components/mobile-search';
dropdowns.forEach(dropdown => { dropdowns.forEach(dropdown => {
$(dropdown).val(null).trigger('change'); $(dropdown).val(null).trigger('change');
$('.select2-selection.is-active').removeClass('is-active'); $('.select2-selection.is-active').removeClass('is-active');
mobileFilterPadding(dropdown);
}); });
}); });
function mobileFilterPadding (element) {
const dropdown = $(element).closest('.select2');
const openDropdown = $('.select2 .expanded');
let dropdownMargin = 0;
if(openDropdown.length > 0 && !openDropdown.hasClass('select2-container--open')){
openDropdown.removeClass('expanded');
if (dropdown.position().top > openDropdown.position().top ){
dropdownMargin = parseInt(openDropdown.css('marginBottom'));
}
openDropdown.css('margin-bottom', '0px');
}
if(dropdown.hasClass('select2-container--open')){
dropdown.addClass('expanded');
const id = $(element).closest('.select2-selection').attr('aria-owns');
const match = $(`ul#${id}`);
const positionalMatch = match.closest('.select2-container');
const margin = match.outerHeight(true);
dropdown.css('margin-bottom', `${margin}px`);
positionalMatch.css('top', positionalMatch.position().top - dropdownMargin);
}
}
// reset mobile filters if they're open past the tablet breakpoint // reset mobile filters if they're open past the tablet breakpoint
$(window).resize(function resize(){ $(window).resize(function resize(){
if ($(window).width() < 768) { if ($(window).width() < 768) {
$('.select2').on('click', (e) => { $('.select2').on('click', (e) => {
const dropdown = $(e.target).closest('.select2'); mobileFilterPadding(e.target);
const openDropdown = $('.select2 .expanded');
let dropdownMargin = 0;
if(openDropdown.length > 0 && !openDropdown.hasClass('select2-container--open')){
openDropdown.removeClass('expanded');
if (dropdown.position().top > openDropdown.position().top ){
dropdownMargin = parseInt(openDropdown.css('marginBottom'));
}
openDropdown.css('margin-bottom', '0px');
}
if(dropdown.hasClass('select2-container--open')){
dropdown.addClass('expanded');
const id = $(e.target).closest('.select2-selection').attr('aria-owns');
const match = $(`ul#${id}`);
const positionalMatch = match.closest('.select2-container');
const margin = match.outerHeight(true);
dropdown.css('margin-bottom', `${margin}px`);
positionalMatch.css('top', positionalMatch.position().top - dropdownMargin);
}
}); });
} }
}).trigger('resize'); }).trigger('resize');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment