block

tabNavigator

Wire value: "tabNavigator"

Appears on: Documentation Topic, Tutorial (Project), Tutorial Article

1. How swift-docc-render consumes this

Grepping src/components/ for the literal string 'tabNavigator' lands on src/components/ContentNode.vue's wire-constant table (ContentNode.vue#L37-L54), whose tabNavigator key holds BlockType.tabNavigator = 'tabNavigator'. That constant is matched in the renderNode() factory function's switch (node.type) dispatch table:

case BlockType.tabNavigator: {
  // If the tabs count is more than the threshold, use vertical tabs instead.
  const vertical = node.tabs.length > TabNavigatorVerticalThreshold;
  const titles = node.tabs.map(tab => tab.title);
  const scopedSlots = node.tabs.reduce((slots, tab) => ({
    ...slots,
    [tab.title]: () => renderChildren(tab.content),
  }), {});
  return createElement(TabNavigator, {
    props: {
      titles,
      vertical,
    },
    scopedSlots,
  });
}

(ContentNode.vue#L405-L420.) TabNavigatorVerticalThreshold is a module-level constant, 7 (ContentNode.vue#L114-L115): tab navigators with more than 7 tabs are automatically switched to a vertical layout, a purely presentational decision made in the JS dispatch layer and never present on the wire. Note also that the component only ever forwards tab.title as a prop array (titles) — each tab's content array is instead converted into a Vue scoped slot keyed by that same title string, via renderChildren(tab.content). This is a delegation to a dedicated child component, TabNavigator, imported from src/components/ContentNode/TabNavigator.vue (ContentNode.vue#L29).

TabNavigator.vue's template renders a navigation strip plus a content stack:

<div class="TabNavigator" :class="[{ 'tabs--vertical': vertical }]">
  <Tabnav v-model="currentTitle" v-bind="{ position, vertical }">
    <TabnavItem v-for="title in titles" :key="title" :value="title">
      {{ title }}
    </TabnavItem>
  </Tabnav>
  <div class="tabs-content">
    <div class="tabs-content-container">
      <transition-group name="fade">
        <template v-for="title in titles">
          <div v-show="title === currentTitle" :key="title"
               :class="{ active: title === currentTitle }" class="tab-container">
            <slot :name="title" />
          </div>
        </template>
      </transition-group>
    </div>
  </div>
</div>

(TabNavigator.vue#L11-L38.) The currently selected tab lives entirely in component-local state: data() { return { currentTitle: this.titles[0] }; } (TabNavigator.vue#L72-L76), defaulting to the first tab. Tabnav is a thin v-model wrapper (src/components/Tabnav.vue) that renders a <nav class="tabnav"><ul class="tabnav-items"> and provides a selectTab callback plus the reactive activeTab getter down to each TabnavItem via Vue's provide/inject (Tabnav.vue#L23-L39). Each TabnavItem renders an <a href="#" class="tabnav-link" @click.prevent="tabnavData.selectTab(value)"> (TabnavItem.vue#L11-L23): clicking it calls selectTab, which is really this.$emit('input', value) on Tabnav (Tabnav.vue#L55-L58), which Vue's v-model binding on <Tabnav v-model="currentTitle"> turns back into an assignment to TabNavigator's own currentTitle data property. Every tab's content <div> is always present in the DOM — visibility is toggled with v-show="title === currentTitle" rather than v-if, so inactive tabs are display: none, not unmounted, and a <transition-group name="fade"> cross-fades the switch. A watch handler additionally keeps currentTitle valid if the titles array itself changes at runtime (falling back to the first remaining title, or jumping to a newly-added one) (TabNavigator.vue#L77-L91).

2. Example JSON and rendered mockup

No literal JSON fixture containing "tabNavigator" was found in either Tests/DocCArchiveTests/Fixtures/ (the only hits there are inside bundled, minified *.js app assets, not RenderNode data) or as a JSON file in Tests/SwiftDocCTests/. swift-docc's own test suite exercises this kind only via Swift-literal assertions in Tests/SwiftDocCTests/Rendering/RenderNodeTranslatorTests.swift (testTabNavigator, around lines 1111–1146) and Tests/SwiftDocCTests/Semantics/Reference/TabNavigatorTests.swift, which confirm a 3-tab navigator titled "Powers", "Exercise routines", "Hats" — the same titles used in the authoring-side doc comment example at Sources/SwiftDocC/Semantics/Reference/TabNavigator.swift, lines 19–32. The example below is hand-written to match that documented shape and the schema in Section 3.

{
  "kind": "tabNavigator",
  "tabs": [
    {
      "title": "Powers",
      "content": [
        { "type": "paragraph", "inlineContent": [
          { "type": "text", "text": "Sloths can climb, hang, and nap." }
        ] }
      ]
    },
    {
      "title": "Exercise routines",
      "content": [
        { "type": "paragraph", "inlineContent": [
          { "type": "text", "text": "A brisk stretch, then a long rest." }
        ] }
      ]
    },
    {
      "title": "Hats",
      "content": [
        { "type": "paragraph", "inlineContent": [
          { "type": "text", "text": "Newfound confidence, one fedora at a time." }
        ] }
      ]
    }
  ]
}
Powers Exercise routines Hats

Sloths can climb, hang, and nap.

mockup: only the tab matching the current selection (currentTitle, defaulting to the first tab, "Powers") is visible; the others exist in the DOM under v-show="false" and would fade/slide in via the fade transition-group on click. The active tab's link gets an underline via the .tabnav-link.active rule (see Section 4); the count of 3 tabs here is well under the vertical threshold of 7, so this renders horizontally.

3. Data sheet

Source: Sources/DocCArchive/Vendored/RenderNode.spec.json, schema object #/components/schemas/TabNavigator (lines 612–630), which is one arm of the RenderBlockContent discriminated union (referenced at spec line 435), plus the separate, recursive #/components/schemas/Tab object (lines 631–648) that each tab entry references. Cross-checked against Components.Schemas.TabNavigator and Components.Schemas.Tab in Sources/DocCArchive/generated/Types.swift (lines 3961–3987 and 3988–4010 respectively).

FieldTypeRequiredEnum values / defaultNote
kind string yes "tabNavigator" (single-value enum) Generated as KindPayload: String, Codable, Hashable, Sendable, CaseIterable { case tabNavigator = "tabNavigator" }, decoded/encoded under the Swift property name kind (no renaming needed here, unlike some other block kinds that discriminate on a property literally named type).
tabs array of Tab yes — (no minimum-count constraint in the wire schema) Generated as [Components.Schemas.Tab]. Each Tab is its own object with two required fields, title: string and content: [RenderBlockContent] (spec lines 631–648; generated as Components.Schemas.Tab.title: Swift.String and .content: [Components.Schemas.RenderBlockContent]). The wire schema places no lower bound on the array length, though swift-docc's authoring-side directive requires at least one @Tab child (see below) and DocC-render's UI implicitly assumes at least one entry since it seeds currentTitle from titles[0].

On the swift-docc production side (secondary/flavor source, not authoritative for wire shape), the enclosing enum case is case tabNavigator(TabNavigator) (Sources/SwiftDocC/Model/Rendering/Content/RenderBlockContent.swift, line 72), and the nested struct is declared at the same file, lines 825–837:

public struct TabNavigator: Codable, Equatable {
    public var tabs: [Tab]

    public struct Tab: Codable, Equatable {
        public var title: String
        public var content: [RenderBlockContent]
    }
}

This matches the wire schema field-for-field. The authoring-side semantic model, Sources/SwiftDocC/Semantics/Reference/TabNavigator.swift, is a separate type (a Semantic/AutomaticDirectiveConvertible directive, not the render type above) whose tabs property uses @ChildDirective(requirements: .oneOrMore) (lines 42–44), i.e. authoring requires at least one @Tab child even though the render-side JSON schema does not enforce a minimum. Its render(with:) method (lines 97–110) is what actually produces the wire object shown above, mapping each authored Tab (title string plus markup content) onto RenderBlockContent.TabNavigator.Tab. An author produces this kind by writing:

@TabNavigator {
   @Tab("Powers") {
      ![A diagram with the five sloth power types.](sloth-powers)
   }

   @Tab("Exercise routines") {
      ![A sloth relaxing and enjoying a good book.](sloth-exercise)
   }

   @Tab("Hats") {
      ![A sloth discovering newfound confidence after donning a fedora.](sloth-hats)
   }
}

(directive doc comment, TabNavigator.swift lines 16–32; introduced in DocC version "5.8" per introducedVersion, line 39). Each @Tab directive's unnamed argument becomes title, and its body content becomes the content block array.

DocCArchive's own transform layer does not yet do anything with this kind: MyHTMLTransformer and MyMarkdownTransformer (Sources/DocCArchive/DocCArchive.swift, lines 242–254) are still stub placeholders that return a hardcoded HTML comment and an empty string respectively for an entire RenderNode, with no per-block-kind switch reached yet — so a tabNavigator node parsed via Components.Schemas.TabNavigator is available on the decoded model today, but nothing in this repository currently converts it into HTML or Markdown output.

4. HTML/CSS mapping in DocC-Render output

Rendered DOM for a tabNavigator node, in context:

SCSS: TabNavigator.vue carries its own scoped <style> block (TabNavigator.vue#L95-L156):

The tab strip itself is styled in Tabnav.vue (Tabnav.vue#L63-L104, e.g. .tabnav--center { justify-content: center; }, .tabnav--vertical { flex-flow: column wrap; }) and in TabnavItem.vue (TabnavItem.vue#L48-L115), where the active-tab underline indicator is pure CSS:

.tabnav-item {
  border-bottom: 1px solid;
  border-color: var(--colors-tabnav-item-border-color, var(--color-tabnav-item-border-color));
}
.tabnav-link.active {
  color: var(--colors-text, var(--color-text));
  cursor: default;
  &:after { border-bottom-color: var(--colors-text, var(--color-text)); }
}

CSS custom properties consumed: --colors-tabnav-item-border-color (falling back to --color-tabnav-item-border-color, itself defined as var(--color-fill-gray) in src/styles/core/colors/_light.scss, line 179) for the resting tab-strip underline, and --colors-text/--color-text for the active tab's label color and its bolder underline; plus the shared --spacing-stacked-margin-xlarge and --spacing-stacked-margin-large spacing tokens and the generic font-styles(tabnav-link) mixin output for typography.

5. Modern CSS-only alternative

Partial

Current behavior in play: TabNavigator.vue holds the selected tab as currentTitle in component data(), seeded from titles[0], and updated only through Tabnav's v-model/$emit('input', value) chain triggered by TabnavItem's @click.prevent="tabnavData.selectTab(value)" handler. Panel visibility is driven by v-show="title === currentTitle" (a JS-computed boolean toggling inline display: none), and the active-tab label styling is driven by a class binding, :class="{ active: title === currentTitle }", whose CSS effect (color and underline via .tabnav-link.active) is itself already plain CSS once the class is present — it is only the decision of which panel/tab is active that lives in JavaScript state, not the styling of that state.

The named native mechanism that mechanically replaces this is a radio-input group with the general sibling selector: one hidden <input type="radio" name="tabNavigator-N" id="tab-N-i"> per tab (the checked one holding the "current" state natively, exactly analogous to currentTitle), paired with a <label for="tab-N-i"> standing in for each TabnavItem, and each tab's content panel given a matching id so a selector chain like #tab-N-i:checked ~ .tabs-content .tab-container:nth-of-type(N) (or, more simply, one radio per panel wrapped so a sibling-combinator rule such as #tab-N-i:checked ~ #panel-N { display: block; } applies) shows only the panel whose radio is checked. Clicking a <label> natively toggles its associated radio's :checked state with no JS, which is exactly the "swap the active tab" behavior selectTab/v-model currently performs, and :checked styling on the associated <label> (via an adjacent-sibling selector, input:checked + label) can reproduce the .tabnav-link.active underline/color treatment without any class-binding JS. The verdict is "partial" rather than "applicable" because two pieces of behavior would not transfer: the cross-fade opacity transition on switch (<transition-group name="fade">) has no direct radio-input equivalent — CSS transitions on display-toggled content don't animate the way the current opacity-based enter/leave classes do, though a @starting-style/transition-behavior: allow-discrete approach could approximate it in browsers that support it — and the runtime vertical/horizontal layout switch keyed on node.tabs.length > 7 is a value computed from wire data at render time, which CSS alone cannot inspect (a container query or :has() selector could react to the rendered DOM shape, e.g. :has(> .tabnav > .tabnav-items > :nth-child(8)), but that is a materially different mechanism than the current JS array-length check, not a drop-in replacement).