Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions packages/@react-aria/table/src/useTableColumnResize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,25 +77,25 @@ export function useTableColumnResize<T>(props: AriaTableColumnResizeProps<T>, st

let startResize = useCallback((item) => {
if (!isResizing.current) {
lastSize.current = state.onColumnResize(item.key, state.getColumnWidth(item.key));
state.onColumnResizeStart(item.key);
lastSize.current = state.updateResizedColumns(item.key, state.getColumnWidth(item.key));
state.startResize(item.key);
onResizeStart?.(lastSize.current);
}
isResizing.current = true;
}, [isResizing, onResizeStart, state]);

let resize = useCallback((item, newWidth) => {
let sizes = state.onColumnResize(item.key, newWidth);
let sizes = state.updateResizedColumns(item.key, newWidth);
onResize?.(sizes);
lastSize.current = sizes;
}, [onResize, state]);

let endResize = useCallback((item) => {
if (lastSize.current == null) {
lastSize.current = state.onColumnResize(item.key, state.getColumnWidth(item.key));
lastSize.current = state.updateResizedColumns(item.key, state.getColumnWidth(item.key));
}
if (isResizing.current) {
state.onColumnResizeEnd();
state.endResize();
onResizeEnd?.(lastSize.current);
}
isResizing.current = false;
Expand Down
2 changes: 1 addition & 1 deletion packages/@react-spectrum/table/src/TableView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ function ResizableTableColumnHeader(props) {
state.sort(column.key, 'descending');
break;
case 'resize':
layout.onColumnResizeStart(column.key);
layout.startResize(column.key);
setIsInResizeMode(true);
break;
}
Expand Down
6 changes: 3 additions & 3 deletions packages/@react-stately/layout/src/TableLayout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ export class TableLayout<T> extends ListLayout<T> {
}

// outside, where this is called, should call props.onColumnResizeStart...
onColumnResizeStart(key: Key): void {
startResize(key: Key): void {
this.resizingColumn = key;
}

// only way to call props.onColumnResize with the new size outside of Layout is to send the result back
onColumnResize(key: Key, width: number): Map<Key, ColumnSize> {
updateResizedColumns(key: Key, width: number): Map<Key, ColumnSize> {
let newControlled = new Map(Array.from(this.controlledColumns).map(([key, entry]) => [key, entry.props.width]));
let newSizes = this.columnLayout.resizeColumnWidth(this.virtualizer.visibleRect.width, this.collection, newControlled, this.uncontrolledWidths, key, width);

Expand All @@ -110,7 +110,7 @@ export class TableLayout<T> extends ListLayout<T> {
return newSizes;
}

onColumnResizeEnd(): void {
endResize(): void {
this.resizingColumn = null;
}

Expand Down
24 changes: 12 additions & 12 deletions packages/@react-stately/table/src/useTableColumnResizeState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ export interface TableColumnResizeState<T> {
* Called to update the state that a resize event has occurred.
* Returns the new widths for all columns based on the resized column.
*/
onColumnResize: (key: Key, width: number) => Map<Key, ColumnSize>,
updateResizedColumns: (key: Key, width: number) => Map<Key, ColumnSize>,
/** Callback for when onColumnResize has started. */
onColumnResizeStart: (key: Key) => void,
startResize: (key: Key) => void,
/** Callback for when onColumnResize has ended. */
onColumnResizeEnd: () => void,
endResize: () => void,
/** Gets the current width for the specified column. */
getColumnWidth: (key: Key) => number,
/** Gets the current minWidth for the specified column. */
Expand Down Expand Up @@ -87,11 +87,11 @@ export function useTableColumnResizeState<T>(props: TableColumnResizeStateProps<
columnLayout.recombineColumns(state.collection.columns, uncontrolledWidths, uncontrolledColumns, controlledColumns)
, [state.collection.columns, uncontrolledWidths, uncontrolledColumns, controlledColumns, columnLayout]);

let onColumnResizeStart = useCallback((key: Key) => {
let startResize = useCallback((key: Key) => {
setResizingColumn(key);
}, [setResizingColumn]);

let onColumnResize = useCallback((key: Key, width: number): Map<Key, ColumnSize> => {
let updateResizedColumns = useCallback((key: Key, width: number): Map<Key, ColumnSize> => {
let newControlled = new Map(Array.from(controlledColumns).map(([key, entry]) => [key, entry.props.width]));
let newSizes = columnLayout.resizeColumnWidth(tableWidth, state.collection, newControlled, uncontrolledWidths, key, width);

Expand All @@ -101,7 +101,7 @@ export function useTableColumnResizeState<T>(props: TableColumnResizeStateProps<
return newSizes;
}, [controlledColumns, uncontrolledColumns, setUncontrolledWidths, tableWidth, columnLayout, state.collection, uncontrolledWidths]);

let onColumnResizeEnd = useCallback(() => {
let endResize = useCallback(() => {
setResizingColumn(null);
}, [setResizingColumn]);

Expand All @@ -111,9 +111,9 @@ export function useTableColumnResizeState<T>(props: TableColumnResizeStateProps<

return useMemo(() => ({
resizingColumn,
onColumnResize,
onColumnResizeStart,
onColumnResizeEnd,
updateResizedColumns,
startResize,
endResize,
getColumnWidth: (key: Key) =>
columnLayout.getColumnWidth(key),
getColumnMinWidth: (key: Key) =>
Expand All @@ -125,9 +125,9 @@ export function useTableColumnResizeState<T>(props: TableColumnResizeStateProps<
}), [
columnLayout,
resizingColumn,
onColumnResize,
onColumnResizeStart,
onColumnResizeEnd,
updateResizedColumns,
startResize,
endResize,
columnWidths,
state
]);
Expand Down