Skip to content

Commit

Permalink
[v4] [table] fix: sync quadrants on frozen cols/rows resize (#5144)
Browse files Browse the repository at this point in the history
Add logic to TableQuadrantStack to force it to re-sync quadrant width/heights after its grid changes in a way that causes the left quadrant to change width or the top quadrant to change height, either through resizing frozen columns or frozen rows.
  • Loading branch information
adidahiya committed Feb 24, 2022
1 parent 86a3d19 commit 3d8bac1
Showing 1 changed file with 29 additions and 5 deletions.
34 changes: 29 additions & 5 deletions packages/table/src/quadrants/tableQuadrantStack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,15 @@ export interface ITableQuadrantStackProps extends Props {
*
* REQUIRES QUADRANT RESYNC
*/
numFrozenColumns?: number;
numFrozenColumns: number;

/**
* The number of frozen rows. Affects the layout of the table, so we need to
* know when this changes in order to synchronize quadrant sizes properly.
*
* REQUIRES QUADRANT RESYNC
*/
numFrozenRows?: number;
numFrozenRows: number;

/**
* The number of rows. Affects the layout of the table, so we need to know
Expand Down Expand Up @@ -362,12 +362,16 @@ export class TableQuadrantStack extends AbstractComponent2<ITableQuadrantStackPr
}

public componentDidUpdate(prevProps: ITableQuadrantStackProps) {
// sync'ing quadrant views triggers expensive reflows, so we only call
// it when layout-affecting props change.
if (
// sync'ing quadrant views triggers expensive reflows, so we only call
// it when layout-affecting props change.
!CoreUtils.shallowCompareKeys(this.props, prevProps, {
include: SYNC_TRIGGER_PROP_KEYS,
})
}) ||
// in addition to those props, we also care about frozen parts of the grid
// which may cause the top / left quadrants to change height / width
this.didFrozenColumnWidthsChange(prevProps) ||
this.didFrozenRowHeightsChange(prevProps)
) {
this.emitRefs();
this.syncQuadrantViews();
Expand Down Expand Up @@ -963,6 +967,26 @@ export class TableQuadrantStack extends AbstractComponent2<ITableQuadrantStackPr
// Helpers
// =======

/** Returns true the cumulative width of all frozen columns in the grid changed. */
private didFrozenColumnWidthsChange(prevProps: ITableQuadrantStackProps) {
return (
this.props.numFrozenColumns > 0 &&
this.props.grid !== prevProps.grid &&
this.props.grid.getCumulativeWidthAt(this.props.numFrozenColumns - 1) !==
prevProps.grid.getCumulativeWidthAt(prevProps.numFrozenColumns - 1)
);
}

/** Returns true the cumulative height of all frozen rows in the grid changed. */
private didFrozenRowHeightsChange(prevProps: ITableQuadrantStackProps) {
return (
this.props.numFrozenRows > 0 &&
this.props.grid !== prevProps.grid &&
this.props.grid.getCumulativeHeightAt(this.props.numFrozenRows - 1) !==
prevProps.grid.getCumulativeHeightAt(prevProps.numFrozenRows - 1)
);
}

/**
* Returns the width or height of *only the grid* in the secondary quadrants
* (TOP, LEFT, TOP_LEFT), based on the number of frozen rows and columns.
Expand Down

1 comment on commit 3d8bac1

@blueprint-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[v4] [table] fix: sync quadrants on frozen cols/rows resize (#5144)

Previews: documentation | landing | table | modern colors demo

Please sign in to comment.