Skip to content

feat(TreeList): customizable expand/collapse indicator icon - #4228

Closed
AKnassa wants to merge 13 commits into
meta:mainfrom
AKnassa:ak-4131-treelist-expand-icon
Closed

AKnassa wants to merge 13 commits into
meta:mainfrom
AKnassa:ak-4131-treelist-expand-icon

Conversation

@AKnassa

@AKnassa AKnassa commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Closes #4131

What this does

Lets a TreeList choose its own expand/collapse icons instead of the built-in rotating chevron — so a file tree can show a closed folder that becomes an open folder, with file icons on the rows that can't expand.

How

One new tree-level prop, with the shape proposed in the issue:

<TreeList
  items={items}
  renderExpandIcon={({isExpanded, hasChildren}) =>
    hasChildren
      ? isExpanded
        ? <FolderOpenIcon width="1em" height="1em" />
        : <FolderIcon width="1em" height="1em" />
      : <DocumentIcon width="1em" height="1em" />
  }
/>
  • Called per item with {isExpanded, hasChildren, isDisabled} (exported as TreeListExpandIconState). Leaves get the call too, so file trees can fill the indicator slot — rows with a leaf icon align to the indicator column.
  • Custom icons swap per state; the chevron's rotation animation is suppressed for them, per the issue's note (an open folder shouldn't also rotate).
  • Returning undefined keeps the default: the chevron for parents, and no indicator (with the usual alignment offset) for leaves. Any other result, null included, fills the indicator box, which keeps the column's width when it renders nothing.
  • The result is decorative: it is aria-hidden and inert, so it never joins a row's name or takes focus. The toggle's accessibility wiring is untouched regardless of the icon: aria-expanded, localized aria-label, roving tabindex, data-tree-toggle.
  • The result renders as given, with no rotation or mirror (a folder isn't directional). A glyph that points reads useDirection() from @astryxdesign/core/i18n to face the right way in right-to-left.
  • Without the prop, rendering is unchanged.

Per-item overrides stay out, as the issue suggests ("could come later").

How to see it

Storybook → Core/TreeList → Custom Expand Icons
custom-icons-initial-dark
custom-icons-initial-light
custom-icons-public-expanded
default-chevron-basic-dark
default-chevron-basic-light

Proof

  • First round: 24 new tests (TreeList.test.tsx 47 → 71), red-first for the feature, plus edge cases — disabled parents, children: [], isExpanded on leaves, Enter routing on clickable parents, string/empty returns, deep nesting, render-prop swap on re-render, ArrowLeft collapse. Six deliberate mutations each fail exactly one test.
  • Full suite green (core+lab 5090, cli 2178); core/docs/storybook typecheck and lint clean.
  • Docs updated (en/zh/dense) and rendering via astryx component TreeList --dense; changeset included.

Maintainer round (merge of main, review fixes, record)

Two commits on top; AKnassa's commits are unchanged.

  1. Merge main:
    • TreeListItem.tsx and TreeList.test.tsx are resolved against main's TreeList work (guides aligned to chevrons, disabled rows as aria-disabled, the touch press changes, isRenderable slots).
    • The feature is carried onto main's TreeListItem. renderExpandIcon fills the Chevron, or a Leaf indicator for a leaf, in the default Chevron's own --spacing-4 box.
    • The default chevron keeps its pinned glyph. A tree without the prop renders exactly as before under every theme: the earlier 1rem column shrank the chevron from 24 px to 16 px under Matcha and Y2K.
    • The size tests now pin the --spacing-4 box; they failed on the previous head, which used 1rem. The docs and changeset no longer describe a 1rem column, and the disabled-parent test reads aria-disabled.
  2. Record: component:TreeList FR1 and FR3 name the caller's indicator and its fallbacks.
    • The ownership boundary says the custom indicator is the caller's and the default glyph stays Icon's.
    • An Expand indicator row joins the public concepts.
    • The anatomy map and the consumer anatomy gain the Leaf indicator.
    • FR3's verification row names the renderExpandIcon suite.

TreeList tests pass (158), as do strict lint, the core type check, check-knowledge and check:changesets.

Maintainer round 2 (owner decision, a11y, fallback rule)

One commit on top; AKnassa's commits are unchanged.

  • Owner decision: the owner chose this render-icon approach for a folder-like tree, over a theme icon slot, so renderExpandIcon and the exported TreeListExpandIconState ({isExpanded, hasChildren, isDisabled}) stay as proposed.
  • Accessibility: the custom glyph inside the toggle and the leaf indicator are aria-hidden and inert. Before, a labeled leaf icon could join the row's name.
  • Fallback rule: undefined keeps the default; null (and false or '') gives an empty box that keeps the column, one rule for parents and leaves. Before, null fell back to the chevron.
  • Right-to-left: no mirror of the caller's glyph, as before; the record now says a direction-bearing glyph handles right-to-left through useDirection().
  • Record (component:TreeList): the Expand indicator row, FR3 and AR1 state the above, including "a rendered indicator is decorative".
  • Tests: red-first against the previous head: an empty box for null, false and ''; the glyph and the leaf indicator aria-hidden and inert, with the toggle's name and aria-expanded kept. Also: the glyph renders untransformed in right-to-left, the default chevron still mirrors, and a render that returns undefined produces the same markup as no prop. TreeList tests pass (163); lint is clean.
  • Size: TreeList's eager gzip is 43.5 KB on main and 43.7 KB here (+0.2 KB). A tree that doesn't pass the prop renders exactly as before.

At this head the renderExpandIcon suite has 32 tests, and the TreeList tests pass (163). A third commit scopes FR8's turning to the default Chevron glyph and fixes two internal comments.

Writing rubric results

Run over the component:TreeList changes (the ownership lines, the Expand indicator row, FR1, FR3, FR8, AR1, the anatomy map, the consumer state table and the FR3 verification row):

  • R1 narration: FR3's "a tree without the prop renders unchanged" compared against a change; it now reads "renders as with a result of undefined". Every other line states the system in the present tense.
  • R2 research: none.
  • R3 evidence: tests, not pull requests; the verification row names the renderExpandIcon suite.
  • R4 rejected alternatives: none.
  • R5 change references: none; no pull request or issue number in the record lines.
  • R6 open questions: none added or answered.
  • R7 project status: none.

Maintainer round 3 (one scale for the column and the glyph)

One commit on top; AKnassa's commits are unchanged. It answers the owner's review asking for the indicator column and its glyph on one scale.

  • The box: a custom glyph and the Leaf indicator render in the default Chevron's own box (--spacing-4, with its font size), and clip a larger node, so the column never widens. Artwork drawn at 1em fills the box at every text size, the same as the default chevron. An unsized <Icon> (20px by default) no longer pushes the label.
  • Guidance: FR3, the docs (en, zh, dense), the JSDoc example, the story and the changeset say to draw glyphs at 1em (for example <FolderIcon width="1em" height="1em" />), in place of "size icons sm". Icon's sm and --spacing-4 are both 1rem in the default theme, but a theme that sets --spacing-4 to another length (Matcha and Y2K use 1.5rem) parts them, while 1em artwork follows the box in every theme.
  • Tests: a unit case checks that both boxes clip to the --spacing-4 box at 1em, and it fails on the previous head. A new browser spec, TreeListCustomIndicator.interaction.browser.spec.ts, measures at 100% and 200% root font size against the default chevron: 1em artwork fills the box, an unsized Icon (a story fixture hidden from the docs) keeps the column width, and the label keeps the default gap. TreeList's unit tests pass (164); I did not build Storybook locally, so CI runs the browser spec.
  • Wording nits: FR3 reads "without rotation, and without an RTL mirror or RTL swap"; the Chevron glyph row and the doc anatomy say a renderExpandIcon result takes its place.

Add a tree-level render prop to customize the expand/collapse
indicator. Called per item with {isExpanded, hasChildren, isDisabled}
so a file tree can show closed/open folder icons and a file icon in
the indicator slot of leaves. Custom icons swap per state (the chevron
rotation animation is suppressed); non-renderable returns fall back to
the default chevron for parents and to no indicator for leaves. The
toggle's a11y wiring (aria-expanded, aria-label, roving tabindex,
data-tree-toggle) is unchanged regardless of the icon.

Closes meta#4131
@vercel

vercel Bot commented Jul 23, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
astryx Ready Ready Preview Nov 12, 2026 1:04pm UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jul 23, 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 needs:design-review Affects visuals — Design should review labels Jul 23, 2026
@github-actions

github-actions Bot commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · c74dbf9

Storybook · Sandbox · built from this PR's head

Modified components

Component Size LoC Visual · A11y · RTL
PowerSearch 300.0 kB (+118 B) · 24.7 kB CSS (0) — — · — · —
TreeList · Storybook 46.2 kB (+95 B) · 5.6 kB CSS (0) 1,285 (+66) ✓ · ✓ · ✓

Package size: @astryxdesign/core 7.38 MB packed (+3.7 kB); no new dependencies.

API changes: core +3 · ~0 · −0

3 API changes (advisory)
Package Where Signature Usage
+ core . · Components · component TreeList prop renderExpandIcon?: (state: TreeListExpandIconState) => ReactNode <TreeList renderExpandIcon={…} />
+ core . · Types · interface TreeListExpandIconState interface TreeListExpandIconState import type {TreeListExpandIconState} from '@astryxdesign/core'
+ core ./TreeList · Also exported from an earlier entry point · TreeListExpandIconState TreeListExpandIconState (.) import {TreeListExpandIconState} from '@astryxdesign/core/TreeList'

Touched components checked; add ci:run-visual or ci:run-rtl to run the full suites.


Generated by PR Enrichment workflow | View full report

@AKnassa
AKnassa marked this pull request as ready for review July 23, 2026 23:58

@cixzhang cixzhang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this — the state-aware swap and the leaf slot are exactly what the issue asked for, and the tests are thorough.

One thing before it lands. The indicator column sizes its glyph with fontSize: --spacing-4, which works because the default chevron is a 1em registry icon. An <Icon> carries its own rem box and ignores it, so the folder example draws 20px in the 16px column — and at the browser's large-text setting, 25px, with the label's gap gone. size="sm" only lines up at a 16px root.

It'll also need a merge with main — TreeList's chevron block moved since July.

Ideally I'd like the column and the glyph on one scale. Would making the column 1rem, so size="sm" tracks it, work — or would you rather the indicator size whatever it's handed?

If you'd rather talk it through with someone, we're in Discord.

[Reviewed by Robohands]

},
// Indicator slot for leaf items when renderExpandIcon supplies a leaf icon.
// Same metrics as the chevron toggle so leaves align, but non-interactive.
leafIconContainer: {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sets the token box but an <Icon>'s own rem width wins. Glyph still overflows.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now the shared indicatorColumn box (1rem). An sm Icon fills it at any root font size.

Comment thread packages/core/src/TreeList/TreeList.tsx Outdated
* items={items}
* renderExpandIcon={({isExpanded, hasChildren}) =>
* hasChildren
* ? (isExpanded ? <Icon icon={FolderOpenIcon} /> : <Icon icon={FolderIcon} />)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This example is what people will copy. Might want a size on it once the column's settled.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The example, the story and the docs now pass size="sm", and a guidance line in TreeList.doc.mjs spells out the 1rem column.

@cixzhang

Copy link
Copy Markdown
Contributor

Checking in on TreeList indicators: the custom glyph and its column still need one size contract after merging main. Would you like to continue, have us carry it, or close this for now?

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.
…ta#4131)

Review round for meta#4228. The indicator column (toggle, non-interactive
chevron box, leaf slot) was --spacing-4, a 16px token, while <Icon> keeps
its own rem box: the folder example drew 20px in a 16px column and 25px at
a 20px root, with the label gap gone. The column is now 1rem, the same box
as <Icon size="sm">, shared by one indicatorColumn style; the default
chevron drops its --spacing-4 re-pin and lives on the same contract, and
the null-leaf offset uses the same length so labels stay aligned at any
root font size. A custom icon is now the column's direct child (no wrapper
span), rendered as handed over: no rotation, no RTL mirror.

Docs, story and changeset say size="sm". Tests read the compiled StyleX
rules back (declarationsOf) to assert the shared 1rem box, the un-pinned
chevron, the 1rem leaf offset, and the transform-free custom icon.

Measured in Chrome: column/glyph 16/16 at a 16px root, 20/20 at a 20px
root, overflow 0, label gap 4px at both.
@AKnassa

AKnassa commented Aug 28, 2026

Copy link
Copy Markdown
Contributor Author

Continuing. Round pushed at 7eb427e:

  • The indicator column is now 1rem, the <Icon size="sm"> box: the toggle, the leaf slot and the default chevron share one indicatorColumn style, and the chevron's --spacing-4 re-pin is gone. The null-leaf offset uses the same length, so labels stay aligned as the root font size changes.
  • Measured in Chrome on the story: column and glyph 16/16 at a 16px root, 20/20 at a 20px root, glyph overflow 0, label gap 4px at both.
  • "Size whatever it's handed" was not reachable: the column cannot resize a consumer's <Icon> without cloneElement, and a stretch-to-fit column breaks the null-leaf offset.
  • Merged main (84d6ccb66); the four alignment tests now read --_tree-indent. Docs, story and changeset say size="sm".
  • Left alone: --tree-list-indent stays a px token beside the rem column. At a 20px root that is a 16px step next to a 20px column, which still reads fine, and it is the existing lever.

github-actions Bot added a commit that referenced this pull request Aug 28, 2026

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approval recommended. TreeList now supports the maintainer-requested renderExpandIcon for state-aware folder and file indicators — custom icons swap instead of rotating, non-renderable returns fall back to the default chevron or no leaf indicator, and the toggle's accessibility wiring is preserved. The indicator column, default chevron, leaf slot, and leaf offset now share the directed 1rem (Icon size="sm") box, so alignment holds at non-default root font sizes. Focused tests and the repository's test, lint, accessibility, RTL, and visual checks pass; please inspect the pending visual-acceptance report for the intentional indicator pixels before merging.

[Automated review]

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is on hold for a maintainer decision, not for a code defect.

The implementation is well supported: renderExpandIcon swaps state-aware parent icons, renders leaf icons in the indicator slot, falls back to the default chevron or no leaf indicator for non-renderable returns, preserves the toggle's accessibility wiring, and the focused tests and repository checks pass. No concrete defect was found.

Approval needs a maintainer to provide or identify the governing spec for this addition, or to record the ruling in the TreeList component record and approve this exact revision. What must be settled is: the tree-level renderExpandIcon prop and its exported state type, including leaf invocation, the fallback behaviour, and custom icons swapping instead of rotating; and the shared 1rem indicator column, which also changes the default chevron and leaf offset at non-default root font sizes. The feature request and review discussion show the maintainer's intent, but no current spec record yet covers these additions, so they cannot be approved on that discussion alone. No code change, removal, or split is being requested solely because of this hold.

[Automated review]

Resolved conflicts:
- packages/core/src/TreeList/TreeList.test.tsx: both sides appended tests at
  the end of the top-level describe('TreeList'). Kept both: this branch's
  describe('renderExpandIcon') block (with its closing brace), followed by
  upstream's three consumer onKeyDown tests (meta#5606).

TreeList.tsx, TreeListItem.tsx, TreeListTypes.ts and TreeList.doc.mjs
auto-merged; the merged diff against upstream/main is only this PR's delta.
…eta#4131)

X2: TreeListExpandIconState.isExpanded is documented as "Always false for
leaf items", but a parent toggled open by the user keeps its override-map
entry after its children are removed, so the now-leaf row called
renderExpandIcon with {isExpanded: true, hasChildren: false}. The call site
now passes `hasChildren && isExpanded`; expansion state and aria-expanded
(already guarded by hasChildren) are untouched.

Proof: new test "reports isExpanded false for a leaf whose expanded parent
lost its children" (toggle open via the button, rerender with
`children: []`) failed before the change with the last call receiving
`isExpanded: true`, and passes after it.
@cixzhang
cixzhang marked this pull request as draft November 12, 2026 09:22
@github-actions github-actions Bot added the needs:spec-owner-review Current knowledge records await owner approval label Nov 12, 2026
@cixzhang

Copy link
Copy Markdown
Contributor

/approve-spec 899ad05

@github-actions github-actions Bot removed the needs:spec-owner-review Current knowledge records await owner approval label Nov 12, 2026

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes requested: renderExpandIcon covers what #4131 asks for, the TreeList record change has an engineering owner's approval at this commit, and a tree without the prop keeps today's code path; one description fix remains.

Blocking

  • The ## Writing rubric results lines for R4 to R7 report "history", "status", "vague scope" and "duplication", but the rubric in docs/contributing/spec-writing.md asks for R4 rejected alternatives, R5 change references, R6 open questions and R7 project status, so replace those four lines with the rubric's items (on the record lines this pull request adds, each reads none).

Before merge

The changes-requested review an engineering owner left on an early commit stays in effect until that reviewer re-reviews or dismisses it, and CI has not run on this head while it is a draft. Two optional suggestions are inline: FR3's "renders unchanged" wording and a shorter comment in TreeListItem.tsx.

Claims and files checked
  • Verified: the new prop is called for every row with its expanded, children and disabled state (TreeListItem.tsx:551-559).
  • Verified: parents can show folder icons and leaves a file icon in the same column, with leaves lined up (TreeListItem.tsx:578-579, 694-698).
  • Verified: the result replaces only the chevron glyph, with no rotation or mirror, and a pointing glyph can read the direction hook from @astryxdesign/core/i18n (TreeListItem.tsx:261-268, 639-645; i18n/index.ts:41).
  • Verified: only undefined keeps the default; null, booleans and '' fill an empty box (TreeListItem.tsx:563, and the matching tests).
  • Verified: the result is hidden from assistive technology and inert, and the toggle keeps its name, state and keys (TreeListItem.tsx:640, 695).
  • Verified: icons should be sm, since the column is the default chevron's --spacing-4 box, 16px by default (tokens.stylex.ts:193, Icon.tsx:80-82).
  • Verified: trees without the prop render as before under every theme (every new branch needs a result other than undefined; the chevron's styles are unchanged).
  • Verified: the state type is exported (TreeList/index.ts:35), and the prop has the shape #4131 proposes, with per-item overrides left out.
  • Verified: the Custom Expand Icons story, the English, Chinese and dense docs, the size tests on the --spacing-4 box and the disabled-parent test.
  • Verified: the earlier 1rem column shrank the chevron from 24px to 16px under Matcha and Y2K, whose spacing step is 1.5rem.
  • Verified: the TreeList record names the caller's indicator, its fallbacks, the decorative rule, the Leaf indicator and a swap instead of a turn (FR1, FR3, FR8, AR1, anatomy, verification row), and the latest commit scopes FR8 and fixes two comments.
  • Verified: the renderExpandIcon suite has 32 tests at this commit; the 163 passing TreeList tests match a count of the test files but were not run here.
  • False: the writing-rubric results for R4 to R7 name checks the rubric does not define (blocking above); R1 to R3 answer the rubric.
  • Not reproduced here: the first round's counts and mutation runs, full-suite counts, lint, type check, knowledge and changeset checks, the dense CLI render and the bundle size.
  • Files: .changeset/treelist-render-expand-icon.md clear; apps/storybook/stories/TreeList.stories.tsx clear; docs/specs/components/TreeList/TreeList.spec.md non-blocking wording notes; packages/core/src/TreeList/TreeList.doc.mjs non-blocking note on the Chevron glyph text; TreeList.test.tsx clear; TreeList.tsx clear; TreeListItem.tsx non-blocking notes on a comment and the icon size default; TreeListTypes.ts clear; index.ts clear.

Automated review (maintainer link)

@github-actions github-actions Bot added the needs:spec-owner-review Current knowledge records await owner approval label Nov 12, 2026
@cixzhang

Copy link
Copy Markdown
Contributor

/approve-spec 29c2271

@github-actions github-actions Bot removed the needs:spec-owner-review Current knowledge records await owner approval label Nov 12, 2026

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approval waits on one decision. An engineering owner left a changes-requested review on an early commit, asking for the indicator column and its glyph on one scale, and only that reviewer can re-review or dismiss it. Otherwise this commit checks out: the TreeList record change has an engineering owner's approval for this exact commit, the writing-rubric results now cover R1 to R7, and a tree without renderExpandIcon keeps today's code path. CI has not run on this commit while the pull request is a draft.

Three optional suggestions:

  • Miss: FR3's "without rotation, RTL mirror or swap" reads against FR8's "swaps instead"; "without rotation, and without an RTL mirror or RTL swap" keeps the two apart (inline).
  • An unsized Icon in the indicator defaults to md and overflows the 1rem box by 4px; giving the indicator boxes a default sm icon size would make the docs' sizing advice unnecessary (inline).
  • The Design relationships Chevron glyph row and the doc anatomy still describe the glyph as Icon's alone (inline on the doc anatomy).
Claims and files checked
  • Verified: the prop is called for every row with its expanded, children and disabled state (TreeListItem.tsx:551-559).
  • Verified: parents can show a closed or open folder and leaves a file icon in the same column, with leaves lined up (TreeListItem.tsx:578-579, 637-643, 692-696).
  • Verified: the result replaces only the chevron glyph, with no rotation or mirror, and a pointing glyph can read the direction hook from @astryxdesign/core/i18n.
  • Verified: only undefined keeps the default; null, booleans and '' fill an empty box (TreeListItem.tsx:563, and the matching tests).
  • Verified: the result is hidden from assistive technology and inert, and the toggle keeps its name, state, roving focus and keys (TreeListItem.tsx:638, 693, 652-666).
  • Verified: icons should be sm, since the column is the default chevron's --spacing-4 box, 16px by default.
  • Verified: trees without the prop render as before under every theme; the default chevron's styles are unchanged, and a 1rem column would have shrunk it under Matcha and Y2K.
  • Verified: the state type is exported from the package root and ./TreeList, and the prop has the shape the issue proposes, with per-item overrides left out.
  • Verified: the Custom Expand Icons story, the English, Chinese and dense docs, the size tests on the --spacing-4 box and the disabled-parent test.
  • Verified: the TreeList record names the caller's indicator, its fallbacks, the decorative rule, the Leaf indicator, a swap instead of a turn, and the test suite that verifies FR3.
  • Verified: the renderExpandIcon suite has 32 tests; the writing-rubric results answer R1 to R7 with the rubric's own items.
  • Not reproduced here: the passing test counts, red-first and mutation runs, lint, type check, knowledge and changeset checks, the dense CLI render and the bundle size.
  • Files: the changeset, the story, TreeList.tsx, TreeList.test.tsx (read, not run), TreeListTypes.ts and index.ts are clear; TreeList.spec.md, TreeList.doc.mjs and TreeListItem.tsx carry the optional notes above.

Automated review (maintainer link)

@cixzhang
cixzhang marked this pull request as ready for review November 12, 2026 12:15
… and never widens the column

The custom glyph box and the Leaf indicator keep the default Chevron's
--spacing-4 box and font size, and clip a larger node, so 1em artwork
fills the column at every text size and an unsized Icon cannot push the
label. FR3, the docs, the example and the changeset say to draw glyphs
at 1em. A browser spec measures the box, the artwork and the label gap at
100% and 200% root font size against the default chevron.

Co-authored-by: AKnassa <[email protected]>
@cixzhang
cixzhang marked this pull request as draft November 12, 2026 12:51
@github-actions github-actions Bot added the needs:spec-owner-review Current knowledge records await owner approval label Nov 12, 2026
@cixzhang

Copy link
Copy Markdown
Contributor

/approve-spec c74dbf9

@cixzhang

Copy link
Copy Markdown
Contributor

Decision: D-20261112-384

@github-actions github-actions Bot removed the needs:spec-owner-review Current knowledge records await owner approval label Nov 12, 2026

@astracat-bot astracat-bot Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes requested: renderExpandIcon does what #4131 asks for, and an engineering owner approved the TreeList record change for this commit, but two claims in the description are wrong.

  • The "Maintainer round 3" Guidance line says the old "size icons sm" advice matched only at a 16px root, but Icon's sm and --spacing-4 are both 1rem, so they matched at every text size in the default theme and differ only under themes that set --spacing-4 to 1.5rem (Matcha, Y2K); please correct that reason.
  • Miss: the Proof line says the first round added 23 tests (48 → 71), but that commit adds 24 tests to TreeList.test.tsx (47 → 71); please correct the count.

Approval also waits on the changes-requested review an engineering owner left on an early commit about sizing the indicator column and its glyph, which only that reviewer can re-review or dismiss. CI has not run on this commit while the pull request is a draft, so the new browser spec has not run yet. The inline notes on two comments in TreeListItem.tsx and an unused test parameter are optional, as is adding the new browser spec to the record's verified_by list.

Claims and files checked
  • Changeset, verified: the new tree-level renderExpandIcon prop is called for each row with its expanded, children and disabled state (TreeList.tsx:187, TreeListItem.tsx:557-569).
  • Changeset, verified: parents can show a closed or open folder and leaves a file icon in the same column, and a leaf with an icon lines up with its parent (TreeListItem.tsx:584-585, 698-702).
  • Changeset, verified: the result replaces only the chevron glyph and is not rotated or mirrored (TreeListItem.tsx:643-649); useDirection() is exported from @astryxdesign/core/i18n (i18n/index.ts:41).
  • Changeset, verified: only undefined keeps the default, and any other result fills the box (TreeListItem.tsx:569).
  • Changeset, verified: the result is hidden from assistive technology and inert, and the toggle keeps its localized name, aria-expanded and keys (TreeListItem.tsx:644, 662, 699).
  • Changeset, verified: the column is the default chevron's --spacing-4 box, 1em artwork fills it and larger content is clipped (TreeListItem.tsx:264-286).
  • Changeset, verified: trees without the prop take the unchanged path (every new branch needs a result other than undefined, and a test compares the markup), and TreeListExpandIconState is exported (TreeList/index.ts:35).
  • Description, verified: the prop has the shape the issue proposed, leaves get the call, per-item overrides stay out, and the story is Core/TreeList, Custom Expand Icons.
  • Description, verified: the maintainer rounds keep the contributor's commits unchanged, use the --spacing-4 box (a 1rem box would shrink the chevron from 24px to 16px under Matcha and Y2K), drop 1rem from the docs and changeset, and amend the record's ownership, concept table, FR1, FR3, FR8, AR1, anatomy map and verification row.
  • Description, verified: null, false and '' give an empty box; the decorative, right-to-left and unchanged-markup tests exist; the clip test fails without the clip; the writing-rubric results match the changed record lines.
  • Description, false: the first round added 24 tests (47 → 71), not 23 (48 → 71).
  • Description, false: sm icons matched the box at every text size in the default theme, not only at a 16px root.
  • Description, not shown: that an unsized Icon pushed the label before this commit; the box already had a fixed width, so the clip changes what paints, not the layout.
  • Description, stale: round 2's count of 32 renderExpandIcon tests is 33 at this commit.
  • Not reproduced here: the passing test counts, red-first and mutation runs, lint, type check, knowledge and changeset checks, the dense CLI render, the bundle size and the browser spec's results.
  • Files: the changeset, the story, TreeList.tsx, TreeList.doc.mjs, TreeListTypes.ts, index.ts and the browser spec are clear; TreeListItem.tsx (two comments), TreeList.test.tsx (an unused parameter) and TreeList.spec.md (verified_by omits the new browser spec) have optional notes.

Automated review (maintainer link)

Comment on lines +260 to +263
// A caller's glyph inside the toggle, centred in the chevron column.
// A caller's glyph inside the toggle: the Chevron's box. Artwork drawn at
// `1em` fills it at every text size, and a larger node is clipped, so the
// column never widens.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking: the first line is the comment this round replaced, so customGlyph now has two. Keep one, for example:

// The Chevron's box. Artwork drawn at `1em` fills it at every text size.
// A larger node is clipped, so the column never widens.

// the chevron's own dimensions, not the indent step, so it does not scale
// with the lever. Published as the private `--_tree-indent` and consumed by
// every row sits flush, like a parent at that level. A leaf that renders its
// own indicator (renderExpandIcon gave it an icon) fills the column itself,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking: "(renderExpandIcon gave it an icon)" is narrower than the code. Any result other than undefined, null included, drops the offset (line 585). For example: "A leaf with a Leaf indicator (any renderExpandIcon result but undefined) fills the column itself, so it takes no offset either."

render(
<TreeList
items={nestedItems}
renderExpandIcon={({hasChildren}) => <Icon icon={GlyphStub} />}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: hasChildren is destructured but never read, which @typescript-eslint/no-unused-vars reports. renderExpandIcon={() => <Icon icon={GlyphStub} />} says the same thing.

@cixzhang
cixzhang marked this pull request as ready for review November 12, 2026 15:03

@kentonquatman kentonquatman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good. Can you also add a block template to show an example of this? We have one for "File Tree With Icons" that serves a very similar use case. I think it will be helpful to show examples of the two types.

@astracat-bot

astracat-bot Bot commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

In reply to @kentonquatman

I'll run a full review to re-check this with your note.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This review finds no blocking defect: renderExpandIcon does what #4131 asks for, the TreeList record change has an engineering owner's approval for this commit, CI passes (including the new browser spec), and trees without the prop render exactly as before.

Approval waits on the two changes-requested reviews that are still open: kentonquatman's asks for a TreeList block template that shows renderExpandIcon beside "File Tree With Icons", and cixzhang's early review on sizing the indicator column and its glyph, which this commit addresses, needs her re-review or dismissal. The earlier inline notes on two comments in TreeListItem.tsx and an unused test parameter, and adding the new browser spec to the record's verified_by list, are optional.

Claims and files checked
  • Changeset, verified: the new tree-level renderExpandIcon prop is called for each row with its expanded, children and disabled state (TreeList.tsx:187, TreeListItem.tsx:557-567).
  • Changeset, verified: parents can show a closed or open folder and leaves a file icon in the same column, and a leaf with an icon lines up with its parent (TreeListItem.tsx:584-585, 698-702).
  • Changeset, verified: the result replaces only the chevron glyph and is not rotated or mirrored (TreeListItem.tsx:643-649); useDirection() is exported from @astryxdesign/core/i18n (i18n/index.ts:41).
  • Changeset, verified: only undefined keeps the default, and any other result fills the box (TreeListItem.tsx:569).
  • Changeset, verified: the result is hidden from assistive technology and never focusable, and the toggle keeps its name, aria-expanded and keys (TreeListItem.tsx:644, 661-670, 699).
  • Changeset, verified: the column is the default chevron's --spacing-4 box (16px by default), 1em artwork fills it and larger content is clipped (TreeListItem.tsx:264-286, the new browser spec in CI).
  • Changeset, verified: trees without the prop render exactly as before (the unchanged-markup test, and identical frames before and after), and TreeListExpandIconState is exported (TreeList/index.ts:35).
  • Description, verified: the prop has the shape the issue proposed, leaves get the call, per-item overrides stay out, and the story is Core/TreeList, Custom Expand Icons.
  • Description, verified: the first round added 24 tests to TreeList.test.tsx (47 → 71).
  • Description, verified: the maintainer rounds keep the contributor's commits unchanged, use the --spacing-4 box (Icon sm and --spacing-4 are both 1rem by default, and Matcha and Y2K set --spacing-4 to 1.5rem), drop sm and 1rem advice from the docs and changeset, and amend the record's ownership, concept table, FR1, FR3, FR8, AR1, anatomy map and verification row.
  • Description, verified: null, false and '' give an empty box; the decorative, right-to-left, clip and unchanged-markup tests exist; the new browser spec measures at 100% and 200% root size and passes in CI on this commit.
  • Description, stale: round 2's count of 32 renderExpandIcon tests is 33 on this commit.
  • Description, not shown: that an unsized Icon pushed the label before this commit; the box already had a fixed width.
  • Not reproduced: the local suite totals, mutation and red-first runs, and the bundle-size figures; CI's unit, lint and type-check jobs pass on this commit.
  • Files: the changeset, the story, TreeList.tsx, TreeList.doc.mjs, TreeListTypes.ts, index.ts and the browser spec are clear; TreeListItem.tsx (two comments), TreeList.test.tsx (an unused parameter) and TreeList.spec.md (verified_by omits the browser spec) have optional notes.

Automated review (maintainer link)

@cixzhang
cixzhang dismissed their stale review November 18, 2026 21:22

(Posted by Cindy's agent.) Dismissed as stale on the owner's decision: this review is on an outdated head. Please re-review the current head if concerns remain.

@cixzhang

Copy link
Copy Markdown
Contributor

Thank you, @AKnassa, for this PR and for the careful write-up in #4131. The folder-and-file tree you described is a good use case, and your notes on rotation and right-to-left helped shape what Astryx now ships.

Since this PR opened, main has gained a theme-level seam for the same need, so we're closing this one in favour of it. Here is how to build the file tree with what ships:

  • Folder open/closed: a theme can replace the branch chevron through the tree-disclosure indicator. The row draws it in place of the chevron, with state expanded or collapsed, and does not rotate or mirror it (component:TreeList FR10).
  • File icons on leaves: each row's start content is yours (startContent on the item, component:TreeList FR3), so a leaf can carry a file icon there.
import {defineTheme, Theme} from '@astryxdesign/core/theme';
import type {IndicatorProps} from '@astryxdesign/core/Indicator';
import {TreeList} from '@astryxdesign/core/TreeList';

function FolderMark({state}: IndicatorProps<'disclosure'>) {
  return state === 'expanded' ? <FolderOpenIcon aria-hidden /> : <FolderIcon aria-hidden />;
}

const fileTree = defineTheme({
  name: 'file-tree',
  indicators: {'tree-disclosure': FolderMark},
});

<Theme theme={fileTree}>
  <TreeList
    aria-label="Files"
    items={[
      {
        id: 'src',
        label: 'src',
        children: [
          {id: 'index', label: 'index.ts', startContent: <DocumentIcon aria-hidden />},
        ],
      },
    ]}
  />
</Theme>

A per-tree renderExpandIcon prop would be a second way to set the same mark, and Astryx keeps one way per concept, so the theme seam is the path. Thanks again for the contribution.

This branch was successfully deployed

1 active deployment
Preview — c74dbf9f Deployed Nov 12, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:run A maintainer lets this outside contributor's pull request run CI (AST-030 FR17) ci:run-a11y Run the accessibility suite on this PR; write access, next push (AST-030 FR12) 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 needs:design-review Affects visuals — Design should review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TreeList: allow customizing the expand/collapse indicator icon (e.g. folder open/closed for file trees)

3 participants