perf: optimize select animate
parent
8ba8983353
commit
7125d84fa2
|
@ -1 +1 @@
|
||||||
Subproject commit bef135d01e96fadf80f7a09c7cd26b18aa6d71d8
|
Subproject commit 7f7141a1dd62488287157dee6a1af52716924c62
|
|
@ -135,32 +135,23 @@ const OptionList = defineComponent<OptionListProps, { state?: any }>({
|
||||||
);
|
);
|
||||||
// Auto scroll to item position in single mode
|
// Auto scroll to item position in single mode
|
||||||
|
|
||||||
let timeoutId: number;
|
|
||||||
watch(
|
watch(
|
||||||
computed(() => props.open),
|
computed(() => props.open),
|
||||||
() => {
|
() => {
|
||||||
/**
|
if (!props.multiple && props.open && props.values.size === 1) {
|
||||||
* React will skip `onChange` when component update.
|
const value = Array.from(props.values)[0];
|
||||||
* `setActive` function will call root accessibility state update which makes re-render.
|
const index = props.flattenOptions.findIndex(({ data }) => data.value === value);
|
||||||
* So we need to delay to let Input component trigger onChange first.
|
// setActive(index);
|
||||||
*/
|
scrollIntoView(index);
|
||||||
clearTimeout(timeoutId);
|
}
|
||||||
timeoutId = setTimeout(() => {
|
|
||||||
if (!props.multiple && props.open && props.values.size === 1) {
|
|
||||||
const value = Array.from(props.values)[0];
|
|
||||||
const index = props.flattenOptions.findIndex(({ data }) => data.value === value);
|
|
||||||
setActive(index);
|
|
||||||
scrollIntoView(index);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
// Force trigger scrollbar visible when open
|
// Force trigger scrollbar visible when open
|
||||||
if (props.open) {
|
if (props.open) {
|
||||||
nextTick(()=>{
|
nextTick(() => {
|
||||||
listRef.current?.scrollTo(undefined);
|
listRef.current?.scrollTo(undefined);
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ immediate: true },
|
{ immediate: true, flush: 'post' },
|
||||||
);
|
);
|
||||||
|
|
||||||
// ========================== Values ==========================
|
// ========================== Values ==========================
|
||||||
|
|
Loading…
Reference in New Issue