Skip to content

Commit 8805d3f

Browse files
authoredFeb 14, 2025··
fix navbar alignement on mobile when Navbar.align prop is set to left (#4214)
upd
1 parent 9b5361d commit 8805d3f

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed
 

‎.changeset/green-drinks-heal.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"nextra-theme-docs": patch
3+
---
4+
5+
- add `overflow: hidden` on `<html>` element instead of `<body>` to lock scroll when mobile nav is open
6+
- increase z-index for mobile nav from `10` to `20`, in navbar from `20` to `30`
7+
- fix navbar alignement on mobile when `Navbar.align` prop is set to `left`

‎packages/nextra-theme-docs/src/components/navbar/index.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ export const Navbar: FC<NavbarProps> = props => {
4242

4343
const logoClass = cn(
4444
'x:flex x:items-center',
45-
align === 'right' && 'x:me-auto'
45+
align === 'left' ? 'x:max-md:me-auto' : 'x:me-auto'
4646
)
4747

4848
return (
4949
<header
5050
className={cn(
51-
'nextra-navbar x:sticky x:top-0 x:z-20 x:w-full x:bg-transparent x:print:hidden',
51+
'nextra-navbar x:sticky x:top-0 x:z-30 x:w-full x:bg-transparent x:print:hidden',
5252
'x:max-md:[.nextra-banner:not([class$=hidden])~&]:top-(--nextra-banner-height)'
5353
)}
5454
>
@@ -64,7 +64,7 @@ export const Navbar: FC<NavbarProps> = props => {
6464
style={{ height: 'var(--nextra-navbar-height)' }}
6565
className={cn(
6666
'x:mx-auto x:flex x:max-w-(--nextra-content-width) x:items-center x:gap-4 x:pl-[max(env(safe-area-inset-left),1.5rem)] x:pr-[max(env(safe-area-inset-right),1.5rem)]',
67-
align === 'right' && 'x:justify-end',
67+
'x:justify-end',
6868
className
6969
)}
7070
>

‎packages/nextra-theme-docs/src/components/sidebar.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ export const MobileNav: FC = () => {
322322
className={cn(
323323
'nextra-mobile-nav', // targeted from userspace
324324
'x:flex x:flex-col',
325-
'x:fixed x:inset-0 x:pt-(--nextra-navbar-height) x:z-10 x:overscroll-contain',
325+
'x:fixed x:inset-0 x:pt-(--nextra-navbar-height) x:z-20 x:overscroll-contain',
326326
'x:[contain:layout_style]',
327327
'x:md:hidden',
328328
'x:[.nextra-banner:not([class$=hidden])~&]:pt-[calc(var(--nextra-banner-height)+var(--nextra-navbar-height))]',

‎packages/nextra-theme-docs/src/stores/menu.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ export const setMenu: Dispatch<SetStateAction<boolean>> = fn => {
1515
useMenuStore.setState(state => {
1616
const hasMenu = typeof fn === 'function' ? fn(state.hasMenu) : fn
1717
// Lock background scroll when menu is opened
18-
document.body.classList.toggle('x:max-md:overflow-hidden', hasMenu)
18+
document.documentElement.classList.toggle(
19+
'x:max-md:overflow-hidden',
20+
hasMenu
21+
)
1922
return { hasMenu }
2023
})
2124
}

0 commit comments

Comments
 (0)
Please sign in to comment.