Skip to content

Commit

Permalink
fix: resizing column action causes order change in BAITable
Browse files Browse the repository at this point in the history
  • Loading branch information
yomybaby committed Nov 11, 2024
1 parent 5a12000 commit 85f75e2
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions react/src/components/BAITable.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useDebounce } from 'ahooks';
import { GetProps, Table } from 'antd';
import { createStyles } from 'antd-style';
import { ColumnsType } from 'antd/es/table';
Expand Down Expand Up @@ -34,9 +35,10 @@ const ResizableTitle = (
width: number;
},
) => {
const { onResize, width, ...restProps } = props;

const { onResize, width, onClick, ...restProps } = props;
const wrapRef = useRef<HTMLTableCellElement>(null);
const [isResizing, setIsResizing] = useState(false);
const debouncedIsResizing = useDebounce(isResizing, { wait: 100 });

// This is a workaround for the initial width of resizable columns if the width is not specified
useEffect(() => {
Expand Down Expand Up @@ -67,9 +69,24 @@ const ResizableTitle = (
/>
}
onResize={onResize}
onResizeStart={() => {
setIsResizing(true);
}}
onResizeStop={() => {
setIsResizing(false);
}}
draggableOpts={{ enableUserSelectHack: false }}
>
<th {...restProps} />
<th
onClick={(e) => {
if (debouncedIsResizing) {
e.preventDefault();
} else {
onClick?.(e);
}
}}
{...restProps}
/>
</Resizable>
);
};
Expand Down

0 comments on commit 85f75e2

Please sign in to comment.