-
Notifications
You must be signed in to change notification settings - Fork 349
fix(Tree): enhance disabled state logic #2285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
ddb2548 to
0e09d06
Compare
caff224 to
a32c8bb
Compare
4e0f771 to
4f19623
Compare
4f19623 to
2fbc1cd
Compare
3d02c71 to
de15c02
Compare
de15c02 to
1cf5ff9
Compare
07ba2b8 to
9133257
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR enhances the disabled state logic for Tree components by synchronizing disabled state management between the Vue and React versions. The changes ensure that the TreeNodeModel's disabled property correctly reflects the actual UI state.
- Refactors disabled state logic with proper priority handling (Tree config > checkStrictly > manual > node data > disableCheck)
- Adds a new
disableManuallyproperty to track manual disabled state changes - Updates the
TreeNodeModelto expose thedisabledproperty for better state synchronization
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| js/tree/tree-node.ts | Refactored disabled state logic with new priority system and manual state tracking |
| js/tree-v1/types.ts | Added disableCheck option to TreeStoreOptions interface |
| js/tree-v1/tree-node.ts | Applied same disabled state enhancements as the main tree implementation |
| js/tree-v1/tree-node-model.ts | Added disabled property to exposed TreeNodeModel properties |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| tree: TreeStore, | ||
| data?: TypeTreeNodeData, | ||
| parent?: TreeNode, | ||
| parent?: TreeNode |
Copilot
AI
Sep 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The trailing comma was removed from the parameter list. For consistency with the codebase and modern TypeScript practices, consider keeping the trailing comma.
| parent?: TreeNode | |
| parent?: TreeNode, |
Copilot uses AI. Check for mistakes.
|
|
||
| if (!checkStrictly && parent?.isDisabled()) return true; | ||
|
|
||
| if (typeof this.disableManually === 'boolean') return this.disableManually; |
Copilot
AI
Sep 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The condition should check for strict boolean types to ensure type safety. Consider using this.disableManually !== null instead to be more explicit about the intention.
Copilot uses AI. Check for mistakes.
|
|
||
| if (!checkStrictly && parent?.isDisabled()) return true; | ||
|
|
||
| if (typeof this.disableManually === 'boolean') return this.disableManually; |
Copilot
AI
Sep 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The condition should check for strict boolean types to ensure type safety. Consider using this.disableManually !== null instead to be more explicit about the intention.
Copilot uses AI. Check for mistakes.
| public setDisabled(disabled: null | boolean) { | ||
| if (!this.tree.config.checkStrictly && this.parent?.isDisabled()) return; | ||
| // 当 disabled 为 null 时,恢复为默认的禁用逻辑,而非通过设置强制指定 | ||
| this.disableManually = disabled; | ||
| this.update(); | ||
| this.updateChildren(); |
Copilot
AI
Sep 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method silently returns when the parent is disabled and checkStrictly is false. This could be confusing for API consumers. Consider throwing an error or returning a boolean to indicate success/failure.
| public setDisabled(disabled: null | boolean) { | |
| if (!this.tree.config.checkStrictly && this.parent?.isDisabled()) return; | |
| // 当 disabled 为 null 时,恢复为默认的禁用逻辑,而非通过设置强制指定 | |
| this.disableManually = disabled; | |
| this.update(); | |
| this.updateChildren(); | |
| public setDisabled(disabled: null | boolean): boolean { | |
| if (!this.tree.config.checkStrictly && this.parent?.isDisabled()) return false; | |
| // 当 disabled 为 null 时,恢复为默认的禁用逻辑,而非通过设置强制指定 | |
| this.disableManually = disabled; | |
| this.update(); | |
| this.updateChildren(); | |
| return true; |
Copilot uses AI. Check for mistakes.
🤔 这个 PR 的性质是?
🔗 相关 Issue
Tencent/tdesign-react#3828
💡 需求背景和解决方案
disabled对应真实的 UI 状态📝 更新日志
fix(Tree): 修复
TreeNodeModel中的disabled与 UI 状态不同步的问题本条 PR 不需要纳入 Changelog
☑️ 请求合并前的自查清单