feat(tree): 新增 keepParentOnUncheck 属性,取消勾选子节点时保持父节点选中 (#8281)

权限树等父子节点均为独立授权项的场景中,checkStrictly 与 autoCheckParent 组合下取消勾选子节点会级联清空父节点,用户显式勾选的父级授权被误清空。

- types.ts:TreeProps 新增 keepParentOnUncheck 可选属性,默认 false(与现有级联取消行为一致)

- tree.vue:onSelect 取消勾选分支的级联条件追加该属性取反判定,勾选方向的级联不受影响
This commit is contained in:
徐蒙恩
2026-08-24 21:19:59 +08:00
committed by GitHub
parent c5c8eb2515
commit dbac4e4c30
2 changed files with 4 additions and 0 deletions
@@ -249,6 +249,7 @@ function onSelect(item: FlattenedItem<Recordable<any>>, isSelected: boolean) {
props.checkStrictly &&
props.multiple &&
props.autoCheckParent &&
!props.keepParentOnUncheck &&
!isSelected
) {
flattenData.value
@@ -27,6 +27,8 @@ export interface TreeProps {
/** 自定义节点类名 */
getNodeClass?: (item: FlattenedItem<Recordable<any>>) => string;
iconField?: string;
/** 取消勾选子节点时保持父节点的选中状态,不级联取消父节点(默认 false:级联取消) */
keepParentOnUncheck?: boolean;
/** label字段 */
labelField?: string;
/** 是否多选 */
@@ -58,6 +60,7 @@ export function treePropsDefaults() {
multiple: false,
showIcon: true,
transition: true,
keepParentOnUncheck: false,
valueField: 'value',
childrenField: 'children',
};