Skip to content

Commit d58a5d8

Browse files
committed
fix: select not update
1 parent 2e06d38 commit d58a5d8

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

components/_util/hooks/useMemo.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@ import { Ref, ref, watch } from 'vue';
33
export default function useMemo<T>(
44
getValue: () => T,
55
condition: any[],
6-
shouldUpdate: (prev: any[], next: any[]) => boolean,
6+
shouldUpdate?: (prev: any[], next: any[]) => boolean,
77
) {
88
const cacheRef: Ref<T> = ref(getValue() as any);
9-
watch(condition, (pre, next) => {
10-
if (shouldUpdate(pre, next)) {
9+
watch(condition, (next, pre) => {
10+
if (shouldUpdate) {
11+
if (shouldUpdate(next, pre)) {
12+
cacheRef.value = getValue();
13+
}
14+
} else {
1115
cacheRef.value = getValue();
1216
}
1317
});

components/auto-complete/__tests__/index.test.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ describe('AutoComplete with Custom Input Element Render', () => {
1313
{
1414
render() {
1515
return (
16-
<AutoComplete ref="component" dataSource={['12345', '23456', '34567']}>
16+
<AutoComplete
17+
ref="component"
18+
options={[{ value: '12345' }, { value: '23456' }, { value: '34567' }]}
19+
>
1720
<input />
1821
</AutoComplete>
1922
);

components/vc-select/OptionList.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ const OptionList = defineComponent<OptionListProps, { state?: any }>({
8282
const memoFlattenOptions = useMemo(
8383
() => props.flattenOptions,
8484
[() => props.open, () => props.flattenOptions],
85-
(prev, next) => next[0] && prev[1] !== next[1],
85+
next => next[0],
8686
);
8787

8888
// =========================== List ===========================

0 commit comments

Comments
 (0)