Sidebar
How the sidebar navigation is structured and configured.
Item Ordering
Pages within a category are sorted by the sidebar_position frontmatter field. Lower values appear first.
Pages without sidebar_position default to 999 and appear at the end of the category, sorted alphabetically by filename.
---
title: My Page
sidebar_position: 3
---Tip
Always set sidebar_position explicitly to control page order. Without it, pages are sorted alphabetically, which may not match your intended reading order.
Category Ordering
Categories in the sidebar are ordered by the sidebar_position of their index page (index.mdx). A category without a position (from its index page or a legacy _category_.json) falls back to position 999; ties sort alphabetically by directory name.
For example, to make "Getting Started" appear first and "Guides" second:
getting-started/index.mdx → sidebar_position: 0
guides/index.mdx → sidebar_position: 1
reference/index.mdx → sidebar_position: 2 Category Index Pages
Creating an index.mdx inside a directory gives the category a landing page. The category name in the sidebar becomes a clickable link to this page.
A typical category index page uses the <CategoryNav /> component to automatically list all pages in the category:
---
title: Guides
sidebar_position: 1
---
Explore our guides to learn about zudo-doc features.
<CategoryNav category="guides" />The <CategoryNav /> component renders a grid of links to all pages in the category (excluding the index itself), sorted by sidebar_position.
Linked and Heading-Only Category Rows
What a category row does depends on its index page:
| Category directory | Sidebar row | Route |
|---|---|---|
Authored index.mdx | Linked row to the landing page; title, position, and description come from its frontmatter | The authored page |
No index.mdx, but it contains pages | Linked row to a generated index page that lists the children; the label comes from the directory name | A generated auto-index route |
index.mdx with category_no_page: true | Heading-only row that expands and collapses | None |
An authored index.mdx is recommended for every category, because it gives the landing page intentional content, a label, and a position. A missing index does not make a category toggle-only. Use category_no_page: true when a group is deliberately a heading without a page.
The sidebar renders a row as a link whenever the row has an href. The hasPage flag only says whether an authored page backs the row, so it is not a test for "linked": generated auto-index rows and type: "link" items have hasPage: false and still link. Note trays are stricter and require a visible routed index.mdx.
Default Open/Closed
Categories containing the current page always open. When sidebar_initial_expansion is omitted, ordinary categories retain the existing expanded default; explicitly configured TypeScript collapsed values remain exceptions.
Set sidebar_initial_expansion: collapsed or expanded on a category's index.mdx to supply an inherited baseline. The nearest category index applies, and a field on the current page overrides it. This controls disclosure, while initialPath continues to control the initial sidebar scope.
---
title: Guides
sidebar_position: 1
sidebar_initial_expansion: collapsed
---Only explicit expand and collapse toggles by the reader are saved for the session. Automatically opening the current page's ancestors (on arrival, including Back/Forward and soft navigation, at any viewport width) and opening the root of a focused or broadened scope are not saved. The reader can collapse even the category containing the current page: it stays collapsed for that page, and hash changes, filter typing, and a reload of the same page do not reopen it. Navigating to another page reveals that page's path again, while choices in unrelated branches are kept.
Restore resets disclosure and scope to the current page's author baseline. Restore appears only when those effective values differ. At the highest scope the entire toolbar disappears, while each category's branch-focus control remains available.
Note
Saved state from earlier versions mixed automatic and manual expansion. On the first load after upgrading, that earlier expand/collapse state is discarded once; a saved scope and the filter text are kept. This does not repeat.
Sidebar Label
Use the sidebar_label frontmatter field to display a different label in the sidebar than the page title. This is useful when the full title is too long for the sidebar.
---
title: Getting Started with zudo-doc Installation
sidebar_label: Installation
sidebar_position: 2
---Tip
The sidebar_label only affects the sidebar. The page title and heading still use title.
Directory Structure
Directories inside src/ become sidebar categories. The directory name is converted from kebab-case to Title Case automatically.
src/content/docs/
getting-started/ → "Getting Started"
index.mdx → category index (sidebar_position: 0)
introduction.mdx → sidebar_position: 1
installation.mdx → sidebar_position: 2
writing-docs.mdx → sidebar_position: 3
guides/ → "Guides"
index.mdx → category index (sidebar_position: 1)
configuration.mdx → sidebar_position: 1
frontmatter.mdx → sidebar_position: 2 Nested Categories (Sub-Groups)
Subdirectories within a category directory create nested collapsible groups in the sidebar. Give each subdirectory its own index.mdx so the group row links to a real landing page:
src/content/docs/
methodology/
index.mdx → title: Methodology, sidebar_position: 1
architecture/
index.mdx → title: Architecture, sidebar_position: 1
bem-strategy.mdx
component-first.mdx
design-systems/
index.mdx → title: Design Systems, sidebar_position: 2
tight-token.mdx
two-tier-size.mdx The automatic sidebar keeps the real category nodes. Each group row is a link with a separate disclosure button, and the landing page is not repeated as a child:
Methodology (linked)
▸ Architecture (linked, collapsible)
BEM Strategy
Component First
▸ Design Systems (linked, collapsible)
Tight Token
Two-Tier SizeNo sidebar configuration is needed for this. Add category_no_page: true to a subdirectory's index.mdx only when that group should be a heading with no page of its own.
The tree is recursive and has no fixed depth limit. Keeping it shallow is a readability recommendation: when a section becomes deep, consider splitting it into another header section. To show a section's linked groups one level shallower without changing files, see Scope Recipes.
Sidebar Configuration
The automatic tree covers most sites. A section can instead be described by a configuration object, bound through the sidebarsConfig chrome slot. A configuration file is not auto-consumed.
Requires a sidebar-data binding
sidebarsConfig defaults to {}, so every section uses filesystem auto-generation. Point chromeBindingsModule at a module that binds your config. Fresh route stubs already consume it; do not edit them. See Custom Components and Host Chrome Bindings.
Create a config whose keys exactly match categoryMatch values in your headerNav, then bind it:
import type { SidebarsConfig } from "@takazudo/zudo-doc/sidebar-utils";
const sidebars: SidebarsConfig = {
guides: [
"guides/introduction",
{ type: "doc", id: "guides/sidebar", label: "Sidebar" },
{ type: "link", label: "Project site", href: "https://example.com" },
{
type: "category",
label: "Architecture",
collapsed: true,
sortOrder: "asc",
items: [{ type: "autogenerated", dirName: "guides/architecture" }],
},
],
};
export default sidebars;import { defineChromeBindings } from "@takazudo/zudo-doc/chrome-bindings";
import sidebars from "./sidebars";
export const chromeBindings = defineChromeBindings({
sidebarsConfig: sidebars,
});export default defineConfig(
zudoDoc({
chromeBindingsModule: "./src/chrome-bindings.ts",
}),
);A section without a matching key, or with an empty array, falls back to filesystem auto-generation.
Item Semantics
Each item produces rows from the automatic tree. None of them creates pages or changes URLs.
| Item or field | Result |
|---|---|
"doc/slug" or { type: "doc", id, label? } | Selects a real document as a leaf; its children are removed. A missing id is skipped. |
{ type: "link", label, href } | A linked row to any URL. |
{ type: "category", label, items, collapsed?, sortOrder? } | A synthetic heading without an href, containing the listed items. |
{ type: "autogenerated" } | The complete supplied tree, including its root rows. |
{ type: "autogenerated", dirName } | Inserts that directory's children into the visible tree. The directory row itself is not shown, though Broaden still knows it as the parent. |
initialPath | Zero-based indexes into the resolved visible tree, not URL segments. |
initialPathMode: "node" | The baseline is the selected row together with its children. |
initialPathMode: "children" (default) | The baseline is only the selected row's children. |
scopeRoot | The highest tree Broaden tree can reach. It does not create a hierarchy or change how initialPath counts. |
sidebar_initial_expansion (frontmatter) | Which branches start open. Disclosure is independent of scope. |
SidebarCategory has no link, href, id, or landing-page property. A synthetic category cannot link its heading to a page.
Listing section landing pages as strings therefore never builds a hierarchy. items: ["learn", "guides", "components"] produces three peer leaf links, and adding scopeRoot or initialPath does not change that: scopeRoot caps Broaden tree, and initialPath selects a view of the tree that already exists. To put complete sections under one linked landing page, use the umbrella tree.
Heading-Only Groups with Synthetic Categories
Use type: "category" when a group is intentionally a heading with no landing page, for example to gather a few pages under a label that has no page of its own:
import type { SidebarsConfig } from "@takazudo/zudo-doc/sidebar-utils";
const sidebars: SidebarsConfig = {
methodology: [
"methodology",
{
type: "category",
label: "Architecture",
items: [{ type: "autogenerated", dirName: "methodology/architecture" }],
},
{
type: "category",
label: "Design Systems",
items: [{ type: "autogenerated", dirName: "methodology/design-systems" }],
},
],
};
export default sidebars;This renders two levels, with headings that are not links:
Methodology (leaf link)
▸ Architecture (heading only)
BEM Strategy
Component First
▸ Design Systems (heading only)
Tight Token
Two-Tier SizeThe string
"methodology"is the category index as a leaf link. Its native children are removed, so the configuration supplies the structure.dirNamepulls the articles of each subdirectory, without the subdirectory row.The Architecture and Design Systems landing pages are no longer reachable from the sidebar.
A synthetic category never links to a landing page
Putting a landing page inside a synthetic category does not make the heading link to it. This configuration renders an unlinked "Basics" heading whose first child is a "Basics" link:
{
type: "category",
label: "Basics",
items: ["reference/basics", "reference/installation", "reference/configuration"],
}If a group has a landing page, keep the real category node (the automatic tree above), or select a shallower view with initialPath. If the pages are siblings on disk and the URLs must stay, see Editorial Navigation.
This Showcase's Configuration
The package default for sidebarsConfig is {}. This repository's own src/ is showcase configuration bound in src/: it gives each header section { items: [], scopeRoot: "configured" }. Most sections use their own filesystem tree, and Broaden tree stops at that section instead of reaching the other header sections.
Learn is the intentional exception. Learn, Guides, Components, and Markdown Features share one umbrella tree: the linked Learn row holds the three complete sections. The Learn page starts at the Learn row with its branches closed, each section page starts at its own row, and Broaden tree reaches Learn. Their sidebars.ts entries are the native fallback for an archived version, which has no Learn page.
Sort Order (Ascending / Descending)
By default, items within a category are sorted in ascending order (lowest sidebar_position first, then alphabetical). You can reverse this to descending order per category using the category_sort_order frontmatter field on the category's index.mdx:
---
title: Changelog
sidebar_position: 10
category_sort_order: "desc"
---When category_sort_order is "desc", items are sorted in reverse — highest position first, then reverse alphabetical. This is useful for date-based content (changelogs, release notes) where the newest items should appear at the top.
Note trays use the same field as their single ordering contract. The selected direction controls how stable ranks are listed in the sidebar, <NoteTrayIndex>, previous/next pager, and home-page block; the rank values themselves never change. With note_tray_sidebar: "year" or "month", groups are chronological in that direction and items inside each group follow rank. Keep sidebar_position monotonic with date so grouped dates and reading order agree. See Note Trays for the complete setup.
Note
_category_.json still works but triggers a zfb build warning. Prefer frontmatter on index.mdx for new categories.
You can also set sortOrder on a synthetic category in a bound sidebar configuration:
{
type: "category",
label: "Releases",
sortOrder: "desc",
items: [
{ type: "autogenerated" },
],
}Tip
For changelog-style categories, combine sortOrder: "desc" with date-prefixed filenames (e.g., 2026-03-10-release.mdx) for automatic newest-first ordering without manually setting sidebar_position.
Ordering Recommendations
Set
sidebar_positionon every page for predictable orderingUse
sidebar_position: 0on category index pagesUse sequential numbers (1, 2, 3...) for pages within each category
Leave gaps between numbers (e.g., 10, 20, 30) if you expect to insert pages later
Use
category_sort_order: "desc"inindex.mdxfor newest-first categoriesFor a note tray, choose
note_tray_sidebar: "index","year", or"month"; year and month require dates on every item
Broader Tree
The controls below the filter change the visible navigation tree without changing the article, reading position, or table of contents. Broaden tree moves to the immediate editorial parent. At the highest available tree the whole scope toolbar (Broaden and Restore) is hidden; there is no disabled button or hint. A custom forest can be that highest tree.
Scope (which part of the tree is shown) is separate from disclosure (which branches are open) and from structure (which rows are parents). Each category has a separate four-corner focus frame button, named “Focus sidebar on” followed by the category. Pointing at it with a mouse or reaching it with the keyboard briefly highlights exactly the branch it would show, without expanding, filtering, or moving anything; on a touch screen one tap focuses the branch directly. The frame of a branch that is already shown on its own is inactive. Category links still open pages, and disclosure buttons still expand or collapse children. The reset-arrow Restore current page’s sidebar button appears while a different scope is selected and returns to the current page’s configured roots and order. These controls also work in the mobile drawer without closing it; page links close it normally.
The filter stays in place when changing scope. A matching category keeps its subtree; a matching descendant keeps its ancestors. Branch expansion choices survive Broaden and branch focus. Restore returns to the configured baseline (including initialPathMode: "node"), clears the selected scope and the saved expand/collapse choices, keeps the filter text, and reveals the current page; a filter that excludes that page must be cleared to show it. The desktop sidebar and the mobile drawer update together. Trees remain recursive with no depth limit.
Scope is temporary session state. initialPath and initialPathMode define only the fresh/Restore baseline. Sections that share an editorial context (the same contextId for the same complete items tree, or the automatic tree) share saved state, so a broadened or focused scope the reader chose stays in effect across those pages until Restore. Following a link inside the selected tree keeps it; another branch widens to the nearest shared editorial ancestor. A saved scope whose view equals the current page's baseline is treated as the baseline, so no Restore button appears. Locale, version, or independent document-context changes return to the destination’s configured sidebar. Changed topology invalidates stored scopes. URLs and modified-click/new-tab link behavior stay native.
Explicit Editorial Context
Existing array configurations keep their initial behavior. To supply parents outside a local view, use the object form: items describes the complete editorial tree and initialPath selects the children of a category by zero-based indexes in the resolved, ordered tree. In this example the initial forest contains Background and Border; the first broader view is Surfaces & borders, followed by Utility reference. These groups need not appear in document URLs. They are synthetic, heading-only rows; to make real landing pages the parents instead, see Editorial Navigation.
import type { SidebarsConfig } from "@takazudo/zudo-doc/sidebar-utils";
const sidebars: SidebarsConfig = {
utilities: {
contextId: "utility-reference",
items: [
{
type: "category",
label: "Utility reference",
items: [
{
type: "category",
label: "Surfaces & borders",
items: ["utilities/background", "utilities/border"],
},
],
},
],
initialPath: [0, 0],
},
};
export default sidebars;Bind this object through chromeBindings.sidebarsConfig as in the configuration example above. contextId is optional; use the same value for sections that share the same complete items tree but choose different initialPath values. Locale, version, and topology revision are added automatically. Invalid paths fail the build rather than inventing parents.
Selecting the Node Itself
initialPathMode controls what initialPath selects. The default, "children", shows the children of the selected category. With "node", the selected node itself is the baseline: its row (a page-backed section keeps its overview link) with its children. navigation.roots still holds the complete editorial tree, so Broaden goes to the target's actual enclosing parent and then on up, without a duplicate or invented parent row.
import type { SidebarsConfig } from "@takazudo/zudo-doc/sidebar-utils";
const sidebars: SidebarsConfig = {
wind: {
items: [{ type: "autogenerated", dirName: "wind" }],
// Utility reference → Surfaces & borders
initialPath: [0, 0],
initialPathMode: "node",
},
};
export default sidebars;Take an autogenerated tree Wind → Utility reference → Surfaces & borders → Background color, with initialPath pointing at Surfaces & borders. On Background color, node mode first shows Surfaces & borders (linked to its overview) with its pages; Broaden then shows Utility reference, then Wind. Children mode first shows only the pages of Surfaces & borders, and the first Broaden adds the Surfaces & borders row.
A missing or empty initialPath keeps the whole resolved forest in either mode. A valid path ending at a leaf page is allowed in node mode and shows that page alone. Invalid indexes and any other initialPathMode value fail the build. Both modes apply identically to the desktop sidebar and the mobile drawer.
An object definition with empty items (items: []) uses the automatic category-filtered tree, exactly like an omitted entry, and then applies initialPath and initialPathMode to it. Both buildSidebarForSection and buildSidebarNavigation agree on the result, and invalid paths or modes fail the same way. A missing entry or an empty array keeps the plain automatic fallback.
Capping the Broadening Boundary
scopeRoot sets the highest tree Broaden tree can reach. Omit it, or set "editorial", and the sidebar keeps the behavior above: a category-filtered automatic tree can still broaden to the full automatic forest, and an autogenerated directory can still broaden through its real ancestors. "configured" makes the authored forest that ceiling.
items: []caps at the category-filtered automatic tree, including the"!"fallback.One
autogenerateditem withdirNamecaps at that directory. Its overview row and occurrence identity stay in place, andinitialPathstill counts indexes inside that directory.One
autogenerateditem withoutdirNamealready requests the full forest, so the cap does not shrink it.Several explicit items cap at that curated forest.
initialPath and initialPathMode still choose only the starting view and the Restore baseline. At the ceiling the scope toolbar is omitted. Any other scopeRoot value fails the build. An array entry and a missing entry stay editorial.
import type { SidebarsConfig } from "@takazudo/zudo-doc/sidebar-utils";
const sidebars: SidebarsConfig = {
reference: { items: [], scopeRoot: "configured" },
wind: {
items: [{ type: "autogenerated", dirName: "wind" }],
initialPath: [0, 0],
initialPathMode: "node",
scopeRoot: "configured",
},
};
export default sidebars;On a Reference page the sidebar shows Reference and its pages, with no Broaden into other header sections. A focused nested branch can still broaden back up to Reference. In the Wind example, node mode starts at Surfaces & borders; Broaden reaches Utility reference, then Wind, and stops there.
An autogenerated entry retains the provenance of its omitted directory root. Authored groupings remain authoritative, and duplicate labels or links keep separate occurrence identities. A custom forest without a shared parent stops at that forest. Header dropdown grouping is not document ancestry.
Scope Recipes
Write the visible tree down before choosing an initialPath. The examples below assume this filesystem:
guides/ (index.mdx, linked)
├── setup/ (index.mdx, linked)
│ └── install.mdx
└── writing/ (index.mdx, linked)
└── pages.mdx
reference/ (index.mdx, linked)
├── basics.mdx
└── commands.mdx Default filesystem navigation already keeps a real section root. With no entry for guides, a Guides page shows the Guides row with its children. There is no need to wrap it:
Guides (linked)
├── Setup (linked)
│ └── Install
└── Writing (linked)
└── PagesCapping Broaden at the section uses the same tree. { items: [], scopeRoot: "configured" } shows exactly the tree above; Broaden tree cannot leave Guides.
Showing linked child groups as peers. The category-filtered tree for guides contains only Guides, so [0] is Guides. Children mode shows its linked groups at the top level, and Broaden returns to the Guides row:
guides: { items: [], initialPath: [0] }Setup (linked)
└── Install
Writing (linked)
└── PagesSelecting a supplied root itself. When the visible tree is a forest you supplied, such as the one-root [Reference] forest of Editorial Navigation, autogenerated without dirName keeps that forest, and node mode selects Reference with its children:
reference: { items: [{ type: "autogenerated" }], initialPath: [0], initialPathMode: "node" }Reference (linked)
├── Basics
└── CommandsThis is correct only because the supplied tree has one root. On the native tree, { type: "autogenerated" } is the whole site forest, [Guides, Reference], so the same definition would select Guides.
dirName changes what [0] means
{ items: [{ type: "autogenerated", dirName: "reference" }], initialPath: [0] } does not select Reference. dirName inserts the children of Reference, so the visible tree is [Basics, Commands] and [0] is Basics. Children mode then shows Basics' children (nothing, because Basics is a page), and node mode shows Basics alone.
[0] is not a universal index into the global tree: always count from the visible tree that the section's items produce.
Custom integrations can call buildSidebarNavigation from @takazudo/ and pass its nodes and navigation to SidebarTree or SidebarToggle. buildSidebarForSection and nodes-only island props remain supported; nodes-only integrations keep the existing tree without scope controls.
Client Navigation Data
The native header and sidebar factories copy only the fields needed by their sidebar islands. Page descriptions remain in server navigation data for category rendering, but are omitted recursively from both visible nodes and the broader tree sent to the browser. Mobile sidebarNodes arrays and callback results are copied without remapping URLs; their object identity is not retained.
Custom hosts can call toSidebarClientData(nodes, navigation) from @takazudo/ before constructing a SidebarTree or SidebarToggle island, then pass the returned object to both SSR and hydration. The helper validates input before selecting fields and preserves occurrence IDs, topology, expansion defaults and the existing navigation context ID. Descriptions can still affect that context ID; this is payload minimization, not a privacy boundary or a change to scope persistence.