Skip to content

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

Closed

Description

@cixzhang

Summary

Allow customizing the expand/collapse indicator icon on TreeList rows. Today the indicator is hardcoded to a rotating chevronRight, so patterns like a file/folder tree — where an expandable node should show a closed-folder icon when collapsed and an open-folder icon when expanded — aren't expressible.

Motivation

  • A folder tree is one of the most common TreeList use cases, and the folder-open / folder-closed icon swap is the expected visual language for it.
  • More generally, teams want the expand affordance to match their domain (folders, categories, org nodes) rather than a generic chevron.
  • startContent already lets you put an icon before the label, but it doesn't control the expand/collapse indicator itself, which is a separate, hardcoded element.

Current behavior

In TreeListItem.tsx the indicator is fixed:

const chevronIcon = (
  <span {...stylex.props(styles.chevronSvg, isExpanded ? styles.chevronExpanded : styles.chevronCollapsed)}>
    {getIcon('chevronRight')}
  </span>
);

There is no prop to override it, and the collapsed/expanded states are expressed only by rotating the same chevron.

Proposed API

Add a way to supply a custom indicator, ideally state-aware so collapsed vs. expanded can be distinct icons (not just a rotation). A render-prop keeps it flexible and avoids a rotation assumption:

<TreeList
  renderExpandIcon={({ isExpanded, hasChildren, isDisabled }) =>
    hasChildren
      ? (isExpanded ? <Icon icon="folderOpen" /> : <Icon icon="folder" />)
      : <Icon icon="file" />
  }
/>

Open to a simpler shape if preferred (e.g. expandIcon / collapseIcon props). Key requirements:

  • Distinguish collapsed vs expanded icons (folder-closed / folder-open), not just a rotated single icon.
  • Optionally distinguish leaf nodes (no children) so a folder tree can render a file/leaf icon in the indicator slot.
  • Default stays the current chevron — this is opt-in.
  • Preserve the existing a11y wiring: the toggle button keeps aria-expanded, aria-label, roving-tabindex behavior, and data-tree-toggle regardless of the icon rendered inside it.

Notes

  • Should the rotation animation be suppressed automatically when a custom state-aware icon is provided (so an open-folder icon isn't also rotated)? Probably yes.
  • Per-item override vs. tree-level render prop — a tree-level renderExpandIcon covers the folder case cleanly; per-item could come later if needed.

Environment

  • Component: TreeList (@astryxdesign/core), packages/core/src/TreeList/TreeListItem.tsx

Activity

  1. added
    enhancement
    component
    on Jul 21, 2026
  2. cixzhang commented on Nov 20, 2026

    @cixzhang
    ContributorAuthor

    Covered on main: a theme's tree-disclosure indicator replaces the branch chevron with an open/closed mark (component:TreeList FR10), and leaf icons go in each row's startContent (FR3). #4228 has a short example. Thanks to @AKnassa for the request and the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    componentenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions