Skip to content

feat: add expandAll() and collapseAll() methods to TreeView#504

Merged
willeastcott merged 2 commits into
mainfrom
feat/treeview-expand-collapse-all
Feb 26, 2026
Merged

feat: add expandAll() and collapseAll() methods to TreeView#504
willeastcott merged 2 commits into
mainfrom
feat/treeview-expand-collapse-all

Conversation

@willeastcott

@willeastcott willeastcott commented Feb 26, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds expandAll() and collapseAll() public methods to TreeView, enabling consumers to expand or collapse the entire tree hierarchy in a single call.
  • Adds unit tests for both new methods.
  • Updates the TreeView HTML example with Expand All / Collapse All buttons to demonstrate the new API.

Motivation

The PlayCanvas Editor currently works around the lack of these methods by directly accessing protected internals (_treeItemIndex, _rootItem) to implement expand/collapse all functionality. This PR provides a proper public API.

Test plan

  • Unit tests added and passing (
    pm test)
  • Verify the TreeView example renders the buttons and they expand/collapse the tree correctly

@willeastcott willeastcott force-pushed the feat/treeview-expand-collapse-all branch from 499e7c7 to adc2cb8 Compare February 26, 2026 13:51

Copilot AI 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.

Pull request overview

Adds a small public API to TreeView for bulk expanding/collapsing items, primarily to avoid consumers (e.g. PlayCanvas Editor) reaching into protected internals for this common behavior.

Changes:

  • Add TreeView.expandAll() and TreeView.collapseAll() methods implemented via existing depth-first traversal.
  • Add unit tests covering the new methods.
  • Update the TreeView HTML example to include “Expand All” / “Collapse All” buttons demonstrating the API.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/components/TreeView/index.ts Introduces the new public methods using the existing _traverseDepthFirst helper.
test/components/treeview.mjs Adds unit tests validating expand/collapse behavior across a small hierarchy.
examples/elements/treeview.html Updates the example UI to provide buttons that call the new API.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@willeastcott willeastcott merged commit 1de4f4e into main Feb 26, 2026
5 checks passed
@willeastcott willeastcott deleted the feat/treeview-expand-collapse-all branch February 26, 2026 13:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants