Skip to content

Commit

Permalink
fix(module:tree): nzCheckBoxChange never emitting (#8038)
Browse files Browse the repository at this point in the history
  • Loading branch information
CondensedMilk7 authored Nov 17, 2023
1 parent 1e1c753 commit a9dc205
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
20 changes: 20 additions & 0 deletions components/core/tree/nz-tree-base.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,26 @@ export class NzTreeBaseService {
return this.conductNodeState('select');
}

/**
* get checked node keys
*/
getCheckedNodeKeys(): NzTreeNodeKey[] {
const keys: NzTreeNodeKey[] = [];
const checkedNodes = this.getCheckedNodeList();

const calc = (nodes: NzTreeNode[]): void => {
nodes.forEach(node => {
keys.push(node.key);
if (node.children.length < 1) return;
calc(node.children);
});
};

calc(checkedNodes);

return keys;
}

/**
* return checked nodes
*/
Expand Down
4 changes: 3 additions & 1 deletion components/tree/tree.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ export class NzTreeComponent

@Output() readonly nzExpandedKeysChange: EventEmitter<string[]> = new EventEmitter<string[]>();
@Output() readonly nzSelectedKeysChange: EventEmitter<string[]> = new EventEmitter<string[]>();
@Output() readonly nzCheckedKeysChange: EventEmitter<string[]> = new EventEmitter<string[]>();
@Output() readonly nzCheckedKeysChange: EventEmitter<NzTreeNodeKey[]> = new EventEmitter<NzTreeNodeKey[]>();
@Output() readonly nzSearchValueChange = new EventEmitter<NzFormatEmitEvent>();
@Output() readonly nzClick = new EventEmitter<NzFormatEmitEvent>();
@Output() readonly nzDblClick = new EventEmitter<NzFormatEmitEvent>();
Expand Down Expand Up @@ -426,6 +426,8 @@ export class NzTreeComponent
// Cause check method will rerender list, so we need recover it and next the new event to user
const eventNext = this.nzTreeService.formatEvent('check', node, event.event!);
this.nzCheckBoxChange.emit(eventNext);
const checkedKeys = this.nzTreeService.getCheckedNodeKeys();
this.nzCheckedKeysChange.emit(checkedKeys);
break;
case 'dragstart':
// if node is expanded
Expand Down

0 comments on commit a9dc205

Please sign in to comment.