diff --git a/.changeset/khaki-panthers-clean.md b/.changeset/khaki-panthers-clean.md new file mode 100644 index 000000000..08828ed76 --- /dev/null +++ b/.changeset/khaki-panthers-clean.md @@ -0,0 +1,5 @@ +--- +"@hi-ui/hiui": patch +--- + +fix(table): 修复虚拟列表 maxHeight 无法支持字符串问题 diff --git a/.changeset/rude-baboons-explode.md b/.changeset/rude-baboons-explode.md new file mode 100644 index 000000000..85db1e0e8 --- /dev/null +++ b/.changeset/rude-baboons-explode.md @@ -0,0 +1,5 @@ +--- +"@hi-ui/table": patch +--- + +fix(table): 修复虚拟列表 maxHeight 无法支持字符串问题 diff --git a/packages/ui/table/src/TableBody.tsx b/packages/ui/table/src/TableBody.tsx index 362d32297..3c9bb1cc7 100644 --- a/packages/ui/table/src/TableBody.tsx +++ b/packages/ui/table/src/TableBody.tsx @@ -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' @@ -15,7 +15,7 @@ const _role = 'table' const _prefix = getPrefixCls(_role) export const TableBody = forwardRef( - ({ prefixCls = _prefix, emptyContent }, ref) => { + ({ prefixCls = _prefix, emptyContent }) => { const { columns, isExpandTreeRows, @@ -33,7 +33,7 @@ export const TableBody = forwardRef( scrollbar, scrollLeft, } = useTableContext() - + const virtualListRef = useRef(null) const cls = cx(`${prefixCls}-body`) const getRequiredProps = useLatestCallback( @@ -58,14 +58,13 @@ export const TableBody = forwardRef( 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 (
( style={{ height: 2, marginTop: -1, background: 'transparent', width: rowWidth }} >
{isArrayNonEmpty(transitionData) ? ( -
+