Skip to content

Commit

Permalink
chore: support set indeterminate
Browse files Browse the repository at this point in the history
  • Loading branch information
uyarn committed Dec 4, 2024
1 parent 12a6bb2 commit 0777282
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
14 changes: 3 additions & 11 deletions src/tree/Tree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -273,24 +273,16 @@ const Tree = forwardRef<TreeInstanceFunctions<TreeOptionData>, TreeProps>((origi
delete spec.checked;
}
if ('indeterminate' in options) {
setTreeIndeterminate([...indeterminate, value]);
// @ts-ignore
setTreeIndeterminate((prevIndeterminate: TreeNodeValue[]) => [...prevIndeterminate, value]);
setIndeterminate(node, spec.indeterminate, { trigger: 'setItem' });
delete spec.indeterminate;
}
node.set(spec);
}
},
}),
[
store,
setExpanded,
setActived,
setTreeIndeterminate,
indeterminate,
setChecked,
setIndeterminate,
handleScrollToElement,
],
[store, setExpanded, setActived, setTreeIndeterminate, setChecked, setIndeterminate, handleScrollToElement],
);

/* ======== render ======= */
Expand Down
2 changes: 1 addition & 1 deletion src/tree/hooks/useStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ export function useStore(
useUpdateLayoutEffect(() => {
if (Array.isArray(value)) {
store.replaceChecked(value);
const checkedValue = store.getCheckedNodes().map((v: TreeNode) => v.data.value);
const checkedValue = store.getCheckedNodes().map((v: TreeNode) => v.data[keys.value || 'value']);
const indeterminateConflict = checkedValue.filter((v) => indeterminate.includes(v));
if (indeterminateConflict.length) {
setTreeIndeterminate(indeterminate.filter((v: TreeNodeValue) => !indeterminateConflict.includes(v)));
Expand Down

0 comments on commit 0777282

Please sign in to comment.