Skip to content

feat(docs): add clickable anchor links to headings#2053

Open
maxffarrell wants to merge 2 commits into
huntabyte:mainfrom
maxffarrell:feat/port-shadcn-bc2db187
Open

feat(docs): add clickable anchor links to headings#2053
maxffarrell wants to merge 2 commits into
huntabyte:mainfrom
maxffarrell:feat/port-shadcn-bc2db187

Conversation

@maxffarrell
Copy link
Copy Markdown
Contributor

Summary

Port of shadcn-ui/ui@bc2db187.

  • Adds a new HeadingAnchor Svelte component that wraps heading content with a clickable # anchor link
  • Updates all MDX heading components (h1h6) to explicitly accept and pass through the id prop (already set by rehype-slug) and wrap children with HeadingAnchor
  • On hover, headings reveal a # symbol and underline the text, linking to #<heading-id> for easy deep-linking

Implementation notes

The bits-ui docs already use rehype-slug (in mdsx.config.js) which auto-generates id attributes on headings from their text content. The HeadingAnchor component reuses those existing IDs rather than computing them from scratch (as shadcn does). The result is equivalent: every heading becomes a shareable anchor link.

Test plan

  • Build the docs site and verify headings show # on hover and link to #<id>
  • Verify headings without an id (no rehype-slug id) render children as plain text (no broken link)
  • Check that existing deep links / in-page navigation still works

🤖 Generated with Claude Code

Port of shadcn-ui/ui@bc2db187 — wraps h1–h6 MDX components with a
HeadingAnchor component that renders a clickable `#` link on hover,
leveraging the existing rehype-slug-generated IDs.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 14, 2026

⚠️ No Changeset found

Latest commit: 61c44ec

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 14, 2026

built with Refined Cloudflare Pages Action

⚡ Cloudflare Pages Deployment

Name Status Preview Last Commit
bits-ui ✅ Ready (View Log) Visit Preview 61c44ec

HTMLAttributes<HTMLHeadingElement> types id as string | null | undefined,
but HeadingAnchor expects string | undefined — coerce null to undefined.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@maxffarrell maxffarrell changed the title feat(docs): add clickable anchor links to MDX headings feat(docs): add clickable anchor links to headings May 15, 2026
@maxffarrell maxffarrell marked this pull request as ready for review May 15, 2026 00:38
@maxffarrell
Copy link
Copy Markdown
Contributor Author

Up to you if you want to merge! Useful but a little ugly

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.

1 participant