Skip to content

Commit 9fac01a

Browse files
committed
feat(ui): support update fixed state when table resize
1 parent 0851206 commit 9fac01a

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

packages/ui/src/components/table/Table.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { useMemo, useRef, useState } from 'react';
22

3-
import { useForkRef, useIsomorphicLayoutEffect } from '@react-devui/hooks';
3+
import { useAsync, useForkRef, useIsomorphicLayoutEffect, useResize } from '@react-devui/hooks';
44
import { getClassName, isSimpleArrayEqual } from '@react-devui/utils';
55

66
import { registerComponentMate } from '../../utils';
@@ -43,6 +43,12 @@ function Table(props: DTableProps, ref: React.ForwardedRef<HTMLDivElement>): JSX
4343
const combineElRef = useForkRef(elRef, ref);
4444
//#endregion
4545

46+
const dataRef = useRef<{
47+
clearTid?: () => void;
48+
}>({});
49+
50+
const async = useAsync();
51+
4652
const [fixed, setFixed] = useState<('left' | 'right')[]>([]);
4753

4854
const getFixed = (el: HTMLDivElement) => {
@@ -70,6 +76,16 @@ function Table(props: DTableProps, ref: React.ForwardedRef<HTMLDivElement>): JSX
7076
// eslint-disable-next-line react-hooks/exhaustive-deps
7177
}, []);
7278

79+
useResize(elRef, () => {
80+
dataRef.current.clearTid?.();
81+
dataRef.current.clearTid = async.setTimeout(() => {
82+
dataRef.current.clearTid = undefined;
83+
if (elRef.current) {
84+
getFixed(elRef.current);
85+
}
86+
}, 100);
87+
});
88+
7389
const contextValue = useMemo<DTableContextData>(
7490
() => ({
7591
gFixed: fixed,

0 commit comments

Comments
 (0)