Add disableSelect prop (rebased from #169)#331
Merged
TrevorBurnham merged 11 commits intomainfrom May 4, 2026
Merged
Conversation
Match repo formatting in filterSelectableNodes and selectContiguous; replace `as NodeApi<T>[]` cast with a type-guarded filter predicate. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Adds a disableSelect prop to Tree (matching the existing disableEdit / disableDrag patterns) to prevent certain nodes from being selectable while still allowing focus/navigation through them.
Changes:
- Introduces
disableSelect?: string | boolean | BoolFunc<T>toTreePropsand documents it in the README. - Gates selection entry points (
select,selectMulti,selectContiguous,selectAll) based on a newnode.isSelectablegetter. - Updates the Gmail showcase + Cypress e2e coverage to demonstrate and validate unselectable nodes.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| modules/showcase/pages/gmail.tsx | Demonstrates disableSelect by preventing selection of “Categories” and “Spam”. |
| modules/react-arborist/src/types/tree-props.ts | Adds disableSelect to the public TreeProps type. |
| modules/react-arborist/src/interfaces/tree-api.ts | Implements select-gating and introduces isSelectable() / filterSelectableNodes(). |
| modules/react-arborist/src/interfaces/node-api.ts | Adds node.isSelectable getter. |
| modules/e2e/cypress/e2e/gmail-spec.cy.js | Adds e2e tests for click selection + select-all behavior with unselectable nodes. |
| README.md | Documents the new disableSelect prop in the TreeProps interface section. |
| CONTRIBUTING.md | Tweaks local testing instructions formatting. |
Comments suppressed due to low confidence (1)
modules/react-arborist/src/interfaces/tree-api.ts:342
select()now callssetSelection()(which already invokesprops.onSelect) and then invokesprops.onSelectagain at the end ofselect(). This results in duplicateonSelectcallbacks for a single selection change, which can cause double side-effects for consumers. Consider either removing theonSelectcall insidesetSelection, or makingselect()use dispatches directly / return early soonSelectis only fired once per action.
if (this.get(id)?.isSelectable) {
this.setSelection({
ids: [id],
anchor: id,
mostRecent: id,
});
}
this.scrollTo(id, opts.align);
if (this.focusedNode && changeFocus) {
safeRun(this.props.onFocus, this.focusedNode);
}
safeRun(this.props.onSelect, this.selectedNodes);
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- select(): drop redundant onSelect call (setSelection already fires it, so previously every selection produced two callbacks) - selectAll(): derive anchor/mostRecent from the selectable subset so shift-click ranges don't start from a non-selected node - e2e: assert existing Inbox selection survives a click on Categories - CONTRIBUTING.md: give the localhost autolink an http:// scheme so it renders as a link Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Collaborator
Author
|
Pushed fd9ab93 addressing Copilot's review:
Not addressed (left as a follow-up to keep this PR scoped):
|
Collaborator
Author
|
Follow-up cleanup tracked in #332. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resurrects @boriskor's #169, rebased onto current main with style cleanup. Closes #56.
Summary
Adds a
disableSelectTree prop in the spirit ofdisableEditanddisableDrag— acceptsstring | boolean | BoolFunc<T>. When the predicate returns true for a node, that node can't be selected via click, keyboard,selectionFollowsFocus,selectAll, or any of the imperative select methods. Focus still moves through the disabled node (so keyboard navigation isn't blocked); only selection is gated.Closes #56, which @jameskerr opened in 2022 asking for exactly this API.
What changed vs #169
selectMulti(opts)and theisActionPossiblerefactor).filterSelectableNodes/selectContiguous, replaced anas NodeApi<T>[]cast with a type-guarded filter predicate.Coverage
select,selectMulti,selectContiguous,selectAll.selectionFollowsFocusflows throughselectso it's gated too.setSelection(imperative escape hatch) is intentionally not gated.node.isSelectablegetter onNodeApi.Test plan
selectionFollowsFocusis on, but the node doesn't get selected🤖 Generated with Claude Code