Skip to content

fix: remove heading level skips from the heading outline#185

Open
adrianschmidt wants to merge 1 commit into
jgroth:mainfrom
Lundalogik:fix/heading-outline
Open

fix: remove heading level skips from the heading outline#185
adrianschmidt wants to merge 1 commit into
jgroth:mainfrom
Lundalogik:fix/heading-outline

Conversation

@adrianschmidt

@adrianschmidt adrianschmidt commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

Fixes #184. Related: #31.

What

The heading outline of a generated component page skipped levels (h1 → h3 "Examples" → h5 example titles), which violates axe's heading-order rule and makes screen-reader navigation harder. The #/debug/<tag> route had the opposite problem: no heading context at all. Together this meant no example markup heading level could be correct on both pages (details in #184).

How

The fix separates heading level (document structure) from appearance (font size) — the visual design is unchanged:

  • "Examples" section heading: h3 → h2, still sized like an h3 via .docs-layout-section-heading. The other section headings (Properties, Events, …) are deliberately left as h3: they only ever follow h3-or-lower headings, so they don't skip, and raising them would create h2 → h4 skips against their h4 children.
  • Example titles: h5 → h3 (the '##### ' prefix in the playground is now '### ', which is also what a comment in First line of text in example files automatically becomes an H5. Better if it's left for the users to decide.  #31 suggested). They keep their old h5 size via CSS custom properties that the playground sets on kompendium-markdown (--kompendium-markdown-h3-*); the fallbacks match typography.scss, so markdown rendered anywhere else is unaffected.
  • The debug route renders the same heading context as the component page: the component name as an h2 and the example title (first line of the example's docs) as an h3, both visually small since the example component is the main content on that page.

With this outline (h1 → h2 Examples → h3 example title), example markup using h4 captions is correct on both the component page and the debug page.

Notes

  • New spec tests cover all three changes (written first, watched fail).
  • Verified visually against kompendium's own docs: component pages look identical to before; the debug page gains the two small context headings.
  • Minor cosmetic limitation: the debug page's h3 renders the docs' first line as plain text, so inline markdown like backticks shows literally there (the playground still renders it as markdown).

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Debug page now displays component and example titles with proper visual hierarchy.
  • Style

    • Updated heading styles across components for improved visual hierarchy.
    • Example section headings now styled with enhanced formatting.

@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 2923ff30-d31a-4241-952f-61a94b33f0d7

📥 Commits

Reviewing files that changed from the base of the PR and between c2636ac and b11ba6a.

📒 Files selected for processing (12)
  • src/components/component-title.ts
  • src/components/component/component.tsx
  • src/components/component/templates/examples.spec.tsx
  • src/components/component/templates/examples.tsx
  • src/components/debug/debug.scss
  • src/components/debug/debug.spec.tsx
  • src/components/debug/debug.tsx
  • src/components/markdown/markdown.scss
  • src/components/playground/playground.scss
  • src/components/playground/playground.spec.tsx
  • src/components/playground/playground.tsx
  • src/style/global-layout-rules.scss

📝 Walkthrough

Walkthrough

Introduces a getComponentTitle utility to centralise tag-to-title conversion, then uses it to fix heading-level skips: ExampleList section heading is promoted from h3 to h2, playground example titles from h5 to h3, and the debug route gains new h2/h3 context headings. SCSS and tests are updated across all three surfaces.

Changes

Heading outline fix

Layer / File(s) Summary
getComponentTitle shared utility
src/components/component-title.ts, src/components/component/component.tsx
New getComponentTitle(tag) helper extracts the tag-to-title logic; KompendiumComponent.renderDocs drops its inline equivalent and calls the helper instead.
ExampleList h3 → h2 and global layout styles
src/components/component/templates/examples.tsx, src/style/global-layout-rules.scss, src/components/component/templates/examples.spec.tsx
ExampleList section heading changed to h2 with docs-layout-section-heading class; the global layout rule gains explicit font-size/line-height; new test suite asserts the h2 heading content and absence of sub-level section headings.
Playground h5 → h3 heading and matching SCSS
src/components/playground/playground.tsx, src/components/playground/playground.scss, src/components/markdown/markdown.scss, src/components/playground/playground.spec.tsx
renderResult() switches heading prefix from ##### to ###; playground.scss and markdown.scss add --kompendium-markdown-h3-* custom properties scoped to .show-case_description and blockquote h3 to preserve the previous visual sizing; new spec asserts the markdown element receives the ### … string.
Debug route context headings and styles
src/components/debug/debug.tsx, src/components/debug/debug.scss, src/components/debug/debug.spec.tsx
renderComponent extended to prepend renderHeadings output — h2 from getComponentTitle and optional h3 from the first docs line; new debug.scss styles both heading levels via .context-heading; new spec verifies h2 and h3 text content in the shadow DOM.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • jgroth

Poem

🐇 Hop, hop — the headings were out of line,
An h1 leapt to h3, then h5 — oh my!
I grabbed my carrot pen and redrew the tree:
h1 → h2 → h3, neat as can be.
The debug page now shows its title with pride,
And axe rules rejoice on the document's right side! 🌿

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: remove heading level skips from the heading outline' directly and concisely captures the main objective of the PR—fixing accessibility violations by correcting heading hierarchy.
Linked Issues check ✅ Passed All code changes align with issue #184 requirements: 'Examples' h3→h2 [examples.tsx], example titles h5→h3 [playground.tsx], and debug route context headings [debug.tsx]; all changes are properly styled using CSS to maintain visual appearance.
Out of Scope Changes check ✅ Passed All changes are directly scoped to issue #184: heading utility extraction [component-title.ts], heading structure corrections, CSS styling for visual consistency, and comprehensive test coverage; no unrelated modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

The heading outline of the generated docs skipped levels
(h1 -> h3 -> h5), which violates axe's heading-order rule and makes
screen-reader navigation harder, and the debug route rendered examples
with no heading context at all, so no example markup heading level
could be correct on both pages.

- The "Examples" section heading is now an h2 instead of an h3, but is
  still sized like an h3 (the other section headings are unchanged,
  since they only follow h3 or lower headings).
- Example titles are now h3 instead of h5, but are still sized like h5
  via custom properties that the playground sets on the markdown
  component.
- The debug route now renders the same heading context as the component
  page: the component name as a small h2 and the example title as a
  small h3.

With this, example markup using h4 captions is correct on both the
component page and the debug page.

fix: jgroth#184
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Heading outline has level skips (h1 → h3 → h5), and the debug route renders no heading context

1 participant