Skip to content

Commit e280b65

Browse files
committed
review
1 parent 2c620fb commit e280b65

File tree

6 files changed

+35
-21
lines changed

6 files changed

+35
-21
lines changed

src/cdk-experimental/column-resize/column-resize-notifier.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export interface ColumnSizeAction extends ColumnSize {
2828
readonly completeImmediately?: boolean;
2929
}
3030

31-
/** Conduit for resize-releated events within the table. */
31+
/** Originating source of column resize events within a table. */
3232
@Injectable()
3333
export class ColumnResizeNotifierSource {
3434
/** Emits when an in-progress resize is canceled. */

src/cdk-experimental/column-resize/column-resize.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {filter, map, mapTo, pairwise, startWith, take, takeUntil} from 'rxjs/ope
1414
import {_closest, _matches} from '@angular/cdk-experimental/popover-edit';
1515

1616
import {ColumnResizeNotifier, ColumnResizeNotifierSource} from './column-resize-notifier';
17-
import {HEADER_CELL_SELECTOR, RESIZE_OVERLAY_SELECTOR} from './constants';
17+
import {HEADER_CELL_SELECTOR, RESIZE_OVERLAY_SELECTOR} from './selectors';
1818
import {HeaderRowEventDispatcher} from './event-dispatcher';
1919

2020
const HOVER_OR_ACTIVE_CLASS = 'cdk-column-resize-hover-or-active';

src/cdk-experimental/column-resize/event-dispatcher.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {distinctUntilChanged, map, share, skip, startWith} from 'rxjs/operators'
1212

1313
import {_closest} from '@angular/cdk-experimental/popover-edit';
1414

15-
import {HEADER_ROW_SELECTOR} from './constants';
15+
import {HEADER_ROW_SELECTOR} from './selectors';
1616

1717
/** Coordinates events between the column resize directives. */
1818
@Injectable()

src/cdk-experimental/column-resize/overlay-handle.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@ import {
2424

2525
import {_closest} from '@angular/cdk-experimental/popover-edit';
2626

27-
import {HEADER_CELL_SELECTOR} from './constants';
27+
import {HEADER_CELL_SELECTOR} from './selectors';
2828
import {ColumnResizeNotifierSource} from './column-resize-notifier';
2929
import {HeaderRowEventDispatcher} from './event-dispatcher';
3030
import {ResizeRef} from './resize-ref';
3131

32+
// TODO: Take another look at using cdk drag drop. IIRC I ran into a couple
33+
// good reasons for not using it but I don't remember what they were at this point.
3234
/**
3335
* Base class for a component shown over the edge of a resizable column that is responsible
3436
* for handling column resize mouse events and displaying any visible UI on the column edge.

src/cdk-experimental/column-resize/resizable.ts

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,16 @@ import {filter, takeUntil} from 'rxjs/operators';
2424

2525
import {_closest} from '@angular/cdk-experimental/popover-edit';
2626

27-
import {HEADER_ROW_SELECTOR} from './constants';
27+
import {HEADER_ROW_SELECTOR} from './selectors';
2828
import {ResizeOverlayHandle} from './overlay-handle';
2929
import {ColumnResize} from './column-resize';
3030
import {ColumnSizeAction, ColumnResizeNotifierSource} from './column-resize-notifier';
3131
import {HeaderRowEventDispatcher} from './event-dispatcher';
3232
import {ResizeRef} from './resize-ref';
3333
import {ResizeStrategy} from './resize-strategy';
3434

35+
const OVERLAY_ACTIVE_CLASS = 'cdk-resizable-overlay-thumb-active';
36+
3537
/**
3638
* Base class for Resizable directives which are applied to column headers to make those columns
3739
* resizable.
@@ -108,6 +110,10 @@ export abstract class Resizable<HandleComponent extends ResizeOverlayHandle>
108110
protected abstract getOverlayHandleComponentType(): Type<HandleComponent>;
109111

110112
private _createOverlayForHandle(): OverlayRef {
113+
// Use of overlays allows us to properly capture click events spanning parts
114+
// of two table cells and is also useful for displaying a resize thumb
115+
// over both cells and extending it down the table as needed.
116+
111117
const positionStrategy = this.overlay.position()
112118
.flexibleConnectedTo(this.elementRef.nativeElement!)
113119
.withFlexibleDimensions(false)
@@ -163,30 +169,38 @@ export abstract class Resizable<HandleComponent extends ResizeOverlayHandle>
163169
this._applySize(size);
164170

165171
if (completeImmediately) {
166-
this.ngZone.run(() => {
167-
this.resizeNotifier.resizeCompleted.next({
168-
columnId: this.columnDef.name,
169-
size: this.elementRef.nativeElement!.offsetWidth,
170-
});
171-
});
172+
this._completeResizeOperation();
172173
}
173174
});
174175

175176
merge(
176177
this.resizeNotifier.resizeCanceled,
177178
this.resizeNotifier.resizeCompleted,
178179
).pipe(takeUntilDestroyed).subscribe(columnSize => {
179-
this.elementRef.nativeElement!.classList.remove(OVERLAY_ACTIVE_CLASS);
180+
this._cleanUpAfterResize(columnSize);
181+
});
182+
}
183+
184+
private _completeResizeOperation(): void {
185+
this.ngZone.run(() => {
186+
this.resizeNotifier.resizeCompleted.next({
187+
columnId: this.columnDef.name,
188+
size: this.elementRef.nativeElement!.offsetWidth,
189+
});
190+
});
191+
}
180192

181-
if (this.overlayRef && this.overlayRef.hasAttached()) {
182-
this._updateOverlayHandleHeight();
183-
this.overlayRef.updatePosition();
193+
private _cleanUpAfterResize(columnSize: ColumnSizeAction): void {
194+
this.elementRef.nativeElement!.classList.remove(OVERLAY_ACTIVE_CLASS);
184195

185-
if (columnSize.columnId === this.columnDef.name) {
186-
this.inlineHandle!.focus();
187-
}
196+
if (this.overlayRef && this.overlayRef.hasAttached()) {
197+
this._updateOverlayHandleHeight();
198+
this.overlayRef.updatePosition();
199+
200+
if (columnSize.columnId === this.columnDef.name) {
201+
this.inlineHandle!.focus();
188202
}
189-
});
203+
}
190204
}
191205

192206
private _createHandlePortal(): ComponentPortal<HandleComponent> {
@@ -234,5 +248,3 @@ export abstract class Resizable<HandleComponent extends ResizeOverlayHandle>
234248
this.elementRef.nativeElement!.appendChild(this.inlineHandle);
235249
}
236250
}
237-
238-
const OVERLAY_ACTIVE_CLASS = 'cdk-resizable-overlay-thumb-active';

0 commit comments

Comments
 (0)