Skip to content

Commit f830f16

Browse files
authored
fix(VirtualList): 解决item-height参数值固定,导致数据量较少时无法滚动的问题 (DevCloudFE#1145)
* fix(VirtualList): 解决item-height参数值固定,导致数据量较少时无法滚动的问题
1 parent b701958 commit f830f16

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

packages/devui-vue/devui/date-picker-pro/__tests__/date-picker-pro.spec.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,11 +424,11 @@ describe('date-picker-pro test', () => {
424424
expect(pickerPanel).toBeTruthy();
425425

426426
const yearListItems = pickerPanel?.querySelectorAll(yearListItemClass);
427-
expect(yearListItems?.length).toBe(13);
427+
expect(yearListItems?.length).toBe(11);
428428
const weekHeader = pickerPanel?.querySelector(weekHeaderClass);
429429
expect(weekHeader?.getElementsByTagName('td').length).toBe(7);
430430
const tableMonthItems = pickerPanel?.querySelectorAll(tableMonthClass);
431-
expect(tableMonthItems?.length).toBe(12);
431+
expect(tableMonthItems?.length).toBe(4);
432432

433433
const date = new Date();
434434
const todayIndex = 7 - ((date.getDate() - date.getDay()) % 7) + date.getDate();

packages/devui-vue/devui/date-picker-pro/__tests__/range-date-picker-pro.spec.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,11 +391,11 @@ describe('range-date-picker-pro test', () => {
391391
expect(pickerPanel).toBeTruthy();
392392

393393
const yearListItems = pickerPanel?.querySelectorAll(yearListItemClass);
394-
expect(yearListItems?.length).toBe(13);
394+
expect(yearListItems?.length).toBe(11);
395395
const weekHeader = pickerPanel?.querySelector(weekHeaderClass);
396396
expect(weekHeader?.getElementsByTagName('td').length).toBe(7);
397397
const tableMonthItems = pickerPanel?.querySelectorAll(tableMonthClass);
398-
expect(tableMonthItems?.length).toBe(12);
398+
expect(tableMonthItems?.length).toBe(4);
399399

400400
const date = new Date();
401401
const todayIndex = 7 - ((date.getDate() - date.getDay()) % 7) + date.getDate();
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { ComputedRef } from 'vue';
2-
import { computed } from 'vue';
2+
import { computed, toRefs } from 'vue';
33
import { VirtualListProps } from '../virtual-list-types';
44

55
interface IUseVirtual {
@@ -8,13 +8,12 @@ interface IUseVirtual {
88
}
99

1010
export default function useVirtual(props: VirtualListProps): IUseVirtual {
11+
const { height, data, itemHeight, virtual } = toRefs(props);
1112
const isVirtual = computed(() => {
12-
const { height, virtual } = props;
13-
return !!(virtual !== false && height);
13+
return Boolean(virtual.value !== false && height.value);
1414
});
1515
const inVirtual = computed(() => {
16-
const { height, data } = props;
17-
return isVirtual.value && data && 20 * data.length > height;
16+
return Boolean(isVirtual.value && data.value.length && itemHeight.value * data.value.length > height.value);
1817
});
1918
return { isVirtual, inVirtual };
2019
}

0 commit comments

Comments
 (0)