Skip to content

Commit c953a7d

Browse files
committed
feat(header): Use click instead of hover for desktop dropdown-menu
Signed-off-by: Khusika Dhamar Gusti <[email protected]>
1 parent 7bf5288 commit c953a7d

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

assets/css/_partial/_header.scss

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -242,22 +242,17 @@ header {
242242
}
243243
}
244244

245-
&:hover .dropdown-menu,
246-
&:focus-within .dropdown-menu {
245+
&.active .dropdown-menu {
247246
display: block;
248247
}
249-
&:hover .dropdown-toggle i {
248+
&.active .dropdown-toggle i {
250249
@include transform(rotate(180deg));
251250
}
252-
&:hover {
251+
&.active {
253252
color: $header-hover-color;
254253
[theme=dark] & { color: $header-hover-color-dark; }
255254
}
256255

257-
&.active .dropdown-toggle i {
258-
@include transform(rotate(180deg));
259-
}
260-
261256
.dropdown-item {
262257
display: block;
263258
padding: 0 .5rem !important;

assets/js/theme.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,25 @@ class Theme {
137137
if ($parentLink) $parentLink.style.fontWeight = 'bold';
138138
}
139139
});
140+
141+
this.util.forEach(document.querySelectorAll('#header-desktop .has-children > a.dropdown-toggle'), $toggle => {
142+
$toggle.addEventListener('click', function(e) {
143+
e.preventDefault();
144+
document.querySelectorAll('#header-desktop .has-children.active').forEach($open => {
145+
if ($open !== $toggle.parentElement) $open.classList.remove('active');
146+
});
147+
$toggle.parentElement.classList.toggle('active');
148+
});
149+
});
150+
151+
document.addEventListener('click', function(e) {
152+
const $dropdowns = document.querySelectorAll('#header-desktop .has-children');
153+
$dropdowns.forEach($dropdown => {
154+
if (!$dropdown.contains(e.target)) {
155+
$dropdown.classList.remove('active');
156+
}
157+
});
158+
});
140159
}
141160

142161
initSwitchTheme() {
@@ -799,9 +818,9 @@ class Theme {
799818
this.initSVGIcon();
800819
this.initTwemoji();
801820
this.initMenuMobile();
821+
this.initDesktopMenu();
802822
this.initSwitchTheme();
803823
this.initSearch();
804-
this.initDesktopMenu();
805824
this.initDetails();
806825
this.initLightGallery();
807826
this.initHighlight();

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"scripts": {
2020
"build": "rm -f -r exampleSite/public && hugo --source=exampleSite --gc",
2121
"build-lunr-segmentit": "browserify src/lib/lunr.segmentit.js -o assets/lib/lunr/lunr.segmentit.js -t babelify --presets @babel/preset-env --presets minify",
22-
"purgejs": "npx mkdirp exampleSite/assets/js && sed '652,656d;674,723d;726,729d;815d' assets/js/theme.js > exampleSite/assets/js/theme.js",
22+
"purgejs": "npx mkdirp exampleSite/assets/js && sed '671,675d;693,742d;745,748d;834d' assets/js/theme.js > exampleSite/assets/js/theme.js",
2323
"deploy": "npm run purgejs && hugo --source=exampleSite --gc --minify && rm -rf exampleSite/assets/js",
2424
"start": "hugo server --source=exampleSite -D --disableFastRender",
2525
"start-production": "hugo server --source=exampleSite -D --disableFastRender -e production",

0 commit comments

Comments
 (0)