Skip to content

fix(Icon): render wrapper as span for valid inline nesting - #1302

Open
ignovak wants to merge 2 commits into
mainfrom
fix/icon-inline-span-wrapper
Open

ignovak wants to merge 2 commits into
mainfrom
fix/icon-inline-span-wrapper

Conversation

@ignovak

@ignovak ignovak commented Nov 11, 2026 •

Copy link
Copy Markdown

Description

Icon rendered its SVG inside a block <div> wrapper. Because an icon is inline content, using it inline — e.g. an icon inside Text (a <p>), or a Link with an icon prop (an <a>) — produced invalid DOM nesting (<div> as a descendant of <p>/<a>) and React validateDOMNesting warnings.

  • Change the Icon SVG wrapper from <div> to <span>. <span> is phrasing content and legal inline.
  • .svg-wrapper is already display: flex, so a <span> renders identically — the change is visually neutral and behaviorally pure.
  • Nothing else changed: role="img"/aria-label are spread onto the inner SVG (not the wrapper), so the wrapper is purely presentational and getByRole('img') is unaffected.

Links and tickets

Good to know

Rationale: an icon is inline content; a block <div> wrapper breaks valid nesting wherever an icon is placed inline. span + display: flex keeps layout identical.

Checklist

  • Breaking changes? (add migration notes in changesets)
  • Visual changes? (specify in changesets)
  • Design review needed?

A patch changeset is included. No visual change.

Contribution

  • Sufficient research before PR
  • Self-reviewed the PR
  • Manually tested the changes (when applies - visual confirmation in Storybook)
  • build and build-storybook work locally
  • Tests and Stories are aligned with the changes

Verified locally: typecheck, lint (0 errors), format, circular-dependency:check, test (881/881), build + health check, storybook:build all pass. Visual regression in Docker: Icon spec 37/37 and the consumer specs that @covers src/components/Icon (iconbutton, popover, codeblock, genericmenu) 72/72 pass with zero snapshot diffs — no snapshots regenerated.

Accessibility

Behavior and ARIA are unchanged (purely a wrapper-element swap). The icon's accessible name still comes from aria-label on the SVG, confirmed by the existing unit and visual tests.

  • Keyboard — unchanged; Icon is non-interactive
  • Names — unchanged; accessible name still on the SVG (getByRole('img') tests pass)
  • Vision — unchanged; colors from tokens, visuals byte-identical in both themes

Screenshots

No visual change — all existing light/dark snapshots match with zero diffs.

🤖 Generated with Claude Code


Note

Low Risk
Presentational wrapper tag change only; styles and ARIA on the inner SVG are unchanged, with a minor caveat for tag-based CSS or DOM assertions.

Overview
Changes the Icon SVG wrapper from a block <div> to an inline <span> so icons nested inside phrasing content (e.g. Text / <p> or Link / <a>) no longer violate DOM nesting rules or trigger React validateDOMNesting console.error warnings. Styling stays on the existing .svg-wrapper classes with display: flex, so appearance and layout should be unchanged.

Adds a regression test that renders an icon inside a <p>, asserts the wrapper is SPAN, and confirms no console errors. A patch changeset documents the element swap and notes that consumers selecting the wrapper by tag name may need to update those selectors.

Reviewed by Cursor Bugbot for commit 613aadd. Bugbot is set up for automated code reviews on this repo. Configure here.

An icon is inline content, but the SVG wrapper was a block <div>, so
using an icon inline (e.g. inside Text or a Link) produced invalid DOM
nesting (<div> inside <p>/<a>) and React validateDOMNesting warnings.

.svg-wrapper is already display: flex, so a <span> renders identically;
<span> is phrasing content and legal inline. Layout is unchanged.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 613aadd

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@clickhouse/click-ui Patch

Not sure what this means? Click here to learn what changesets are.

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

@XOP XOP added bug Something isn't working a11y Accessibility improvements labels Nov 11, 2026

@XOP XOP 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.

Please consider recommended updates (css, changeset, test)


return (
<div
<span

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.

the intention is great 👍

some deeper checks are needed, as it can get messy pretty quick.

please check the span targets in css, that were not affected before the change, i.e. in the InputWrapper:

.wrapper span:first-of-type {
  max-width: 100%;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

if the icon is present there, it will be affected.

this may also have a waterfall effect - i.e. for the apps that do use html targeting, this change will be breaking. not a reason to avoid the change, just note that it is visually breaking for such cases.

side note - raw html elements should not be targeted, exactly for this reason :) we should use classnames; if there's an exception then a comment is mandatory, yet it's not a perfect guardrail.


other thing - would be great to have a regression test for this small update.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

thanks, the concerns are addressed:

Add a regression test that renders an Icon inside a <p> and asserts the
wrapper is a span with no React validateDOMNesting warning, so a revert
to <div> is caught here. Note the div->span element change in the
changeset for consumers that target the wrapper by tag name.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@workflow-authentication-public

Copy link
Copy Markdown
Contributor

Storybook Preview Deployed

✅ Preview URL: https://click-bue0x56ld-clickhouse.vercel.app

Built from commit: c9f4b6ae7fee3059cfb8d66369357756b4303da6

@workflow-authentication-public

Copy link
Copy Markdown
Contributor

Chromatic Storybook

Check Status Link
Storybook ✅ 670 stories published Open Storybook
UI Tests ✅ 670 tests unchanged Open build

Built from commit: 613aadddb952068eff31a39393c218ebeb5af6e3 · Chromatic run

Statuses as of the end of the run. The build link shows the live review state.

This branch has not been deployed

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

Labels

a11y Accessibility improvements bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants