Skip to content

Commit b3c14b2

Browse files
authored
fix(main.ts style.css): add animation to sidebar dropdown menu (#452)
1 parent 4c6bee3 commit b3c14b2

File tree

2 files changed

+37
-8
lines changed

2 files changed

+37
-8
lines changed

src/main.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ const dropDownElements = document.querySelectorAll('.dropdown');
121121
const getDegreeElement = getRange('animation');
122122
const getRadioButtonSetElement = getRadioButtonSet('animation');
123123
const getDurationElement = getInputSpinner('animation');
124-
const events = ["dragover", "drop"];
124+
const events = ['dragover', 'drop'];
125125

126126
if (openSidePanelButton) {
127127
openSidePanelButton.style.display = 'none';
@@ -333,10 +333,10 @@ document.addEventListener('click', (e: Event) => {
333333
});
334334

335335
// Disable file opening in browser
336-
for ( let event of events) {
336+
for (let event of events) {
337337
document.addEventListener(event, (e) => {
338338
e.preventDefault();
339-
})
339+
});
340340
}
341341

342342
// clicking on the menu icon should close the nav bar
@@ -432,6 +432,28 @@ getRadioButtonSetElement.forEach((radioButton: HTMLInputElement) => {
432432

433433
// configuring dropdown menu
434434
dropDownElements.forEach((dropDown) => {
435+
// add click event listener to the dropdown parent element
436+
dropDown.addEventListener('click', (e) => {
437+
// keep dropdown open when a subitem is clicked on
438+
e.stopPropagation();
439+
const target = e.target as HTMLElement;
440+
if (!dropDown.children[0].innerHTML.includes(target.outerHTML)) return;
441+
442+
const listElement = dropDown.lastElementChild as HTMLElement;
443+
if (listElement.id === 'showList') {
444+
listElement.id = '';
445+
return;
446+
}
447+
448+
// clear other open dropdown menus
449+
dropDownElements.forEach((dropdown) => {
450+
const listElement = dropdown.lastElementChild as HTMLElement;
451+
listElement.id = '';
452+
});
453+
454+
listElement.id = 'showList';
455+
});
456+
435457
const listElement = dropDown.lastElementChild as HTMLElement;
436458

437459
// loop through children of dropdown and add event listener to each child

src/style.css

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,19 +115,26 @@ nav ul {
115115
.dropdown > ul {
116116
visibility: hidden;
117117
position: relative;
118-
height: 0px;
118+
max-height: 0px;
119+
opacity: 0;
120+
transform: scaley(0);
121+
transform-origin: 50% 0;
122+
margin-bottom: 10px;
119123
}
120124

121125
.dropdown > ul {
122-
transition: 350ms transform;
126+
transition-property: transform, max-height, opacity;
127+
transition-duration: 350ms;
128+
/* transition: transform 350ms, max-height 350ms, opacity 350ms; */
123129
transition-timing-function: ease-in-out;
124130
}
125131

126-
.dropdown:hover > ul,
132+
/* .dropdown:hover > ul, */
127133
#showList {
128134
visibility: visible;
129-
height: fit-content;
130-
transform: translateX(10px);
135+
max-height: 50px;
136+
opacity: 1;
137+
transform: scale(1) translateX(10px);
131138
}
132139

133140
#category {

0 commit comments

Comments
 (0)