Skip to content

Commit 5ae06bd

Browse files
Marshall PetersonMarshall Peterson
Marshall Peterson
authored and
Marshall Peterson
committed
move the min/max check to TableLayout so that it will correctly support percentage values for min/max
1 parent 1499f75 commit 5ae06bd

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

packages/@react-aria/table/src/useTableColumnResize.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ export function useTableColumnResize(state, item): any {
2727
},
2828
onMove({deltaX}) {
2929
columnResizeWidthRef.current += deltaX;
30-
let widthRespectingBoundaries = Math.max(item.props.minWidth || 75, Math.min(columnResizeWidthRef.current, item.props.maxWidth || Infinity));
31-
stateRef.current.setResizeDelta(widthRespectingBoundaries);
32-
stateRef.current.setColumnWidth(item.key, widthRespectingBoundaries);
30+
stateRef.current.setResizeDelta(columnResizeWidthRef.current);
3331
},
3432
onMoveEnd() {
3533
stateRef.current.setCurrentResizeColumn();

packages/@react-stately/layout/src/TableLayout.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,17 @@ export class TableLayout<T> extends ListLayout<T> {
7171
this.wasLoading = this.isLoading;
7272
this.isLoading = loadingState === 'loading' || loadingState === 'loadingMore';
7373

74+
// only rebuild columns that come after the column being resized, if no column is being resized, they will all be built
7475
const resizeIndex = this.collection.columns.findIndex(column => column.key === this.currentResizeColumn);
75-
let affectedResizeColumns = this.collection.columns.slice(resizeIndex + 1, this.collection.columns.length);
76-
let remainingSpace = this.virtualizer.visibleRect.width;
77-
remainingSpace = this.collection.columns.slice(0, resizeIndex + 1).reduce((acc, column) => acc - this.getColumnWidth_(column.key), this.virtualizer.visibleRect.width);
76+
// if resizing, set the column width for the resized column to the delta bounded by it's min/max
77+
if (resizeIndex > -1) {
78+
const columnProps = this.collection.columns[resizeIndex].props;
79+
this.setColumnWidth(this.currentResizeColumn, Math.max(this.getMinWidth(columnProps?.minWidth), Math.min(this.getMaxWidth(columnProps.maxWidth), this.resizeDelta)));
80+
}
81+
const affectedResizeColumns = this.collection.columns.slice(resizeIndex + 1, this.collection.columns.length);
82+
const remainingSpace = this.collection.columns.slice(0, resizeIndex + 1).reduce((acc, column) => acc - this.getColumnWidth_(column.key), this.virtualizer.visibleRect.width);
7883
this.buildColumnWidths(affectedResizeColumns, remainingSpace);
84+
7985
let header = this.buildHeader();
8086
let body = this.buildBody(0);
8187
body.layoutInfo.rect.width = Math.max(header.layoutInfo.rect.width, body.layoutInfo.rect.width);

0 commit comments

Comments
 (0)