|
1 | 1 | import React, { useMemo, useRef, useState } from 'react';
|
2 | 2 |
|
3 |
| -import { useForkRef, useIsomorphicLayoutEffect } from '@react-devui/hooks'; |
| 3 | +import { useAsync, useForkRef, useIsomorphicLayoutEffect, useResize } from '@react-devui/hooks'; |
4 | 4 | import { getClassName, isSimpleArrayEqual } from '@react-devui/utils';
|
5 | 5 |
|
6 | 6 | import { registerComponentMate } from '../../utils';
|
@@ -43,6 +43,12 @@ function Table(props: DTableProps, ref: React.ForwardedRef<HTMLDivElement>): JSX
|
43 | 43 | const combineElRef = useForkRef(elRef, ref);
|
44 | 44 | //#endregion
|
45 | 45 |
|
| 46 | + const dataRef = useRef<{ |
| 47 | + clearTid?: () => void; |
| 48 | + }>({}); |
| 49 | + |
| 50 | + const async = useAsync(); |
| 51 | + |
46 | 52 | const [fixed, setFixed] = useState<('left' | 'right')[]>([]);
|
47 | 53 |
|
48 | 54 | const getFixed = (el: HTMLDivElement) => {
|
@@ -70,6 +76,16 @@ function Table(props: DTableProps, ref: React.ForwardedRef<HTMLDivElement>): JSX
|
70 | 76 | // eslint-disable-next-line react-hooks/exhaustive-deps
|
71 | 77 | }, []);
|
72 | 78 |
|
| 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 | + |
73 | 89 | const contextValue = useMemo<DTableContextData>(
|
74 | 90 | () => ({
|
75 | 91 | gFixed: fixed,
|
|
0 commit comments