From a19a74caea9f0208347137a7e90d0bcffb3b3739 Mon Sep 17 00:00:00 2001 From: IceMooncake <147961575+IceMooncake@users.noreply.github.com> Date: Thu, 18 Dec 2025 11:32:50 +0800 Subject: [PATCH] fix(table): return 0 when scrollbar does not exist and avoid forced y scroll (#8443) --- components/_util/getScrollBarSize.ts | 7 +++++-- components/vc-table/Table.tsx | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/components/_util/getScrollBarSize.ts b/components/_util/getScrollBarSize.ts index 12a142f3fc..ab077216a0 100644 --- a/components/_util/getScrollBarSize.ts +++ b/components/_util/getScrollBarSize.ts @@ -54,9 +54,12 @@ export function getTargetScrollBarSize(target: HTMLElement) { return { width: 0, height: 0 }; } + const hasVertical = target.scrollHeight > target.clientHeight; + const hasHorizontal = target.scrollWidth > target.clientWidth; + const { width, height } = getComputedStyle(target, '::-webkit-scrollbar'); return { - width: ensureSize(width), - height: ensureSize(height), + width: hasVertical ? ensureSize(width) : 0, + height: hasHorizontal ? ensureSize(height) : 0, }; } diff --git a/components/vc-table/Table.tsx b/components/vc-table/Table.tsx index d68688787f..f7ced9a131 100644 --- a/components/vc-table/Table.tsx +++ b/components/vc-table/Table.tsx @@ -379,7 +379,7 @@ export default defineComponent({ watchEffect(() => { if (fixHeader.value) { scrollYStyle.value = { - overflowY: 'scroll', + overflowY: 'auto', maxHeight: toPx(props.scroll.y), }; }