Explorar o código

fix: 针对空数据又存在横向滚动条的高度计算优化

lanjianrong %!s(int64=4) %!d(string=hai) anos
pai
achega
66be870f07
Modificáronse 1 ficheiros con 7 adicións e 1 borrados
  1. 7 1
      src/components/Table/src/hooks/useTableScroll.ts

+ 7 - 1
src/components/Table/src/hooks/useTableScroll.ts

@@ -69,6 +69,7 @@ export function useTableScroll(
     // )
 
     setTableHeight(dataSource?.length ? height : null)
+
     if (!dataSource?.length) {
       // TODO:针对无数据的情况下,特别设置tboody
       const tbodyEl: HTMLElement = tableElRef.current
@@ -78,7 +79,12 @@ export function useTableScroll(
       let hasScrollBar = el?.style.width !== '100%'
 
       if (el?.style.width !== '100%') {
-        hasScrollBar = el?.clientWidth > el?.style.width
+        const contentWidth =
+          tableElRef.current
+            ?.querySelector('.ant-table-container')
+            ?.querySelector('div.ant-table-content')?.clientWidth || 0
+
+        hasScrollBar = el?.clientWidth > contentWidth
       }
 
       const notDataHeight = `${height - (hasScrollBar ? 8 : 0)}px`