Allow custom content above the sidebar navigation tree (For example: product/section switcher)
Is your feature request related to a problem? Please describe.
Nextra's <Layout> has no supported way to render custom content above the sidebar's page tree (inside the sidebar column, above <Menu>). This is a common pattern in docs sites that pin something above the navigation like a version dropdown, a product/section switcher, a language selector, an environment picker, etc. For example. Stripe's product switcher in its left nav column, or the Sphinx/PyData theme's version dropdown (documented pattern: "insert a version switcher at the top of the primary sidebar while keeping the default navigation below it").
Right now there's no generic extension point for this. Anything that needs to live in that specific position has no supported way to do so.
Describe the solution you'd like
A generic slot on <Layout> to render arbitrary content above the sidebar's <Menu> tree, e.g.:
<Layout
sidebar={{
// ...existing options
extra: <MyCustomComponent />
}}
...
>Rendered by Sidebar just above the <Menu>/<Collapse> tree (implementation detail maintainers would know best, could also live above the scroll area, similar to how the mobile nav's search slot sits above its <Menu>). Being a plain ReactNode slot, it would support any use case (dropdown, tabs, banner, etc.) without Nextra needing to model the specific UI.
Describe alternatives you've considered
- The
sidebarprop as it exists today only accepts layout options (autoCollapse,defaultMenuCollapseLevel,defaultOpen,toggleButton). No slot for aReactNode. - Using the
navbar/childrenslot on<Navbar>(which is supported) It Works, but it's a different visual location (top bar, not the sidebar column) than what most comparable tools use for this pattern.
Additional context
Looked at the Sidebar component (nextra-theme-docs/dist/components/sidebar.js) It reads everything from useThemeConfig() internally and renders the <Menu> tree directly, with no prop-drilled slot to inject content before it.
Thanks for maintaining Nextra. Appreciate you taking a look at this.
Source: shuding/nextra