Skip to content

Commit

Permalink
fix: table view scroll to top when expand/collapse
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanoshadjipetrou committed Oct 2, 2024
1 parent 45c4717 commit e5c228f
Showing 1 changed file with 0 additions and 30 deletions.
30 changes: 0 additions & 30 deletions src/app/components/table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const CollapseElement = `<svg width="17" height="16" viewBox="0 0 17 16" fill="n
export const Table: React.FC<TableProps> = (props: TableProps) => {
const tableBuiltRef = React.useRef(false);
const ref = React.useRef<HTMLDivElement>(null);
const [expandedCount, setExpandedCount] = React.useState(0);

React.useEffect(() => {
if (ref.current) {
Expand Down Expand Up @@ -41,16 +40,6 @@ export const Table: React.FC<TableProps> = (props: TableProps) => {
dataTreeStartExpanded,
});

table.on("dataTreeRowExpanded", (_, level) => {
if (level === 0) {
setExpandedCount((prev) => prev + 1);
}
});
table.on("dataTreeRowCollapsed", (_, level) => {
if (level === 0) {
setExpandedCount((prev) => prev - 1);
}
});
table.on("tableBuilt", () => {
tableBuiltRef.current = true;
});
Expand All @@ -76,25 +65,6 @@ export const Table: React.FC<TableProps> = (props: TableProps) => {
}
}, [props.data, tableBuiltRef.current]);

React.useEffect(() => {
if (ref.current) {
const tables = Tabulator.findTable(`#${props.id}`);
if (tables.length > 0 && tables[0]) {
if (
expandedCount > 0 &&
props.extraColumns &&
props.extraColumns.length > 0
) {
tables[0].setColumns(props.columns.concat(props.extraColumns));
} else {
setTimeout(() => {
tables[0].setColumns(props.columns);
}, 1);
}
}
}
}, [expandedCount, props.columns, props.extraColumns]);

return (
<Box
ref={ref}
Expand Down

0 comments on commit e5c228f

Please sign in to comment.