Skip to content

fix(core): drop styling wrappers around icons; render glyphs through Icon - #4838

Merged
cixzhang merged 4 commits into
mainfrom
feat/icon-rotation-targets
Aug 9, 2026
Merged

cixzhang merged 4 commits into
mainfrom
feat/icon-rotation-targets

Conversation

@cixzhang

@cixzhang cixzhang commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

Why

A state-driven rotation — the chevron that turns when a section opens — is part of how the glyph looks in that state. Across core it lived on a styling wrapper while the component's icon theme target sat on the glyph inside it, so the element a theme could reach and the element that actually moved were two different nodes. Selector shows the split exactly: its chevron <Icon> already carried themeProps('selector-indicator-icon', {state}) with a comment explaining that same-element rules in @layer astryx-theme beat the icon's own base styles — but rotate(180deg) sat on the wrapper span above it.

Most of those wrappers turned out to exist only to host the transform. Remove the reason and there is nothing left to keep.

What

No new theme targets. This is wrapper removal and consolidation onto targets that already exist:

  • Selector, MultiSelector, ComplexSelector — the rotation moves onto the <Icon> that already carries *-indicator-icon. One selector now reaches the glyph's colour, size, and its transform. Also drops triggerIconStatus (a transition: none override that existed only to suppress the wrapper's rotation transition for status icons, and is dead once the transition rides on the chevron itself).
  • Table tree / grouped rows / row expansion — the wrapper spans are deleted; the icon carries the rotation. Icon's own span is already inline-flex, and the real layout (24×24 box, centering, hover chrome) lives on the buttons, which are untouched.
  • TreeList — two nested styling spans (an RTL mirror wrapping a rotation) collapse into one.
  • Banner, CodeBlock, TabList, Chat tool calls — the transform and its transition move onto the icon; each wrapper keeps only the layout it genuinely does.

Folding the RTL mirror. Where rtlStyles.mirror sat on a separate parent, it is folded into each state's transform, because transform is one property and on a single element the later value would win:

chevronExpanded: {
  transform: {
    default: 'rotate(90deg)',
    ':is([dir="rtl"] *)': 'scaleX(-1) rotate(90deg)',
  },
},

Composite matrix is identical to the nested pair at every point of the transition, in both directions.

New lint rule — @astryx/no-wrapper-transform (warn). Fails a <div>/<span> that exists to apply a transform to the icon inside it. Deliberately narrower than the existing no-style-only-wrapper, which fires only when a wrapper can be deleted outright: a transform wrapper often also does real layout, which exempts it there, but the transform still belongs on the child. It matches only an icon child (a name ending in Icon, or a useIcon() binding) — a transform around a non-glyph component is usually positioning the wrapper's own box, which is why Carousel's floating button pill is correctly left alone.

It ships as warn, not error, because it currently reports the useIcon() call sites (SideNav, TopNav, Collapsible) that this PR deliberately leaves alone — see below.

Second commit: render glyphs through <Icon>, not a styling span

SideNav, TopNav, Collapsible, TreeList and Breadcrumbs called useIcon(name) for a bare ReactNode and rendered it inside a hand-written <span> holding the styles. That span is a weaker reimplementation of <Icon>, which already resolves the same glyph and renders a span carrying merged className/style/xstyle plus the pre-existing astryx-icon theme target. Converting is why those sites had no targetable element: they had opted out of the component that provides one.

Node count is unchanged (span + glyph either way) and no new theme targets are added — astryx-icon already exists.

I first went the other way and drafted useIcon(name, props) with cloneElement. Lint rejected it — @astryx/no-react-introspection bans cloneElement and .props reads, pointing at "a wrapper component" instead — and that component already existed. The API change was abandoned before it went anywhere.

useIcon() keeps its place for resolving a glyph without rendering it: MoreMenu and ChatSendButton hand the node to another component as the default for a consumer-overridable prop, which <Icon> cannot express.

The sizing trap, since it nearly caused a silent regression. These glyphs are width/height: 1em SVGs, and their wrappers set a box but no font-size — so the glyph rendered at the inherited 14px inside a 24px or 28px box. <Icon> sets font-size alongside width/height, so a naive conversion would have inflated every chevron (14px → 24px in SideNavItem). Each converted site pins fontSize: 'inherit' (or the exact type-scale token) so the rendered glyph is unchanged; the boxes that match no Icon size keep their exact dimensions in xstyle.

Two wrappers deliberately survive: SideNavHeading's and TopNavHeading's chevron buttons carry aria-label, onClick and popover.triggerProps — they are triggers, not styling wrappers, and <Icon> renders a span. SideNavCollapseButton keeps its RTL mirror span, because rtlStyles.mirror must stay outside the state rotation.

With the conversion done, @astryx/no-wrapper-transform reports zero findings in core, so it ships as error rather than warn.

Risk

Default appearance is unchanged. Two behaviour notes, both improvements, both measured:

  • RTL in the Table plugins. The mirror there sat on a bare <span> (display: inline), and transform does not apply to a non-replaced inline box — so those chevrons never mirrored in RTL. Folding the mirror onto the icon makes it take effect.
  • A half-pixel centering fix. The row-expansion chevron sat 0.5px above centre because the removed wrapper's line-height nudged the centered flex item. Measured after: a 12px icon in a 24px button at offset 6.00 — exact centre.

Visual verification

Two Storybook dev servers — detached origin/main vs this branch — screenshotted with Playwright at 2×, LTR and RTL, disclosure toggles clicked so both states appear in frame.

A first pass reported 22/22 identical and was wrong: Storybook's Vite resolves @astryxdesign/core to source, not dist, so the "before" server was serving this branch's code. Caught because the before capture contained astryx-tree-list-chevron-icon, a class that does not exist on main. Re-run against a detached origin/main; the numbers below are from that run.

Re-run after the <Icon> conversion, which is where the pixel risk actually lived:

Story LTR RTL
TreeList, Collapsible, Selector, SideNav, TopNav, TabMenu, Banner, CodeBlock, Table tree 0 differing px 0 differing px
Table row expansion 23 / 952,000 (0.002%) 22 / 952,000
Table grouped rows 0 18 / 952,000 (max channel delta 12/255 — antialiasing on one vertical rule)

TreeList — before / after, 0 differing pixels:

treelist before
treelist after

Table row expansion — the 23 changed pixels. Cropping the region to a luminance grid shows the same glyph one device pixel lower, i.e. the centering fix, not a reshape:

before (x100+22, y72+20)          after
       =*=                        (blank)
      :***-                              =*=
      :***=                             :***-
       +**.                             :***=
        .                                +**.
                                          .

Third commit: the RTL audit was testing the old structure

pr-rtl failed on the first push, and it was right to notice something changed — but it was asserting the wrong thing. isFlipMatrix looked for one element whose computed transform is a pure matrix(-1,0,0,1). Once the mirror is folded into the same declaration as the rotation, no single element reads as a flip, even though the composition renders identically to the nested form.

The audit now composes the transform chain from the glyph upward and asserts the general contract:

RTL_matrix == scaleX(-1) · LTR_matrix

which holds for both shapes:

state LTR RTL pure flip?
collapsed identity matrix(-1, 0, 0, 1) yes
expanded rotate(90°) matrix(0, 1, 1, 0) no — but still the mirror

Verified both directions rather than just the happy one: on this branch treelist goes from AUTO FAIL to AUTO PASS (1 pass / 0 fail); with scaleX(-1) deleted from the folded transforms it returns to AUTO FAIL. So the check still catches a genuinely unmirrored glyph — it just no longer fails a correct one for its DOM shape.

The double-flip heuristic is narrowed to match: it now fires only when the LTR and RTL matrices are actually equal, rather than whenever both happen to contain a flip.

Testing

  • pnpm -F @astryxdesign/core typecheck · pnpm -F @astryxdesign/core lint — 0 errors, 12 warnings, all pre-existing no-style-only-wrapper reports on main. no-wrapper-transform reports nothing, so it ships as error.
  • pnpm exec vitest run --project ui over TreeList, Table, Banner, CodeBlock, TabList, Chat, Selector, MultiSelector, ComplexSelector and the themingTargets guard — 1269 passing. Table.perf budget failures reproduce on clean main; the TabList keyboard-nav and useTableFiltering failures pass twice in isolation (parallel-load flake).
  • pnpm exec vitest run --project node internal/eslint-plugin-astryx/no-wrapper-transform.test.mjs — 18 cases, including the Carousel-shaped false positive as an explicit valid case.
  • Selector's and MultiSelector's "byte-identical default icon" guards now assert a superset rather than exact equality: the chevron additionally carries the rotation classes by design, and the guard that matters — every colour/size class of a standalone icon is still present — is preserved.

@vercel

vercel Bot commented Aug 9, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
astryx Ignored Ignored Aug 9, 2026 3:04pm

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Aug 9, 2026
@github-actions github-actions Bot added the needs:design-review Affects visuals — Design should review label Aug 9, 2026
@github-actions

github-actions Bot commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

🧪 Sandbox Preview

View Sandbox for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

Modified Components

Banner (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 340 -
Complexity N/A High (24) -
Breadcrumbs (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 612 -
Complexity N/A Very High (48) -
Chat (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 5362 -
Complexity N/A Very High (438) -
CodeBlock (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 1586 -
Complexity N/A Very High (84) -
Collapsible (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 426 -
Complexity N/A Very High (39) -
ComplexSelector (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 355 -
Complexity N/A Very High (31) -
MultiSelector (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 1449 -
Complexity N/A Very High (175) -
Selector (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 1462 -
Complexity N/A Very High (138) -
SideNav (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 1889 -
Complexity N/A Very High (179) -
TabList (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 808 -
Complexity N/A Very High (41) -
Table (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 1936 -
Complexity N/A Very High (112) -
TopNav (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 2128 -
Complexity N/A Very High (156) -
TreeList (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 772 -
Complexity N/A Very High (78) -

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@astryxdesign/core N/A 4.7KB 1.2KB

Accessibility Audit

Status: 3 accessibility violation(s) found — 2 serious, 1 moderate.

Banner - 1 issue(s)
  • 🟠 serious: Ensure the contrast between foreground and background colors meets WCAG 2 AA minimum contrast ratio thresholds
    • Rule: color-contrast · Affects 1/16 stories · Learn more
    • WCAG: 1.4.3 (Level AA)
Chat - 1 issue(s)
  • 🟠 serious: Ensure the contrast between foreground and background colors meets WCAG 2 AA minimum contrast ratio thresholds
    • Rule: color-contrast · Affects 2/8 stories · Learn more
    • WCAG: 1.4.3 (Level AA)
TabList - 1 issue(s)
  • 🟡 moderate: Ensure landmarks are unique
    • Rule: landmark-unique · Affects 2/11 stories · Learn more

Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

github-actions Bot added a commit that referenced this pull request Aug 9, 2026
@cixzhang cixzhang changed the title feat(theme): put state rotations on the icon element as a theme target fix(core): drop wrapper elements around rotating icons Aug 9, 2026
github-actions Bot added a commit that referenced this pull request Aug 9, 2026
@cixzhang cixzhang changed the title fix(core): drop wrapper elements around rotating icons fix(core): drop styling wrappers around icons; render glyphs through Icon Aug 9, 2026
github-actions Bot added a commit that referenced this pull request Aug 9, 2026
github-actions Bot added a commit that referenced this pull request Aug 9, 2026
@cixzhang
cixzhang merged commit 4b1fef5 into main Aug 9, 2026
19 checks passed
@github-actions
github-actions Bot deleted the feat/icon-rotation-targets branch August 10, 2026 06:33
ernestt added a commit that referenced this pull request Aug 10, 2026
Keep triggerGhost/triggerGhostDisabled styles from this PR, adopt
main's unwrapped Icon pattern (color="secondary", no wrapper span)
from #4838.
humbertovirtudes pushed a commit that referenced this pull request Aug 18, 2026
* fix(Table): mirror the row-expansion chevron under RTL

The row-expansion chevron rotated 90deg on expand with no RTL
handling at all, so the glyph pointed the same direction regardless
of text direction. Flagged by the weekly full-suite RTL audit (#5141,
D1 icon-mirror) against TableRowExpansion and TreeList.

TreeListItem's chevron already has the correct pattern for this exact
shape (rotate + directional glyph): fold the RTL mirror into each
state's own transform rather than a separate wrapper, since both are
`transform` and a later declaration on the same element would win.
Applied the identical pattern here.

Also fixed the context-menu action's icon, which swaps between
chevronDown (expanded, no mirroring needed) and chevronRight
(collapsed, directional) instead of rotating -- chevronRight needs
rtlStyles.mirror in the collapsed state, matching the convention used
by Pagination/Carousel/Lightbox/Calendar for static directional
chevrons.

TreeList's own instance already has the correct mirror (verified: it
is the only chevron render site in that directory, landed in #4838,
uses the exact fold-into-transform pattern this PR now matches) --
the audit's "treelist" finding may be stale or probing a state this
source-level check can't reproduce; nothing to fix there that I could
find.

* chore: add changeset for row-expansion RTL chevron fix
AKnassa added a commit to AKnassa/astryx that referenced this pull request Aug 27, 2026
Conflicts: TreeList.tsx, TreeListItem.tsx, TreeListTypes.ts, index.ts —
resolved as a union of main's TreeListVariant / Icon-rendered chevron /
flush-leaf column logic (meta#4838, meta#4540, meta#4530, meta#4334) and this branch's
renderExpandIcon. A leaf that renders its own indicator no longer reserves
the chevron column. The four alignment tests now read the published
--_tree-indent custom property instead of the removed inline marginLeft.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot. needs:design-review Affects visuals — Design should review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant