mirror of
https://github.com/facebook/docusaurus.git
synced 2025-04-29 18:27:56 +02:00
fix(theme): only render secondaryMenu if it should be shown (#10705)
Co-authored-by: sebastien <lorber.sebastien@gmail.com>
This commit is contained in:
parent
396deedba4
commit
a6ef3897e0
1 changed files with 27 additions and 5 deletions
|
@ -5,19 +5,37 @@
|
||||||
* LICENSE file in the root directory of this source tree.
|
* LICENSE file in the root directory of this source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import React, {type ReactNode} from 'react';
|
import React, {version, type ReactNode} from 'react';
|
||||||
import clsx from 'clsx';
|
import clsx from 'clsx';
|
||||||
import {useNavbarSecondaryMenu} from '@docusaurus/theme-common/internal';
|
import {useNavbarSecondaryMenu} from '@docusaurus/theme-common/internal';
|
||||||
import {ThemeClassNames} from '@docusaurus/theme-common';
|
import {ThemeClassNames} from '@docusaurus/theme-common';
|
||||||
import type {Props} from '@theme/Navbar/MobileSidebar/Layout';
|
import type {Props} from '@theme/Navbar/MobileSidebar/Layout';
|
||||||
|
|
||||||
function NavbarMobileSidebarPanel({children}: {children: ReactNode}) {
|
// TODO Docusaurus v4: remove temporary inert workaround
|
||||||
|
// See https://github.com/facebook/react/issues/17157
|
||||||
|
// See https://github.com/radix-ui/themes/pull/509
|
||||||
|
function inertProps(inert: boolean) {
|
||||||
|
const isBeforeReact19 = parseInt(version!.split('.')[0]!, 10) < 19;
|
||||||
|
if (isBeforeReact19) {
|
||||||
|
return {inert: inert ? '' : undefined};
|
||||||
|
}
|
||||||
|
return {inert};
|
||||||
|
}
|
||||||
|
|
||||||
|
function NavbarMobileSidebarPanel({
|
||||||
|
children,
|
||||||
|
inert,
|
||||||
|
}: {
|
||||||
|
children: ReactNode;
|
||||||
|
inert: boolean;
|
||||||
|
}) {
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={clsx(
|
className={clsx(
|
||||||
ThemeClassNames.layout.navbar.mobileSidebar.panel,
|
ThemeClassNames.layout.navbar.mobileSidebar.panel,
|
||||||
'navbar-sidebar__item menu',
|
'navbar-sidebar__item menu',
|
||||||
)}>
|
)}
|
||||||
|
{...inertProps(inert)}>
|
||||||
{children}
|
{children}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -40,8 +58,12 @@ export default function NavbarMobileSidebarLayout({
|
||||||
className={clsx('navbar-sidebar__items', {
|
className={clsx('navbar-sidebar__items', {
|
||||||
'navbar-sidebar__items--show-secondary': secondaryMenuShown,
|
'navbar-sidebar__items--show-secondary': secondaryMenuShown,
|
||||||
})}>
|
})}>
|
||||||
<NavbarMobileSidebarPanel>{primaryMenu}</NavbarMobileSidebarPanel>
|
<NavbarMobileSidebarPanel inert={secondaryMenuShown}>
|
||||||
<NavbarMobileSidebarPanel>{secondaryMenu}</NavbarMobileSidebarPanel>
|
{primaryMenu}
|
||||||
|
</NavbarMobileSidebarPanel>
|
||||||
|
<NavbarMobileSidebarPanel inert={!secondaryMenuShown}>
|
||||||
|
{secondaryMenu}
|
||||||
|
</NavbarMobileSidebarPanel>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Reference in a new issue