Skip to content

fix(TreeList): make the row indent reachable from the theme layer (RFC #4308, Option A) - #4448

Closed
AKnassa wants to merge 1 commit into
meta:mainfrom
AKnassa:rocky/issue-4308-treelist-indent
Closed

AKnassa wants to merge 1 commit into
meta:mainfrom
AKnassa:rocky/issue-4308-treelist-indent

Conversation

@AKnassa

@AKnassa AKnassa commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Summary

Implements Option A of RFC #4308, and only Option A.

TreeListItem applied the per-level indent as an inline margin-inline-start on the row's content wrapper — the same element that carries the astryx-tree-list-item theme target. An inline longhand outranks every cascade layer, so a rule in @layer astryx-theme could never win against it. The indent was outside the theming contract entirely, and consumers were pushed into !important/unlayered CSS.

- style={{marginInlineStart: computedMarginLeft}}
+ style={indentStyle}                      // {'--_tree-indent': …}

  contentWrapper: {
+   marginInlineStart: 'var(--_tree-indent, 0px)',
  }

A custom property carries a value, not a declaration, so it doesn't create the same specificity floor. margin-inline-start now lives in @layer astryx-base where the theme layer overrides it in normal cascade order.

Rendering is unchanged at every nesting depth, including the extra chevron-width offset leaves carry so their labels line up with sibling parents' labels.

What this does not do

RFC consequence (1) is a cascade bug — a themeable surface that no sanctioned channel can reach — so fixing it doesn't need a decision. The other two do, and I've left them alone:

  • Option B (move the indent to an outer element so the highlight can span the full row, clearing consequence 2) is a DOM-structure change with back-compat and visual-regression risk. It wants a snapshot/visual baseline and your call.
  • Option C (indentSize prop, consequence 4) is new public API.

Consequence (3) — per-level insets not derivable in calc() because data-tree-level lives on the <li> rather than the themed element — is unchanged by this PR, and as the RFC notes it isn't fully resolvable in pure CSS while that stays true.

Naming: I used the private --_tree-indent, matching the file's existing --_tree-focus-outline convention, since the per-row value is an implementation detail — what becomes theme-reachable is the margin-inline-start declaration, not the variable. If you'd rather publish it as a documented --astryx-* lever (a second, finer control), that's a one-line rename and I'm happy to make it.

Tests

New TreeListItem.indentReachable.test.tsx — 5 tests pinning the two facts the fix rests on: no inline margin-inline-start/margin-left on the themed row at any depth, and a stylesheet rule declaring margin-inline-start from the variable. They deliberately don't depend on jsdom resolving @layer precedence, which it doesn't do reliably — the assertions are about where the declaration lives, which is the part that determines the outcome in a real browser.

TreeList.test.tsx's noGuides indentation test asserted the inline longhand directly, so it now reads the variable. Its intent is unchanged: indent survives when connectors are suppressed, and grows with depth.

Mutation-checked: restoring the inline longhand fails 5 tests.
All 69 TreeList tests green. pnpm check:repo, eslint and tsc --noEmit clean.

The row's content wrapper is the `astryx-tree-list-item` theme target, and
its per-level indent was applied as an inline `margin-inline-start`. An
inline longhand outranks every cascade layer, so `@layer astryx-theme` could
never win against it — the indent sat outside the theming contract entirely
and consumers had to reach for `!important` or unlayered CSS.

The row now publishes only the computed distance as `--_tree-indent` and
`margin-inline-start` is declared in `styles.contentWrapper`, which lands in
`@layer astryx-base` where the theme layer can override it normally. A
custom property carries a value, not a declaration, so it does not create the
same specificity floor.

Rendering is unchanged at every nesting depth, including the extra
chevron-width offset leaves carry so their labels align with sibling parents.

This is Option A of the RFC only. Option B (moving the indent onto an outer
element so the highlight can span the full row) is a DOM-structure change
with back-compat and visual-regression risk, and Option C (an `indentSize`
prop) is new public API. Both are calls for maintainers, not consequences of
fixing the cascade bug.

`TreeList.test.tsx`'s noGuides indentation test asserted the inline longhand
directly, so it now reads the variable instead; its intent — indent survives
when connectors are suppressed, and grows with depth — is unchanged.

Refs meta#4308
@vercel

vercel Bot commented Jul 28, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
astryx Ready Ready Preview, Comment Jul 28, 2026 6:06am

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jul 28, 2026
@github-actions github-actions Bot added community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge labels Jul 28, 2026
@github-actions

Copy link
Copy Markdown
Contributor

PR Analysis Report

Modified Components

TreeList
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 759 -
Complexity N/A Very High (78) -

Bundle Size Summary

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

Accessibility Audit

Status: No accessibility violations detected.


Generated by PR Enrichment workflow | View full report

@cixzhang

Copy link
Copy Markdown
Contributor

Thanks so much for this, @AKnassa — your write-up of the root cause was spot on: the indent was pinned to an inline margin-inline-start on the same element as the astryx-tree-list-item theme target, so it outranked every cascade layer and was unreachable from @layer astryx-theme. That framing is exactly what made the fix obvious.

We landed a forward fix in #4530 that builds on the same Option A cascade change you identified, and also takes you up on the offer at the end of your description — publishing the per-level step as a documented, public lever (--tree-list-indent, default var(--spacing-4)) rather than keeping it as the private --_tree-indent. That lets a theme retune the indent metric (e.g. to var(--spacing-5)) via defineTheme on the tree-list target, and the guide lines read the same variable so they stay aligned.

Since #4530 covers this ground, I'm going to close this PR — but the diagnosis here is what got us there, so thank you. Hope to see more contributions from you. 🙏

@cixzhang cixzhang closed this Jul 30, 2026
@github-actions
github-actions Bot deleted the rocky/issue-4308-treelist-indent branch July 30, 2026 08:22

This branch was successfully deployed

1 active deployment
Preview — faf69608 Deployed Jul 28, 2026 by vercel[bot]
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. community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants