Skip to content

Docs: add paddingLeft to OcticonHeaders so anchor icon is not clipped in light theme#33957

Closed
mixelburg wants to merge 1 commit into
storybookjs:nextfrom
mixelburg:fix/docs-heading-anchor-clipping-in-light-theme
Closed

Docs: add paddingLeft to OcticonHeaders so anchor icon is not clipped in light theme#33957
mixelburg wants to merge 1 commit into
storybookjs:nextfrom
mixelburg:fix/docs-heading-anchor-clipping-in-light-theme

Conversation

@mixelburg
Copy link
Copy Markdown

@mixelburg mixelburg commented Feb 27, 2026

Closes #31505

What I did

When the docs addon renders headings with anchor icons (OcticonAnchor), the anchor is positioned using float: left with marginLeft: '-24px'. This negative-margin approach requires the heading itself to have at least 24px of left padding so the floating icon has room to appear without being clipped by the parent container.

In the light theme the heading had no left padding, so the icon was cut off. The dark theme happened to have extra left space from a parent container, which masked the bug.

The fix adds paddingLeft: '24px' to the OcticonHeaders styled components (the same approach used by GitHub's Markdown heading anchors).

Before (light theme): anchor icon cut off on the left side
After (light theme): anchor icon fully visible, matching dark-theme behaviour

Summary by CodeRabbit

  • Bug Fixes
    • Fixed header styling in documentation blocks to properly display anchor icons without clipping in both light and dark themes.

…ipped

The docs heading anchor link (OcticonAnchor) uses float:left with
marginLeft:-24px to position itself to the left of the heading text.
Without paddingLeft on the heading itself, this negative-margin float
extends outside the element's content box, causing the icon to be
clipped by the parent container in the light theme.

Adding paddingLeft:'24px' to OcticonHeaders creates the space the
floating anchor needs to be fully visible, mirroring the approach used
by GitHub's Markdown heading anchors.

Closes storybookjs#31505
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Feb 27, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f73e0fe and 25bdf45.

📒 Files selected for processing (1)
  • code/addons/docs/src/blocks/blocks/mdx.tsx

📝 Walkthrough

Walkthrough

A styling adjustment added left padding to OcticonHeaders in the MDX documentation blocks. This reserves space for a floating anchor icon to prevent visual clipping without modifying any functional logic or control flow.

Changes

Cohort / File(s) Summary
Header Styling Update
code/addons/docs/src/blocks/blocks/mdx.tsx
Added paddingLeft: '24px' to OcticonHeaders styling across header types with comments to reserve space for the floating anchor icon.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes


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.

@valentinpalkovic valentinpalkovic changed the title fix(docs): add paddingLeft to OcticonHeaders so anchor icon is not clipped in light theme Docs: add paddingLeft to OcticonHeaders so anchor icon is not clipped in light theme Mar 2, 2026
@valentinpalkovic valentinpalkovic moved this to Empathy Queue (prioritized) in Core Team Projects Mar 2, 2026
@storybook-app-bot
Copy link
Copy Markdown

Package Benchmarks

Commit: 25bdf45, ran on 2 March 2026 at 13:51:03 UTC

The following packages have significant changes to their size or dependencies:

storybook

Before After Difference
Dependency count 49 49 0
Self size 20.19 MB 20.42 MB 🚨 +228 KB 🚨
Dependency size 16.52 MB 16.52 MB 0 B
Bundle Size Analyzer Link Link

@storybook/cli

Before After Difference
Dependency count 183 183 0
Self size 779 KB 779 KB 0 B
Dependency size 67.37 MB 67.60 MB 🚨 +228 KB 🚨
Bundle Size Analyzer Link Link

@storybook/codemod

Before After Difference
Dependency count 176 176 0
Self size 32 KB 32 KB 🎉 -36 B 🎉
Dependency size 65.89 MB 66.12 MB 🚨 +228 KB 🚨
Bundle Size Analyzer Link Link

create-storybook

Before After Difference
Dependency count 50 50 0
Self size 1.04 MB 1.04 MB 0 B
Dependency size 36.71 MB 36.94 MB 🚨 +228 KB 🚨
Bundle Size Analyzer node node

Copy link
Copy Markdown
Member

@Sidnioulz Sidnioulz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

Unfortunately, it has very visible side effects. All heading text gets moved to the right, and is no longer aligned to the content.

Image

For this bug, we'll want to fix the underlying CSS conflict issue described in the GitHub issue instead of changing text alignment.

Please make sure to test your changes in the Storybook UI with yarn task compile && yarn storybook:ui prior to pushing changes. Please also make sure to correctly fill in the "Manual testing" part of the PR template going forward.

@Sidnioulz
Copy link
Copy Markdown
Member

@mixelburg FYI I could not reproduce the original issue in #28259.

If you are able to reproduce it, could you please provide a link to a reproduction repository? This would be very helpful. We also have a fix by Claude that looks reasonably smart to me but we need a repro case to validate it.

Thanks,

@mixelburg

This comment was marked as low quality.

@mixelburg mixelburg closed this Mar 8, 2026
@github-project-automation github-project-automation Bot moved this from Empathy Queue (prioritized) to Done in Core Team Projects Mar 8, 2026
@Sidnioulz
Copy link
Copy Markdown
Member

Closing this in favour of the approach at #34015 which handles the CSS ordering more robustly. I wasn't able to provide a repro case and the paddingLeft fix has the side-effect of shifting all heading text. Thanks for the review @Sidnioulz!

Thanks for checking if you could repro!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[Bug]: docs - heading left margin only appears in the dark theme

3 participants