Skip to content

Commit

Permalink
Merge pull request XiaoMi#2847 from aqiusen/hotfix/table/2864
Browse files Browse the repository at this point in the history
fix(table): 修复虚拟列表maxHeight无法支持字符串问题(XiaoMi#2846)
  • Loading branch information
solarjoker authored Jun 12, 2024
2 parents 4f135ae + 57e5b5e commit 9416cd0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/khaki-panthers-clean.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hi-ui/hiui": patch
---

fix(table): 修复虚拟列表 maxHeight 无法支持字符串问题
5 changes: 5 additions & 0 deletions .changeset/rude-baboons-explode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hi-ui/table": patch
---

fix(table): 修复虚拟列表 maxHeight 无法支持字符串问题
17 changes: 8 additions & 9 deletions packages/ui/table/src/TableBody.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { forwardRef, useCallback, useEffect, useMemo, useState } from 'react'
import React, { forwardRef, useMemo, useRef } from 'react'
import VirtualList from 'rc-virtual-list'
import { cx, getPrefixCls } from '@hi-ui/classname'
import { __DEV__ } from '@hi-ui/env'
Expand All @@ -15,7 +15,7 @@ const _role = 'table'
const _prefix = getPrefixCls(_role)

export const TableBody = forwardRef<HTMLDivElement | null, TableBodyProps>(
({ prefixCls = _prefix, emptyContent }, ref) => {
({ prefixCls = _prefix, emptyContent }) => {
const {
columns,
isExpandTreeRows,
Expand All @@ -33,7 +33,7 @@ export const TableBody = forwardRef<HTMLDivElement | null, TableBodyProps>(
scrollbar,
scrollLeft,
} = useTableContext()

const virtualListRef = useRef(null)
const cls = cx(`${prefixCls}-body`)

const getRequiredProps = useLatestCallback(
Expand All @@ -58,14 +58,13 @@ export const TableBody = forwardRef<HTMLDivElement | null, TableBodyProps>(

if (virtual) {
// TODO: avg和summay row的逻辑

const realHeight = scrollBodyElementRef.current?.getBoundingClientRect().height
const realHeight = (virtualListRef.current as (HTMLTableElement | null))?.getBoundingClientRect().height
const maxHeightNumStr = String(maxHeight).replace(/px$/, '')
const vMaxHeight = maxHeight
? !isNaN(Number(String(maxHeight).replace(/px/, '')))
? Number(maxHeight)
? !isNaN(Number(maxHeightNumStr))
? Number(maxHeightNumStr)
: realHeight
: 300

return (
<div
ref={scrollBodyElementRef}
Expand All @@ -87,7 +86,7 @@ export const TableBody = forwardRef<HTMLDivElement | null, TableBodyProps>(
style={{ height: 2, marginTop: -1, background: 'transparent', width: rowWidth }}
></div>
{isArrayNonEmpty(transitionData) ? (
<div style={{ width: '100%', position: 'sticky', left: 0 }}>
<div ref={virtualListRef} style={{ width: '100%', position: 'sticky', left: 0, maxHeight}}>
<VirtualList
prefixCls={`${cls}--virtual`}
data={transitionData}
Expand Down

0 comments on commit 9416cd0

Please sign in to comment.