Repository navigation
feat(treelist): flush leaves in all-leaf groups + themeable inter-row gap - #4540
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
PR Analysis Report📚 Storybook PreviewView Storybook for this PR 🧪 Sandbox PreviewView Sandbox for this PR Modified ComponentsTreeList (@astryxdesign/core) · View in Storybook
Bundle Size Summary
Accessibility AuditStatus: No accessibility violations detected. Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
cixzhang
left a comment
There was a problem hiding this comment.
File-explorer-style full-width rows are a legit look, and your margin→padding approach for keeping labels aligned while the box goes edge-to-edge is exactly the right mechanism. Let's discuss the shape before adding API, though: we're cautious about visual-option props unless there are clear enumerable variations, and 'inset' | 'full' is really one styling choice. I checked whether a consumer could paint a full-bleed highlight themselves today — and they can't: the row's hover/selected background lives on the same element that carries the indent margin, so the highlight is always inset. So this is a real gap. My preferred direction: instead of a rowHighlight prop, use your padding-based indent to make the row box full-width structurally, so the existing astryx-tree-list-item theme target becomes a full-bleed surface consumers can style (defineTheme → paint the row background/hover). That way "full-width highlight" is something people style, not a prop we enumerate — and it composes with the hover-reveal work (#4538) and the leaf-flush fix (#4570). Does styling the row target cover your use case if we expose it that way? Happy to pair on where the indent should sit.
Reworked from the earlier `rowHighlight` prop approach per review (#4540): instead of enumerating an `'inset' | 'full'` styling option, make the row box full-width STRUCTURALLY so the existing `astryx-tree-list-item` theme target becomes a full-bleed surface consumers can paint. The per-level indent moves from the row's outer `margin-inline-start` to inner `padding-inline-start`, so the row box spans the tree's full width at every depth. The hover/selected background and focus ring already paint on this element, so they now reach edge-to-edge, and a theme can style the whole row (`defineTheme` → paint `astryx-tree-list-item` background/hover) for a file-explorer-style highlight — no new prop. `--_tree-indent` is unchanged (still `level * step`, plus the leaf chevron-column offset), so labels stay exactly where they were — only how the distance is applied changed. A leaf's highlight is now flush with its sibling parents' (previously a leaf's box was inset past them because the chevron offset lived in the margin), folding in the intent of the now-dropped leaf-flush trial. `padding-inline-start` (longhand) beats the base `paddingInline` origin naturally; the base inline-start padding is folded into the calc so the content start gap is preserved. No API change. Tests assert the indent is never applied as an inline margin and that a leaf and a parent at the same level both start from the box edge. Docs add a best-practice on styling the row target for full-width highlight.
5f65a31 to
d8efc7e
Compare
|
Reworked to your preferred direction — dropped the
Styling the row target covers the use case, yes. Ready for another look. |
cixzhang
left a comment
There was a problem hiding this comment.
Thanks for reworking this exactly as discussed — dropping the prop and turning the row into a full-bleed surface is the right shape, and I confirmed the margin-based indent genuinely blocked full-bleed theming before, so this is a real enabling fix.
Two notes on where it stands:
Since this changes the default appearance for every consumer — at depth > 0 the row background, hover/pressed overlay, and focus-visible outline now extend edge-to-edge instead of starting at the indent — I'd like design sign-off before it lands (it's already tagged needs:design-review). That's the main gate here; the change is defensible (bigger hit target, clearer selection), it just needs a Design yes on the visual shift.
Separately, you don't have to wait on this PR to get the look you want: you can already achieve the full-bleed file-explorer style today by theming the tree-list-item target internally with the same set of styles this PR bakes in — paint the row background/hover/selected via defineTheme on your own theme. So this is unblocked for your use case regardless of when the default change lands.
One system-level heads-up for whoever picks this up after design signs off (not a blocker, and it predates this PR): the per-level indent is now padding-inline-start on the same element that carries the tree-list-item theme target, so a theme that sets padding on that target will override the indent. Worth a changeset/doc line steering themers to background/hover/selected rather than layout padding — or moving the indent onto a dedicated inner wrapper so the two never share a property. Not required for this PR; just flagging so we don't nudge folks straight into it.
f06ebbf to
d51ca55
Compare
|
@cixzhang — ready for another look. Since your last pass:
The 2px default and the full-bleed row (edge-to-edge background/hover/focus at depth > 0) both change the default appearance, so this still wants Design sign-off ( — on behalf of Freddy |
A leaf reserves the chevron-alignment column whenever the tree contains any expandable item (a caret exists somewhere to align labels under), so every row in a hierarchical tree renders exactly as before. Only a fully flat tree — no expandable items at all — drops the empty chevron column and renders its rows flush. The reserve decision is a whole-tree property (computed once at the root), not a per-group one: an all-leaf group nested under an expandable parent still reserves the column so its rows stay indented past the parent's label. Also adds a themeable --tree-list-row-gap (default 0px) for an inter-row gap; the connector guides span the gap automatically and no longer overhang the last row.
Set --tree-list-row-gap's default to var(--spacing-0-5) (2px) so rows have a light separation out of the box, instead of 0px. A theme can still widen or close it via the tree-list target; the guide connectors span the gap as before.
The row-gap test called generateThemeCSSFlat, a helper that no longer exists after the rebase onto main (main renamed the theme-CSS helper). Point it at generateThemeTestCSS, the surviving helper, so the row-gap CSS assertion runs.
d51ca55 to
7647d7c
Compare
|
@cixzhang — this branch has been repurposed to your steer, so the earlier CHANGES_REQUESTED (against the Your ask: don't add a What this PR is now (no new visual-option prop):
So "full-width highlight" is now something you style (paint Rebased clean onto One call for you: default row-gap is a subtle 2px rather than — on behalf of Freddy |
…sExpandableItems Satisfies the @astryx/boolean-prop-naming lint rule (strict mode in CI promotes it to an error), which requires boolean props to start with is/has. Internal prop on TreeListItemInternalProps only — no public API change.
|
Pushed On your two earlier notes:
— on behalf of Freddy |
|
Seems like we'll keep the gap themeable then. Thanks! |
| /** | ||
| * Whether the tree contains at least one expandable item anywhere (i.e. a | ||
| * caret exists somewhere to align labels under). A leaf reserves the chevron | ||
| * column — the extra offset that lines its label up past an expandable | ||
| * ancestor/sibling's caret — whenever this is true, so it stays indented | ||
| * beyond its parent's label. Only a fully flat tree (no expandable items at | ||
| * all) has no caret to align under, so its rows sit flush (no chevron-column | ||
| * offset). Computed once for the whole tree by TreeList. | ||
| */ | ||
| hasExpandableItems: boolean; |
There was a problem hiding this comment.
Hmm should default be true for backwards compatibility? Or perhaps hasOnlyLeaves as the option?
cixzhang
left a comment
There was a problem hiding this comment.
🔴 Blocking — the row-gap margins sit on tree-list-item, the same element that carries themeProps. That placement is both a correctness bug (--tree-list-row-gap renders at half its configured value, TreeListItem.tsx:88) and a seam problem. Moving them onto the existing rowWrapper — as padding-block, which can't collapse — fixes the measurement and keeps tree-list-item a pure paint seam. That's the one thing I'd want fixed before this merges. Also carrying needs:code-review + needs:design-review.
I'd already approved this and I'm not withdrawing that — the shape is right and this is a one-commit fix. But I went back over the theming half with a finer comb and found a real bug that none of the tests can see.
1. 🔴 The row-gap lever delivers half its value
marginBlock: calc(var(--tree-list-row-gap, 0px) / 2) on the row box assumes half-above + half-below sums to a full gap. It doesn't — the margins collapse. Neither rowWrapper (position: relative only) nor li.wrapper (margin: 0; padding: 0) establishes a BFC, so the row box's block margins collapse out through both, and adjacent <li> margins then collapse into each other at max(g/2, g/2).
Measured in Chrome against the exact box structure:
--tree-list-row-gap |
rendered separation |
|---|---|
0px |
0px |
2px (default) |
1px |
4px |
2px |
8px |
4px |
16px |
8px |
The <li> height is unchanged at every value, which confirms the margins are outside it — and that means half the gap leaks above the first row and below the last, collapsing with whatever the consumer put around the TreeList. At a 16px lever that's 8px of phantom margin on each end.
So the documented 2px default is really 1px, and every theme override is off by 2×. Since --tree-list-row-gap is a public, documented lever, the contract in TreeList.doc.mjs and the changeset is wrong as written.
The fix I'd reach for is padding-block on rowWrapper: padding can't collapse, rowWrapper carries no theme target, and the <li>s stay contiguous so the guides still bridge. That also addresses note 2 below. The guide heights in TreeListBranches.tsx:54–65 would need retuning if the <li> starts absorbing the gap.
2. 🟡 Design direction: layout properties on a paint target
Not a blocker on its own and not really this PR's doing — but this PR is where it becomes worth deciding.
A principle I'm converging on: a theming target is a paint seam (color, background, border, radius, shadow, font), not a layout seam (margin, padding, gap, display, position, sizing). Layout encodes the component's structural contract — overflow, hit-target size, RTL, focus order — and it's exactly what a DOM refactor should stay free to change. Where layout genuinely needs to be themeable, it should go through the declared derived-var / container-padding pipeline rather than a raw class target.
The var here passes that test: --tree-list-row-gap is a declared, documented var on the tree-list root, not a raw gap write on a class target. That's the sanctioned mechanism.
The element doesn't. themeProps('tree-list-item') sits on the same contentWrapper that now carries two layout longhands — marginInlineStart (the whole per-level indent) and, new here, marginBlock (the gap) — and the comment frames theme override of them as a feature. A theme writing margin: 0 on tree-list-item today zeroes the indent at every depth and flattens the tree; I confirmed that in the browser. That's the padding footgun I flagged on Jul 31, now pointed at margin too.
The full-bleed row surface we agreed on is a paint seam and I still want it. Relocating the gap per note 1 gets tree-list-item most of the way back to purely paintable; moving the pre-existing indent margin off it too can be a separate PR.
3. 🟡 Two comments describe a 0px default that isn't the default
TreeListBranches.tsx:61-62 ("At the default 0px gap … the default look is unchanged") and TreeListItem.tsx:89-90 ("Default 0px preserves the contiguous look"). The default is --spacing-0-5; 0px is only the var() fallback, which never fires. Leftovers from the pre-Aug-4 pass — worth fixing, because the verticalLast clamp was reasoned under both of those assumptions.
4. 🟡 Tests assert declarations, not geometry
This is why finding 1 got through CI:
- The default-gap test asserts
getPropertyValue('--tree-list-row-gap') === 'var(--spacing-0-5)'— the declaration text. It passes whether the gap renders at 0px, 1px, or 40px. - The two guide tests regex the global StyleX stylesheet via
collectCssText(). StyleX emits everystylex.createrule on import regardless of whether the class is applied, and neither test checks the guide element'sclassName— so both pass even if theisLast ? verticalLast : verticalFullbranch were reverted. The test grabsguide, asserts non-null, then ignores it. reservesColumnparses thecalc()string shape (countingvar(, looking for+). Right thing tested, brittle mechanism.
At least one test should assert a measured separation, and the guide tests should assert the applied class.
The flush-leaf tests themselves are good — the named regression test for the all-leaf-group-under-a-folder case is exactly right.
5. 🟡 A derived mapping would make the obvious spelling work
derivedVarRegistry.ts has no tree-list entries, so this is consistent with --tree-list-indent and not a conformance break. But a theme author's natural first attempt is rowGap on the tree-list target — and since .astryx-tree-list isn't flex or grid, that's a valid declaration that does nothing, silently. A derived entry mapping rowGap → --tree-list-row-gap would fix that and put the lever on the pipeline note 2 prefers.
6. 🟢 PR body describes the superseded behavior
The body still says the flush decision is per-group ("only when its group contains an expandable sibling"). The shipped logic is whole-tree, so only fully flat trees flush. The "Behavior change" section therefore overstates the blast radius — worth updating, it undersells the change.
Related: the changeset says "hierarchical trees render exactly as before" in point (1), which point (2) contradicts by adding a gap to every tree.
On your question from my last pass
hasExpandableItems needs no default. TreeListItem isn't exported — only TreeList is — so there's no back-compat surface, and required is safer than a default that would silently apply old behavior at a forgotten call site. I'd also keep the name over hasOnlyLeaves: it's a whole-tree fact, and the root-only computation is correct since any expandable descendant forces every ancestor to have children.
Process note
These two changes would have been better as two PRs — different blast radius, different review gates, and the bundling is why the changeset ends up asserting something it contradicts. Not worth splitting at this point; just for next time.
Everything else looks good: StyleX only, no raw values, logical properties throughout, no themeable surface removed, and the whole-tree flush decision is genuinely more correct than the per-group version it replaced.
There was a problem hiding this comment.
Approving — clean, well-scoped change. ✅
Both fixes verified against the current branch:
Flush leaves in all-leaf groups — the "check expandability once at the root" optimization is correct: any expandable node forces its whole ancestor chain to be expandable, so a root-level .some() reliably detects whether any caret exists to align under. Edge cases (children: [], children: undefined) are handled consistently with the existing hasChildren derivation. Rendered a flat list from source before/after — leaves reclaim the wasted chevron gutter and sit flush, while mixed trees are pixel-identical. Exactly the intended behavior.
Themeable --tree-list-row-gap — follows the established --tree-list-* lever pattern; the guide-spanning math (bridge on non-last rows, clamp the last-in-group connector by half the gap) keeps the connector continuous with no consumer-side tuning.
On the default 2px gap: this is a good call and worth calling out as a consistency win — List and DropdownMenu already ship the same 2px inter-row gap (--spacing-0-5), so this brings TreeList in line with the rest of the dense-list family rather than introducing a new value. (Separately, we'll look at whether the dense-list row gap should be codified as a shared convention/token so it's defined in one place — but that's a follow-up, not a blocker for this PR.)
Conventions all met: StyleX-only, RTL-safe via logical properties, LTR + zh docs updated, thorough tests covering both the leaf-offset and row-gap/guide behavior. CI green.
One forward-looking, non-blocking thought: the collectCssText() test helper is a nice pattern; if other components start asserting on compiled CSS rules it might be worth promoting to a shared test util.
Review finding (cixzhang, #4540): the inter-row gap sat as margin-block on the row box (contentWrapper) as calc(--tree-list-row-gap / 2) top and bottom, assuming half+half sums to a full gap. It does not — neither the row wrapper (position:relative) nor the <li> (margin/padding:0) establishes a BFC, so the block margins collapse out and adjacent rows collapse to max(g/2,g/2)=g/2. The lever delivered HALF its configured value (2px default rendered 1px) and half leaked above the first row / below the last. Move the gap onto rowWrapper as padding-block: padding cannot collapse, so the full gap renders; rowWrapper carries no theme target, so the paintable tree-list-item stays a pure paint seam (layout off the paint target, per the theming-target guidelines in #4774); and the <li>s stay contiguous so the guides still bridge. Retune the guide heights: the gap now lives inside the <li> (padding), so verticalFull no longer adds the gap (100% already covers it, +1px hairline bridge) and verticalLast clamps 100% - gap/2 to end at the row bottom. Tests: assert the APPLIED verticalFull/verticalLast class on a row s own connector (not a global-stylesheet regex, which passed regardless), and assert the gap rides padding-block on the row wrapper and NOT margin-block on the paint target. Verified the new geometry test fails on the pre-fix margin placement. Changeset corrected: (1) no longer claims hierarchical trees are unchanged, and (2) states the 2px default shifts every tree (matching List/DropdownMenu).
|
Pushed 1. 🔴 Row-gap delivered half its value → fixed. You're right on the mechanism: Guide-height retune (the part you flagged would need it): the gap now lives inside the 2. 🟡 Layout on a paint target → resolved by (1). With the gap moved off 3. 🟡 Stale 4. 🟡 Tests asserted declarations, not geometry → rewritten.
5. 🟢 6. 🟡 PR body + changeset → corrected. Body now describes the shipped whole-tree flush (only fully flat trees flush) instead of the superseded per-group wording, and no longer claims hierarchical trees are unchanged. Changeset point (1)↔(2) contradiction removed: (2) now states plainly that the 2px default shifts every tree (framed as the On the process note — agreed, these were two changes and should've been two PRs; noted for next time. 76/76 tests, typecheck, strict lint all green. — on behalf of Freddy |
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.
What
Two upstream TreeList fixes that let consumers drop fragile parity CSS:
Flat-tree leaves render flush. A leaf reserved a chevron-alignment column (chevron width + gap) on top of its level indent unconditionally — even when nothing in the tree had a caret to align under. That reservation is now a whole-tree decision: a leaf reserves the column whenever the tree contains any expandable item anywhere (checked once at the root, since any expandable descendant forces its whole ancestor chain to be expandable). So only a fully flat tree — no expandable items at all — renders its rows flush; any tree with at least one caret keeps the same per-level alignment as before, including all-leaf groups nested under a folder (they stay indented past their parent's label).
Themeable inter-row gap
--tree-list-row-gap(default2px,var(--spacing-0-5)). Opens a subtle vertical separation between rows, matching the inter-row gapListandDropdownMenualready ship. The gap rides collapse-proofpadding-blockon the row wrapper — notmargin-blockon the paintabletree-list-itemtarget — so it delivers its full configured value and keeps the paint seam free of layout (per the theming-target guidelines in feat(lint): automate the rubric's §2 theming-target checks #4774). The<li>s stay contiguous, so the connector guides span the gap by construction; the last-in-group guide is clamped internally so it does not overhang. Set it on thetree-listtarget to widen or close the gap.Why
Both are real gaps consumers currently work around with brittle structural CSS (
:has()/:not([aria-expanded])leaf-offset hacks, adata-*-gated flat-list reset, and a hand-tuned guide-height + last-child clamp to fake a row gap). Fixing them upstream makes that CSS deletable and reduces the parity layer to sanctioned theme overrides.Behavior change
2pxdefault inter-row gap. This is a deliberate default shift (it brings TreeList in line withList/DropdownMenu, both--spacing-0-5); a theme can close it to0pxvia thetree-listtarget.Notes
--tree-list-indentremains the per-level step lever;--tree-list-row-gapis orthogonal.hasExpandableItemsonTreeListItemInternalProps(not exported), required (no default) per review.