Repository navigation
fix(theme): make shared focus outlines themeable - #4654
Merged
Merged
Conversation
cixzhang
requested review from
ejhammond,
humbertovirtudes,
imdreamrunner and
josephfarina
as code owners
August 2, 2026 15:18
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
github-actions
Bot
requested review from
cvkxx,
ernestt,
kentonquatman and
rubyycheung
August 2, 2026 15:18
cixzhang
force-pushed
the
fix/focus-outline-consistency
branch
from
August 2, 2026 15:29
ce99cfc to
4c808b1
Compare
cixzhang
force-pushed
the
fix/focus-outline-consistency
branch
from
August 2, 2026 21:29
4c808b1 to
1eba42f
Compare
cixzhang
commented
Aug 3, 2026
| ':active': `linear-gradient(${colorVars['--color-overlay-pressed']}, ${colorVars['--color-overlay-pressed']})`, | ||
| }, | ||
| outline: { | ||
| default: null, |
Contributor
Author
There was a problem hiding this comment.
This is kind of nice to have which is an error-specific outline color.
cixzhang
force-pushed
the
fix/focus-outline-consistency
branch
from
August 3, 2026 03:06
1eba42f to
96b7019
Compare
rubyycheung
approved these changes
Aug 7, 2026
Two problems found by focusing components in a browser rather than reading the diff. The ring was being clobbered. makeFocusOutlineProps spread its own style FIRST, and StyleX is last-wins — so any caller style touching `outline` silently deleted it. TreeList's contentWrapper carries `outline: 'none'`, so a focused tree row painted no ring at all: base gave `DIV 2px solid rgb(38,38,38)`, this branch gave nothing (WCAG 2.4.7). Caller styles now go first, which also makes the helper safe for the other 25 components rather than relying on none of them resetting outline. Verified across TreeList, Button, Token, Link, Pagination, TabList and SegmentedControl — all 2px solid on Tab. The unit test missed it because it asserts on the published CSS variable, which was fine; only the paint was broken. It failed for an unrelated reason (the variable was renamed `--_tree-focus-outline` -> `--_focus-outline`), and that stale name is why the real regression had no failing test pointing at it. Dropped the astryx-focus-outline theme target. A theme can only override it unconditionally: generateThemeRules turns a ':focus-visible' key into '.focus-visible' and truncates ':has(:focus-visible)' at the paren, both silently producing rules that never match. So the target could not express a state override — the one thing it exists for — while Theme.doc.mjs advertised exactly those two states. The utility styles are the substance of this PR (-143 lines, five identical definitions to one); themeability is worth adding on top once the pseudo-selector handling is fixed. Full UI suite 6132/6132.
Resolving the rebase by keeping both sides was wrong for these two. Timestamp: main deliberately removed this element's focus ring while this branch was open — its comment says the hover card's dashed underline is the affordance and the anchor 'needs no separate focus outline'. Keeping both sides re-added the ring AND resurrected tooltip styles main had deleted, producing a file that did not parse. Deferring to main; Timestamp is now untouched by this PR. Theme.doc.mjs: only a quote-style reformat and a stray blank line remained once the focus-outline target was dropped. Reverted to main.
cixzhang
force-pushed
the
fix/focus-outline-consistency
branch
from
August 11, 2026 05:00
6a45575 to
abab28e
Compare
Contributor
PR Analysis Report📚 Storybook PreviewView Storybook for this PR 🧪 Sandbox PreviewView Sandbox for this PR Modified ComponentsAvatar (@astryxdesign/core) · View in Storybook
AvatarGroup (@astryxdesign/core) · View in Storybook
Button (@astryxdesign/core) · View in Storybook
Calendar (@astryxdesign/core) · View in Storybook
ClickableCard (@astryxdesign/core) · View in Storybook
CodeBlock (@astryxdesign/core) · View in Storybook
Collapsible (@astryxdesign/core) · View in Storybook
Dialog (@astryxdesign/core) · View in Storybook
Item (@astryxdesign/core) · View in Storybook
Link (@astryxdesign/core) · View in Storybook
Outline (@astryxdesign/core) · View in Storybook
Pagination (@astryxdesign/core) · View in Storybook
Resizable (@astryxdesign/core) · View in Storybook
SegmentedControl (@astryxdesign/core) · View in Storybook
SelectableCard (@astryxdesign/core) · View in Storybook
TabList (@astryxdesign/core) · View in Storybook
Table (@astryxdesign/core) · View in Storybook
Thumbnail (@astryxdesign/core) · View in Storybook
Token (@astryxdesign/core) · View in Storybook
TopNav (@astryxdesign/core) · View in Storybook
TreeList (@astryxdesign/core) · View in Storybook
Bundle Size Summary
Accessibility AuditStatus: 6 accessibility violation(s) found — 5 serious, 1 moderate. ClickableCard - 1 issue(s)
Outline - 1 issue(s)
SelectableCard - 1 issue(s)
TabList - 1 issue(s)
Thumbnail - 1 issue(s)
Token - 1 issue(s)
Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
cixzhang
commented
Aug 11, 2026
| ':focus-visible': '2px', | ||
| }, | ||
| }, | ||
| focusable: {}, |
Review feedback, plus what a rendered-ring sweep across every touched component turned up. Destructive buttons had lost their error-red focus ring to the shared accent one. Two separate causes, both found by measuring rather than reading: - The shared style set the "outline" SHORTHAND, which resets every longhand it covers -- so a variant's "outlineColor" could not survive it regardless of ordering. The ring is longhands now. - My earlier fix put the shared style last to stop callers clobbering it, which also ate deliberate overrides. Caller styles go last again; TreeList's contentWrapper loses the redundant "outline: none" that made that ordering necessary (the shared style already defaults to none, and the shorthand erased the ring). Removes --button-focus-offset. Button was the only component exposing its focus offset as a themeable var and the only one offsetting by 3px; both read as incidental -- the var arrived in the un-prefix migration (#2941) and was never revisited. Marked breaking in the changeset. Cleans up four empty style objects left behind by the consolidation (Avatar, Item, Token, TopNavItem) and their call-site references. Verified by focusing 22 components in Chrome and diffing the computed ring against origin/main. Only intended differences remain: destructive back to rgb(165,12,37), and 3px -> 2px on Button, Calendar, Dialog and Pagination. Every other component byte-identical. 731 tests pass across the touched components.
cixzhang
force-pushed
the
fix/focus-outline-consistency
branch
from
August 11, 2026 05:59
e30efd6 to
6523594
Compare
…entions Checking the spec inverted the fix. Design Conventions, User Interaction States: "Focused (Outline style) -- 2px --color-accent outline at 3px offset". Button, Calendar, Dialog and Pagination were the components still matching it; the other general controls had drifted to 2px. The consolidation now takes the documented value, so the drifted components move TO spec rather than the majority eroding it. Restores --button-focus-offset. Its 3px default is no longer Button-specific, but it is a documented public var and removing it would break any theme setting it for no gain. It still overrides the shared offset, so a theme can tune button rings specifically. Destructive keeps its error-red ring. Measured in Chrome after the change -- all eleven general controls now read 2px solid at 3px offset, and destructive reads rgb(165,12,37): Button (primary + destructive), Calendar, Dialog, Pagination, Link, TabList, Token, TreeList, SegmentedControl, TopNav.
cixzhang
enabled auto-merge (squash)
August 11, 2026 06:17
cixzhang
added a commit
that referenced
this pull request
Aug 11, 2026
…d outline Replaces the :has()-suppression machinery with the approach #4654 makes possible: the owner paints the standard ring onto the indicator's own element at focus time. Why the owner and not the indicator: the control's native input is opacity: 0, so the ring has to land on the picture beside it -- and that picture is third-party code once a theme replaces it. A replacement that simply does not draw one ships a control with no visible focus (WCAG 2.4.7), which is the DEFAULT outcome: our own sample replacement destructures {state, size, isDisabled} and drops the rest. Nothing can enforce otherwise; a component ignoring every prop is still assignable to IndicatorComponent, and branding the return type does not work either because JSX types every expression as JSX.Element. Why the indicator's element and not a wrapper: outline follows that element's border-radius, so the ring is shaped correctly without the owner hardcoding a guess about what it hosts. RadioListItem used to carry border-radius: 50% for a circle it did not own. Two details, both measured rather than assumed: - Inline style, not an injected class. React replaces className wholesale on re-render, so an injected class disappears the moment the control changes state -- pressing Space on a focused checkbox lost the ring. React reconciles style per property, so an outline set this way survives. - The handler checks :focus-visible. The CSS this replaces got keyboard-vs-pointer for free; asking the element keeps the browser's heuristic, including focus({focusVisible: true}). Adds FOCUS_OUTLINE_PARTS to the shared focus-outline module -- the same ring as its StyleX variants, exposed as longhand values for the one case that must apply it imperatively. Longhands rather than the outline shorthand for the reason #4654 established: a shorthand resets every longhand it covers, so a caller could not re-color the ring. Each owner wraps its indicator in a display: contents slot, so the ring has one unambiguous target whatever a theme renders. Verified in Chrome: built-in checkbox rings at r=6px, built-in radio at r=50%, a replacement that forwards nothing still rings, and a mouse click rings nothing. 298 tests pass across the touched components.
cixzhang
added a commit
that referenced
this pull request
Aug 11, 2026
SideNavItem, SideNavHeading and the drawer modes of TopNavMenu, TopNavMegaMenu and TopNavMegaMenuItem styled no focus state at all, so a keyboard-focused nav row fell back to the browser's outline: measured 'auto 1px rgb(0,95,204)' in light and 'rgb(153,200,255)' in dark, the same blue in every theme because it is Chrome's and not Astryx's. Each focusable now composes focusOutlineProps.focusVisible, which is how the 26 components migrated in #4654 consume the one shared definition: 2px solid var(--color-accent) at the 3px offset Design Conventions documents. Measured after the change, the ring matches TabList, Button, Link and TopNavItem exactly, and tracks the theme (y2k rgb(45,36,27)). The ring is NOT written into navItemStyles.item. StyleX cannot compose a created style into another definition, so putting it there would mean restating the outline longhands in a sixth place -- the duplication #4654 exists to remove. The file header now says so. In the split-action path the row is a <div> holding two independent tab stops, so the link and the chevron each ring themselves and the row does not: focusWithin on the row would paint the same outline for either child, and TreeList's publish/read pair needs the focusable to be the ancestor of the drawing element, which it is not here. No consumer drew its own ring, so nothing double-rings -- checked by measuring all of them in Chromium before touching anything. TopNavItem already adopted the utility in #4654 and is left alone.
cixzhang
added a commit
that referenced
this pull request
Aug 11, 2026
Twelve tests, all twelve red on the merge base. They assert composition rather than paint: jsdom does not derive :focus-visible from user-event's Tab on an <a>/<button>, so the rendered ring cannot be read back here. The classes are compared against stylex.props(focusOutlineStyles .focusVisible) instead of hardcoded hashes, so the assertion follows the utility if its declarations change. #4654's own review is why the paint is verified in a real browser instead: there, unit tests asserting classes and published CSS variables stayed green while two components had lost their ring entirely.
cixzhang
added a commit
that referenced
this pull request
Aug 12, 2026
SideNavItem, SideNavHeading and the drawer modes of TopNavMenu, TopNavMegaMenu and TopNavMegaMenuItem styled no focus state at all, so a keyboard-focused nav row fell back to the browser's outline: measured 'auto 1px rgb(0,95,204)' in light and 'rgb(153,200,255)' in dark, the same blue in every theme because it is Chrome's and not Astryx's. Each focusable now composes focusOutlineProps.focusVisible, which is how the 26 components migrated in #4654 consume the one shared definition: 2px solid var(--color-accent) at the 3px offset Design Conventions documents. Measured after the change, the ring matches TabList, Button, Link and TopNavItem exactly, and tracks the theme (y2k rgb(45,36,27)). The ring is NOT written into navItemStyles.item. StyleX cannot compose a created style into another definition, so putting it there would mean restating the outline longhands in a sixth place -- the duplication #4654 exists to remove. The file header now says so. In the split-action path the row is a <div> holding two independent tab stops, so the link and the chevron each ring themselves and the row does not: focusWithin on the row would paint the same outline for either child, and TreeList's publish/read pair needs the focusable to be the ancestor of the drawing element, which it is not here. No consumer drew its own ring, so nothing double-rings -- checked by measuring all of them in Chromium before touching anything. TopNavItem already adopted the utility in #4654 and is left alone.
cixzhang
added a commit
that referenced
this pull request
Aug 14, 2026
SideNavItem, SideNavHeading and the drawer modes of TopNavMenu, TopNavMegaMenu and TopNavMegaMenuItem styled no focus state at all, so a keyboard-focused nav row fell back to the browser's outline: measured 'auto 1px rgb(0,95,204)' in light and 'rgb(153,200,255)' in dark, the same blue in every theme because it is Chrome's and not Astryx's. Each focusable now composes focusOutlineProps.focusVisible, which is how the 26 components migrated in #4654 consume the one shared definition: 2px solid var(--color-accent) at the 3px offset Design Conventions documents. Measured after the change, the ring matches TabList, Button, Link and TopNavItem exactly, and tracks the theme (y2k rgb(45,36,27)). The ring is NOT written into navItemStyles.item. StyleX cannot compose a created style into another definition, so putting it there would mean restating the outline longhands in a sixth place -- the duplication #4654 exists to remove. The file header now says so. In the split-action path the row is a <div> holding two independent tab stops, so the link and the chevron each ring themselves and the row does not: focusWithin on the row would paint the same outline for either child, and TreeList's publish/read pair needs the focusable to be the ancestor of the drawing element, which it is not here. No consumer drew its own ring, so nothing double-rings -- checked by measuring all of them in Chromium before touching anything. TopNavItem already adopted the utility in #4654 and is left alone.
7 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
The standard focus outline was written out independently in every component that draws one — same intent, five separate definitions. Beyond the duplication, they had drifted apart, which is the more interesting finding (below). This came up while evaluating agentcloud and trying to replicate its styling through Astryx themes.
Astryx has a deliberate split here: input/field focus treatments differ from general interactive chrome. This PR targets the general outline only.
What
Adds
packages/core/src/utils/focusOutline.stylex.ts— one definition, in four application shapes:focusVisiblefocusWithinpublishFocusVisibleVarsfocusWithinOrPublishedApplied across 26 components of general interactive chrome. Outline primitives stay private to the helper. Net −438 lines.
Resolved real drift from Design Conventions
The consolidation forced a question the duplication had hidden: which value is correct? Design Conventions, §User Interaction States, is explicit:
Rendered-ring measurements across the affected components showed most had drifted to a 2px offset. Only Button, Calendar, Dialog and Pagination still matched the spec. This PR takes the documented value, so Link, TabList, Token, TreeList, SegmentedControl and TopNav items move to spec — their ring now sits 1px further from the control.
Measured in Chrome, after:
--button-focus-offsetis retained. Its default is no longer Button-specific, but it is a documented public var and it still overrides the shared offset.Not themeable yet — deliberately
An earlier revision exposed a shared
astryx-focus-outlinetheme target. Removed, because the theme system cannot express what such a target is for. A focus ring is a state treatment, andgenerateThemeRulesmishandles state keys, silently, in two ways:So a theme could only override the ring unconditionally — a permanent outline on 26 components — while
Theme.doc.mjsadvertised exactly those two states. The consolidation stands on its own; themeability is a good follow-up once pseudo-selector handling is fixed, and this module is the foundation for it.Three bugs found in review, all by measuring rather than reading
contentWrapper'soutline: 'none'deleted it. A focused tree row painted nothing (WCAG 2.4.7).outlineshorthand, which resets every longhand it covers — so a variant'soutlineColorcould not survive it at any ordering. The ring is longhands now, and the redundant reset in TreeList is gone.Avatar,Item,Token,TopNavItem), plus their call-site references.The existing unit tests missed (1) and (2): they assert on published CSS variables and class presence, both of which were fine. Only the paint was wrong.
Test plan
origin/mainfor 22 components, Tab-focused, in real Chrome — the sweep that found the drift, and the only check that catches this class of bug.CI=true).main(was 131 commits behind).Timestampis untouched by this PR —maindeliberately removed that element's ring in the meantime.Follow-ups
generateThemeRulesdrops or mangles pseudo-selector keys — affects any component target declaringstates.CheckboxInput/RadioListItemaren't in the sweep; they're the two controls whose focus lives on a visually hidden input, and should consumepublishFocusVisibleVarsnext.