diff --git a/packages/components/src/virtual-list/VirtualList.tsx b/packages/components/src/virtual-list/VirtualList.tsx index 69772a6a..847f64d8 100644 --- a/packages/components/src/virtual-list/VirtualList.tsx +++ b/packages/components/src/virtual-list/VirtualList.tsx @@ -67,6 +67,10 @@ export const VirtualList: React.FC = React.forwardRef< }); }, [childList, offsets]); + useEffect(() => { + autoFillLayoutRef.current = true; + }, [childList.length]); + useEffect(() => { if (!autoFillLayoutRef.current) return; const [start, end] = offsets; diff --git a/packages/components/src/virtual-list/demo/dynamic-size.tsx b/packages/components/src/virtual-list/demo/dynamic-size.tsx index cb45042b..9349e4fe 100644 --- a/packages/components/src/virtual-list/demo/dynamic-size.tsx +++ b/packages/components/src/virtual-list/demo/dynamic-size.tsx @@ -2,15 +2,32 @@ * title: 动态尺寸 */ -import { VirtualList, Alert } from '@tool-pack/react-ui'; -import React from 'react'; - -const length = 100; +import { VirtualList, Select, Alert } from '@tool-pack/react-ui'; +import React, { useState } from 'react'; +const options = [ + { label: 100, value: 100 }, + { label: 500, value: 500 }, + { label: 1000, value: 1000 }, + { label: 5000, value: 5000 }, + { label: 10000, value: 10000 }, +]; const App: React.FC = () => { + const [num, setNum] = useState(100); return ( <> -

列表内含 {length} 个不定高度 Alert 组件

+ item 数量: +