diff --git a/components/_util/getScrollBarSize.ts b/components/_util/getScrollBarSize.ts index 12a142f3f..ab077216a 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 d68688787..f7ced9a13 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), }; }