Skip to content

Commit 9486149

Browse files
committed
fix: submenu in the mobile navigation fails to expand properly #334
1 parent 74be052 commit 9486149

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

src/css/custom.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ $primary: #0033ff;
5858
opacity: 0.75;
5959
}
6060

61-
.navbar__link.bi-translate {
61+
.bi-translate {
6262
svg {
6363
display: none;
6464
}
6565
}
66-
.navbar__link.bi::before {
66+
.bi-translate::before {
6767
font-size: 24px;
6868
margin-right: 0.25rem;;
6969
}

src/theme/NavbarItem/NavbarNavLink.tsx

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
import React from 'react';
8+
import React, { useEffect } from 'react';
99
import Link from '@docusaurus/Link';
1010
import useBaseUrl from '@docusaurus/useBaseUrl';
1111
import isInternalUrl from '@docusaurus/isInternalUrl';
@@ -40,11 +40,18 @@ export default function NavbarNavLink({
4040
const normalizedHref = useBaseUrl(href, {forcePrependBaseUrl: true});
4141
const isExternalLink = label && href && !isInternalUrl(href);
4242

43-
const clickLink = (e) => {
44-
if (e.target?.lang) {
45-
localStorage.setItem('_lang_user_', e.target.lang);
46-
}
47-
}
43+
useEffect(() => {
44+
const handleClick = (event) => {
45+
if (event.target.tagName === 'A' && event.target.lang) {
46+
localStorage.setItem('_lang_user_', event.target.lang);
47+
}
48+
};
49+
document.addEventListener('click', handleClick);
50+
51+
return () => {
52+
document.removeEventListener('click', handleClick);
53+
};
54+
}, [])
4855

4956
// Link content is set through html XOR label
5057
const linkContentProps = html
@@ -68,7 +75,6 @@ export default function NavbarNavLink({
6875
href={prependBaseUrlToHref ? normalizedHref : href}
6976
{...props}
7077
{...linkContentProps}
71-
onClick={clickLink}
7278
/>
7379
);
7480
}
@@ -85,7 +91,6 @@ export default function NavbarNavLink({
8591
})}
8692
{...props}
8793
{...linkContentProps}
88-
onClick={clickLink}
8994
/>
9095
);
9196
}

0 commit comments

Comments
 (0)