Skip to content

Commit

Permalink
fix(tree-select): filterByText keep pace with innerInputValue (#3862)
Browse files Browse the repository at this point in the history
filterByText keep pace with innerInputValue

closed #3833, #3852
  • Loading branch information
PeterJayawesome authored Jan 21, 2024
1 parent f1eeaed commit 1350ecf
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions src/tree-select/tree-select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export default defineComponent({
const treeRef = ref(null);

// data
const filterByText = ref(null);
const actived = ref([]);
const expanded = ref([]);
const nodeInfo = ref(null);
Expand Down Expand Up @@ -77,6 +76,22 @@ export default defineComponent({
);

// computed
/** filterByText keep pace with innerInputValue */
const filterByText = computed(() => {
const value = innerInputValue.value || '';
if (value === '') {
return null;
}
return (node: TreeNodeModel<TreeOptionData>) => {
if (isFunction(props.filter)) {
const filter: boolean | Promise<boolean> = props.filter(String(value), node);
if (isBoolean(filter)) {
return filter;
}
}
return node.data[realLabel.value].indexOf(value) >= 0;
};
});
const tDisabled = computed(() => {
return formDisabled.value || props.disabled;
});
Expand Down Expand Up @@ -230,19 +245,6 @@ export default defineComponent({
return;
}
setInnerInputValue(value);
if (!value) {
filterByText.value = null;
return null;
}
filterByText.value = (node: TreeNodeModel<TreeOptionData>) => {
if (isFunction(props.filter)) {
const filter: boolean | Promise<boolean> = props.filter(String(value), node);
if (isBoolean(filter)) {
return filter;
}
}
return node.data[realLabel.value].indexOf(value) >= 0;
};
props.onSearch?.(String(value));
};

Expand Down

0 comments on commit 1350ecf

Please sign in to comment.