Refactoring dropdown.vue so that dropdownMobile calls openDropdown and closeDropdown

This commit is contained in:
alexthomson1
2020-01-25 18:28:26 -07:00
parent 9bfc76cd20
commit ab4009bd32

View File

@@ -811,9 +811,7 @@ export default {
} }
}, },
dropdownMobile (click) { dropdownMobile (click) {
this.dropdown(click.currentTarget.parentElement); const element = click.currentTarget.parentElement;
},
dropdown (element) {
const droppedElement = document.getElementsByClassName('down')[0]; const droppedElement = document.getElementsByClassName('down')[0];
if (droppedElement && droppedElement !== element) { if (droppedElement && droppedElement !== element) {
droppedElement.classList.remove('down'); droppedElement.classList.remove('down');
@@ -821,9 +819,11 @@ export default {
droppedElement.lastChild.style.maxHeight = 0; droppedElement.lastChild.style.maxHeight = 0;
} }
} }
if (element.classList.contains('down')) {
element.classList.toggle('down'); this.closeDropdown(element);
element.lastChild.style.maxHeight = element.classList.contains('down') ? `${element.lastChild.scrollHeight}px` : 0; } else {
this.openDropdown(element);
}
}, },
closeDropdown (element) { closeDropdown (element) {
element.classList.remove('down'); element.classList.remove('down');