Skip to content

Code: Fix inline code blocks inside links removing link affordance#33903

Merged
Sidnioulz merged 8 commits into
storybookjs:nextfrom
yatishgoel:fix/inline-code-link-affordance
Mar 24, 2026
Merged

Code: Fix inline code blocks inside links removing link affordance#33903
Sidnioulz merged 8 commits into
storybookjs:nextfrom
yatishgoel:fix/inline-code-link-affordance

Conversation

@yatishgoel

@yatishgoel yatishgoel commented Feb 22, 2026

Copy link
Copy Markdown
Member

Closes #33901

What I did

Fixed a CSS specificity issue where inline code blocks (<code>) inside links (<a>) lost all link styling (color, underline),
making them appear unclickable.

Added an '& code' CSS rule to both the A styled component and the DocumentWrapper component so that code inside links inherits
the link color, displays an underline, and uses pseudo-elements for spacing (instead of padding, which breaks the underline).

Checklist for Contributors

Testing

The changes in this PR are covered in the following automated tests:

  • stories
  • unit tests
  • integration tests
  • end-to-end tests

Manual testing

  1. Run Storybook locally
  2. Create a story with a description containing [`inline-code`](https://example.com)
  3. Verify the inline code inside the link is underlined and uses the link color (blue)
  4. Verify regular inline code (not inside links) is unaffected
  5. Verify regular links (without code) are unaffected

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Checklist for Maintainers

  • When this PR is ready for testing, make sure to add ci:normal, ci:merged or ci:daily GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found in code/lib/cli-storybook/src/sandbox-templates.ts

  • Make sure this PR contains one of the labels below:

    Available labels
    • bug: Internal changes that fixes incorrect behavior.
    • maintenance: User-facing maintenance tasks.
    • dependencies: Upgrading (sometimes downgrading) dependencies.
    • build: Internal-facing build tooling & test updates. Will not show up in release changelog.
    • cleanup: Minor cleanup style change. Will not show up in release changelog.
    • documentation: Documentation only changes. Will not show up in release changelog.
    • feature request: Introducing a new feature.
    • BREAKING CHANGE: Changes that break compatibility in some way with current major version.
    • other: Changes that don't fit in the above categories.

🦋 Canary release

This PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the @storybookjs/core team here.

core team members can create a canary release here or locally with gh workflow run --repo storybookjs/storybook publish.yml --field pr=<PR_NUMBER>

Summary by CodeRabbit

  • Style
    • Inline code inside links now inherits the link color, receives consistent underline thickness with reduced side padding, and uses subtle non‑breaking‑space spacing for improved inline appearance.
  • Documentation
    • Added demo examples and storybook content showing inline code within links and mixed inline-code scenarios for visual reference.

Enhance the appearance of code elements within links by applying underline and spacing styles. This change ensures better visibility and consistency across typography components.
@dosubot

dosubot Bot commented Feb 22, 2026

Copy link
Copy Markdown

Related Documentation

Checked 0 published document(s) in 1 knowledge base(s). No updates required.

How did I do? Any feedback?  Join Discord

@coderabbitai

coderabbitai Bot commented Feb 22, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 344986db-33b4-4e68-9cae-8ea2bf7a0b19

📥 Commits

Reviewing files that changed from the base of the PR and between 34a9f1c and df5e58c.

📒 Files selected for processing (1)
  • code/core/src/components/components/typography/DocumentWrapper.stories.tsx
✅ Files skipped from review due to trivial changes (1)
  • code/core/src/components/components/typography/DocumentWrapper.stories.tsx

📝 Walkthrough

Walkthrough

Adds nested styling so inline <code> inside anchor elements inherits link color, receives the link underline (matching thickness), removes horizontal code padding, and gains small non‑breaking spaces before/after; also adds Storybook/Markdown examples demonstrating inline code within links.

Changes

Cohort / File(s) Summary
Typography: DocumentWrapper & Link element
code/core/src/components/components/typography/DocumentWrapper.tsx, code/core/src/components/components/typography/elements/A.tsx
Added an & code rule for code inside anchors: color: inherit, apply text-decoration: underline with link thickness, remove left/right padding, and add ::before/::after non‑breaking spaces (small font-size) to adjust spacing/underline.
Stories / Examples
code/addons/docs/src/blocks/blocks/Markdown.stories.tsx, code/core/src/components/components/typography/DocumentWrapper.stories.tsx
Appended multiple Markdown/Storybook examples showcasing inline <code> inside links and mixed content for visual verification.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs


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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
code/core/src/components/components/typography/DocumentWrapper.tsx (1)

69-82: Consider extracting shared link-code styles.

The & code styling block is now duplicated identically in both A.tsx and DocumentWrapper.tsx. You could extract this to a shared constant (e.g., in lib/common.ts) for DRY consistency:

export const linkCodeStyles = {
  color: 'inherit',
  textDecoration: 'underline',
  textDecorationThickness: '1px',
  padding: 0,
  '&::before': {
    content: '"\\00a0"',
    fontSize: '0.5em',
  },
  '&::after': {
    content: '"\\00a0"',
    fontSize: '0.5em',
  },
};

This is optional—the current duplication is minimal and clear.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@code/core/src/components/components/typography/DocumentWrapper.tsx` around
lines 69 - 82, Extract the duplicated '& code' style object into a shared
exported constant (e.g., linkCodeStyles) and replace the inline objects in
DocumentWrapper (component DocumentWrapper) and A (component A) with a reference
to that constant; ensure the constant exports the same properties (color,
textDecoration, textDecorationThickness, padding, '&::before', '&::after') and
is imported where used so both components consume the single source of truth.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@code/core/src/components/components/typography/DocumentWrapper.tsx`:
- Around line 69-82: Extract the duplicated '& code' style object into a shared
exported constant (e.g., linkCodeStyles) and replace the inline objects in
DocumentWrapper (component DocumentWrapper) and A (component A) with a reference
to that constant; ensure the constant exports the same properties (color,
textDecoration, textDecorationThickness, padding, '&::before', '&::after') and
is imported where used so both components consume the single source of truth.

@LuLaValva

Copy link
Copy Markdown

Thanks for trying to fix my issue @yatishgoel! I haven't figured out how to test locally, but I'm fairly certain that setting padding: 0 like this will cause issues. When I was playing with this in browser dev tools I only removed horizontal padding. Please make sure you look at these things yourself before putting up a PR

@valentinpalkovic valentinpalkovic changed the title Bug: Fix inline code blocks inside links removing link affordance Code: Fix inline code blocks inside links removing link affordance Mar 2, 2026
@valentinpalkovic valentinpalkovic added bug ci:normal Run our default set of CI jobs (choose this for most PRs). labels Mar 2, 2026
@storybook-app-bot

storybook-app-bot Bot commented Mar 2, 2026

Copy link
Copy Markdown

Package Benchmarks

Commit: df5e58c, ran on 23 March 2026 at 20:51:44 UTC

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

@storybook/cli

Before After Difference
Dependency count 184 184 0
Self size 780 KB 780 KB 🚨 +84 B 🚨
Dependency size 67.67 MB 67.68 MB 🚨 +10 KB 🚨
Bundle Size Analyzer Link Link

@storybook/codemod

Before After Difference
Dependency count 177 177 0
Self size 32 KB 32 KB 🚨 +36 B 🚨
Dependency size 66.19 MB 66.20 MB 🚨 +10 KB 🚨
Bundle Size Analyzer Link Link

@Sidnioulz Sidnioulz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the PR @yatishgoel! 🙇

Could you please edit stories as mentioned under, so that we have UI tests and non-regression tests for the change you made? I'll then send this to our designer for a design review.

Thanks

Comment thread code/core/src/components/components/typography/elements/A.tsx
Comment thread code/core/src/components/components/typography/DocumentWrapper.tsx
Added examples of inline code within links to the Markdown and DocumentWrapper stories for better demonstration of typography features. Adjusted padding styles in DocumentWrapper and A components for improved layout consistency.
@yatishgoel

Copy link
Copy Markdown
Member Author

Thanks for the PR @yatishgoel! 🙇

Could you please edit stories as mentioned under, so that we have UI tests and non-regression tests for the change you made? I'll then send this to our designer for a design review.

Thanks

Thanks for the feedback @Sidnioulz! I've made the following changes:

  • Added code inside a examples to DocumentWrapper.stories.tsx and Markdown.stories.tsx
  • Fixed padding: 0 → only zeroing horizontal padding (paddingLeft: 0, paddingRight: 0) as @LuLaValva pointed out

DocumentWrapper story:
DocumentWrapperStory

Markdown story:
MarkdownStory

@Sidnioulz

Copy link
Copy Markdown
Contributor

Thanks @yatishgoel for adding the stories!

We have to get #33139 merged before because it's gonna break your PR. I'll put it in my backlog and get back to you afterward with instructions. The stories will help us get a UI outcome to reflect on once we rebase your PR branch :)

Talk to you soon!

@Sidnioulz

Copy link
Copy Markdown
Contributor

@yatishgoel we've merged the other PR that affected link styles, could you please have a look at the conflicts? Also, ideally we'd want to ensure the same text decoration thickness is used as in the other PR (as that was reviewed by our design team). Thanks!

@github-actions github-actions Bot added the Stale label Mar 21, 2026
@yatishgoel

Copy link
Copy Markdown
Member Author

@yatishgoel we've merged the other PR that affected link styles, could you please have a look at the conflicts? Also, ideally we'd want to ensure the same text decoration thickness is used as in the other PR (as that was reviewed by our design team). Thanks!

@Sidnioulz can you please confirm whether the & code underline should also be 0.03125rem or if a slightly thicker underline (like the original 1px) would be preferred for code elements specifically, since code text is styled differently and a thicker underline might improve visibility there

@Sidnioulz

Copy link
Copy Markdown
Contributor

@yatishgoel we've merged the other PR that affected link styles, could you please have a look at the conflicts? Also, ideally we'd want to ensure the same text decoration thickness is used as in the other PR (as that was reviewed by our design team). Thanks!

@Sidnioulz can you please confirm whether the & code underline should also be 0.03125rem or if a slightly thicker underline (like the original 1px) would be preferred for code elements specifically, since code text is styled differently and a thicker underline might improve visibility there

Hey there! Yes, I believe we want to go for the same underline.

@Sidnioulz Sidnioulz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for bearing with us and seeing this to completion, @yatishgoel 🙏 Great work.

@yatishgoel

Copy link
Copy Markdown
Member Author

Thanks for bearing with us and seeing this to completion, @yatishgoel 🙏 Great work.

Thank you for the guidance and patience throughout, @Sidnioulz ! Happy to contribute 🙌

@Sidnioulz Sidnioulz merged commit 33afce2 into storybookjs:next Mar 24, 2026
118 checks passed
@github-project-automation github-project-automation Bot moved this from Blocked to Done in Core Team Projects Mar 24, 2026
@github-actions github-actions Bot mentioned this pull request Mar 24, 2026
15 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug ci:normal Run our default set of CI jobs (choose this for most PRs). needs triage

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[Bug]: Inline code blocks inside links remove link affordance

5 participants