Repository navigation
Description
Summary
TreeList applies per-row indentation as an inline style on the same element that carries the row highlight and StyleX styling. Because inline styles beat every cascade layer, indentation is unreachable from the sanctioned theming layer (@layer astryx-theme), forcing consumers into !important/unlayered CSS. This RFC proposes making indentation reachable through sanctioned channels and lays out options for maintainers to choose from.
Where it lives
In packages/core/src/TreeList/TreeListItem.tsx, indent is computed as:
const computedMarginLeft = hasChildren
? `calc(${nestedLevel} * ${spacingVars['--spacing-4']})`
: `calc(${nestedLevel} * ${spacingVars['--spacing-4']} + ${spacingVars['--spacing-4']} + ${spacingVars['--spacing-2']})`;and applied as an inline style on the row's content wrapper <div> — which is also the astryx-tree-list-item theme target and the StyleX-styled element:
<div
{...mergeProps(
themeProps('tree-list-item', {
density,
selected: isSelected ? 'selected' : null,
disabled: isDisabled ? 'disabled' : null,
}),
stylex.props(
styles.contentWrapper,
densityStyles[density],
/* interactive / focusVisibleOutline / disabled / selected ... */
isSelected && styles.selected,
),
)}
style={{marginLeft: computedMarginLeft}} // <-- inline indent on the highlighted element
onClick={handleClick}>
{innerContent}
</div>Note that data-tree-level (and data-tree-id) live on the outer <li role="treeitem">, not on this content <div>, so the level is not available as a selector hook on the highlighted element itself.
Consequences
- Inline style beats every cascade layer.
defineThemeoutput lands in@layer astryx-theme(above StyleX's@layer astryx-base), but an inlinestyleoutranks all layered CSS. So a consumer cannot retune indentation via a theme — they're pushed into!importantand unlayered CSS. This is the root cause. - The highlight includes the indent. Because indent is applied on the highlighted content wrapper, the hover/selected background is inset by the indent and cannot span the full row width or clear the guide rails — a common design need for full-width navigation rows.
- Per-level insets can't be derived in
calc().data-tree-levelsits on the<li>, not the themed element, and CSS can't read an attribute value intocalc(). Consumers wanting custom insets end up enumerating per-level rules by hand. - No configurable indent metric. The per-level step is hardcoded to
--spacing-4; there is noindentSizeprop or indent token to change it.
Why this matters (Astryx theming model)
Astryx's theming contract is that a component's styled surface is reachable through documented astryx-* targets in @layer astryx-theme, sitting above StyleX's @layer astryx-base. An element whose layout is fixed by an inline style sits outside that contract entirely — it can't be reached by defineTheme or a token, only by an escape hatch. This is the same principle the theming.targets guard embodies: an undocumented (here, unreachable) surface is an unthemeable element. Indent is currently one such surface.
Proposal (RFC — options for maintainers)
Making indentation reachable through sanctioned channels. These are complementary; each maps to a subset of the consequences above.
Option A — Indent as a CSS custom property
Publish per-row indent as a CSS variable (name is maintainers' call, e.g. --astryx-tree-indent) and have StyleX consume it in calc() instead of setting an inline style. This moves indent into the cascade so defineTheme / a token can set it.
- Solves: (1). The metric becomes layer-reachable and no longer requires
!important. - Does not solve on its own: (2) — indent still sits on the highlighted element.
Option B — Move indent onto an outer element
Restructure so the indent is applied to an outer wrapper rather than the highlighted content wrapper, letting the highlight span the full row independent of indent.
- Solves: (2), enabling full-width highlight/nav rows.
- Tradeoffs (called out honestly): this is a DOM-structure change. It carries back-compatibility and visual-regression risk for consumers who target the current structure, and should be weighed against a snapshot/visual baseline.
Option C — indentSize prop
Expose an indentSize prop (token or number, default --spacing-4) so the per-level metric is configurable with no CSS at all.
- Solves: (4), and gives an API-level lever for (1)/(3) without requiring consumers to reach into CSS.
Combining
- A + C covers (1), (3, insofar as the metric is now settable rather than hand-enumerated), and (4) without a DOM change.
- A + B + C is the full fix, additionally addressing (2) at the cost of the structural change in B.
Consequence (3) specifically is eased by A/C (a single settable metric replaces hand-enumerated per-level rules); it is not fully resolvable in pure CSS as long as level lives only as an attribute on the <li>.
Related theme-target additions
There are already-open sibling PRs extending this component's themeable surface — #4305 (adds an astryx-tree-list-chevron target) and #4306 (adds an astryx-tree-list-item-label target). This RFC is in the same spirit for the row's indentation/layout surface, and any chosen option should stay consistent with those additions.
Scope
Analysis + proposal only — no implementation is attached. Requesting maintainer direction on which option(s) to pursue.
Activity
freddymeta commentedon Jul 25, 2026
Thanks for the thorough write-up. My recommendation is to pursue Option A alone as the minimal, sufficient fix, and to hold off on B and C.
Option A is the right primitive here. Moving indent off the inline
style={{marginLeft}}and onto a CSS custom property that StyleX consumes incalc()is exactly what makes indent reachable from@layer astryx-theme/ a token — with no new public API surface. It directly resolves the root cause (consequence 1) and eases (3), since a single layer-settable metric replaces hand-enumerated per-level rules.Why a theme target alone won't work for indent (unlike the guide lines / chevron / label targets): those surfaces are reachable because they're styled through layered CSS, so a
defineThemerule in@layer astryx-themecan win. Indent is different — it's applied as an inlinestyle, and inline styles outrank every cascade layer, including@layer astryx-theme. So adding anastryx-tree-*target on the element can't override it; the value has to first leave the inline style. A CSS custom property (Option A) is the smallest change that does that. This is the one case where a target is insufficient and the underlying mechanism has to change.Hold off on Option C (
indentSizeprop) for now. A new public prop is new API surface and should go through API/spec review rather than riding along in a themeability fix — a sibling guide-line prop was just split out of its PR for exactly that reason. Option A already makes the indent metric themeable through the sanctioned channel, so C isn't needed to unblock the core need; it can be proposed separately if there's demand for an API-level lever.Treat Option B (full-width highlight) as optional and separate. It's only needed if consumers specifically want the selected/hover highlight to span the full row width independent of indent, and it's a DOM-structure change with real visual-regression risk. It shouldn't be bundled into "make indent themeable" — that goal is fully met by A. If full-width highlight becomes a requirement, it deserves its own RFC/PR with a visual baseline.
Net: Option A only. It fixes the root cause with no new API and no structural risk; B and C are separable follow-ups gated on an actual need.
feat(core): make TreeList per-level indent a themeable CSS variable (#…
cixzhang commentedon Jul 30, 2026
Resolved by #4530 (TreeList row indentation theming).