Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(table): 修复虚拟列表maxHeight无法支持字符串问题(#2846) #2847

Merged
merged 6 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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