Skip to content

Commit 7125d84

Browse files
committed
perf: optimize select animate
1 parent 8ba8983 commit 7125d84

File tree

2 files changed

+10
-19
lines changed

2 files changed

+10
-19
lines changed

antdv-demo

components/vc-select/OptionList.tsx

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -135,32 +135,23 @@ const OptionList = defineComponent<OptionListProps, { state?: any }>({
135135
);
136136
// Auto scroll to item position in single mode
137137

138-
let timeoutId: number;
139138
watch(
140139
computed(() => props.open),
141140
() => {
142-
/**
143-
* React will skip `onChange` when component update.
144-
* `setActive` function will call root accessibility state update which makes re-render.
145-
* So we need to delay to let Input component trigger onChange first.
146-
*/
147-
clearTimeout(timeoutId);
148-
timeoutId = setTimeout(() => {
149-
if (!props.multiple && props.open && props.values.size === 1) {
150-
const value = Array.from(props.values)[0];
151-
const index = props.flattenOptions.findIndex(({ data }) => data.value === value);
152-
setActive(index);
153-
scrollIntoView(index);
154-
}
155-
});
141+
if (!props.multiple && props.open && props.values.size === 1) {
142+
const value = Array.from(props.values)[0];
143+
const index = props.flattenOptions.findIndex(({ data }) => data.value === value);
144+
// setActive(index);
145+
scrollIntoView(index);
146+
}
156147
// Force trigger scrollbar visible when open
157148
if (props.open) {
158-
nextTick(()=>{
149+
nextTick(() => {
159150
listRef.current?.scrollTo(undefined);
160-
})
151+
});
161152
}
162153
},
163-
{ immediate: true },
154+
{ immediate: true, flush: 'post' },
164155
);
165156

166157
// ========================== Values ==========================

0 commit comments

Comments
 (0)