From 441678cd365819e4523238ebca361d1cd22a874e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E6=9C=BA=E5=99=A8=E4=BA=BA?= Date: Thu, 17 Aug 2023 18:02:09 +0800 Subject: [PATCH] chore: fixed pos --- assets/virtual.less | 13 ++++++++++--- src/Cell/index.tsx | 2 ++ src/StaticTable/BodyLine.tsx | 2 +- src/Table.tsx | 7 +++---- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/assets/virtual.less b/assets/virtual.less index 418cc3a23..d353b9833 100644 --- a/assets/virtual.less +++ b/assets/virtual.less @@ -5,19 +5,26 @@ box-sizing: border-box; } + @border: 1px solid @border-color; + .@{tablePrefixCls}-row { display: flex; width: 100%; - border-bottom: 1px solid @border-color; - border-left: 1px solid @border-color; + border-bottom: @border; + border-left: @border; } .@{tablePrefixCls}-cell { flex: 1 0 auto; + width: var(--virtual-width); padding: 8px 16px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; - border-right: 1px solid @border-color; + border-right: @border; + + &-fix-left { + left: calc(var(--sticky-left) + 1px) !important; + } } } diff --git a/src/Cell/index.tsx b/src/Cell/index.tsx index fad3ed55f..0e31f0eb7 100644 --- a/src/Cell/index.tsx +++ b/src/Cell/index.tsx @@ -140,11 +140,13 @@ function Cell(props: CellProps) { if (isFixLeft) { fixedStyle.position = 'sticky'; fixedStyle.left = fixLeft as number; + fixedStyle['--sticky-left'] = `${fixLeft}px`; } if (isFixRight) { fixedStyle.position = 'sticky'; fixedStyle.right = fixRight as number; + fixedStyle['--sticky-right'] = `${fixRight}px`; } // ================ RowSpan & ColSpan ================= diff --git a/src/StaticTable/BodyLine.tsx b/src/StaticTable/BodyLine.tsx index abd24d30d..0724de7fd 100644 --- a/src/StaticTable/BodyLine.tsx +++ b/src/StaticTable/BodyLine.tsx @@ -49,7 +49,7 @@ const BodyLine = React.forwardRef((props, ref) => const { style: cellStyle, colSpan, rowSpan } = additionalCellProps; const mergedStyle = { ...cellStyle, - width: colWidth, + '--virtual-width': `${colWidth}px`, }; // When `colSpan` or `rowSpan` is `0`, should skip render. diff --git a/src/Table.tsx b/src/Table.tsx index f2ba4bd35..b7adffa12 100644 --- a/src/Table.tsx +++ b/src/Table.tsx @@ -391,16 +391,15 @@ function Table(tableProps: TableProps', mergedScrollLeft, scrollLeft); - forceScroll(mergedScrollLeft, scrollHeaderRef.current); forceScroll(mergedScrollLeft, scrollBodyRef.current); forceScroll(mergedScrollLeft, scrollSummaryRef.current); forceScroll(mergedScrollLeft, stickyRef.current?.setScrollLeft); } - if (currentTarget) { - const { scrollWidth, clientWidth } = currentTarget; + const measureTarget = currentTarget || scrollHeaderRef.current; + if (measureTarget) { + const { scrollWidth, clientWidth } = measureTarget; // There is no space to scroll if (scrollWidth === clientWidth) { setPingedLeft(false);