Skip to content

Commit a90861a

Browse files
kseamonwagnermaciel
authored andcommitted
fix(material-experimental/column-resize): Update for MDC and spec changes (#23908)
Updates selectors to work with MDC table. Applies some spec updates that improve appearance and update colors to address a11y contrast ratio issues. See internal changelist 407673233 for more context and a screencast link. (cherry picked from commit 2e40f7c)
1 parent e103a21 commit a90861a

File tree

3 files changed

+90
-17
lines changed

3 files changed

+90
-17
lines changed

src/material-experimental/column-resize/_column-resize-theme.scss

Lines changed: 51 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
$foreground: map.get($config, foreground);
1010

1111
$non-resizable-hover-divider: theming.get-color-from-palette($foreground, divider);
12-
$resizable-hover-divider: theming.get-color-from-palette($primary, 200);
13-
$resizable-active-divider: theming.get-color-from-palette($primary, 500);
12+
$resizable-hover-divider: theming.get-color-from-palette($primary, 600);
13+
$resizable-active-divider: theming.get-color-from-palette($primary, 600);
1414

1515
// TODO: these styles don't really belong in the `color` part of the theme.
1616
// We should figure out a better place for them.
@@ -21,13 +21,16 @@
2121

2222
.mat-column-resize-flex {
2323
.mat-header-cell,
24-
.mat-cell {
24+
.mat-mdc-header-cell,
25+
.mat-cell,
26+
.mat-mdc-cell {
2527
box-sizing: border-box;
2628
min-width: 32px;
2729
}
2830
}
2931

30-
.mat-header-cell {
32+
.mat-header-cell,
33+
.mat-mdc-header-cell {
3134
position: relative;
3235
}
3336

@@ -36,6 +39,7 @@
3639
}
3740

3841
.mat-header-cell:not(.mat-resizable)::after,
42+
.mat-mdc-header-cell:not(.mat-resizable)::after,
3943
.mat-resizable-handle {
4044
background: transparent;
4145
bottom: 0;
@@ -46,23 +50,26 @@
4650
width: 1px;
4751
}
4852

49-
.mat-header-cell:not(.mat-resizable)::after {
53+
.mat-header-cell:not(.mat-resizable)::after,
54+
.mat-mdc-header-cell:not(.mat-resizable)::after {
5055
content: '';
5156
}
5257

5358
.mat-header-cell:not(.mat-resizable)::after,
59+
.mat-mdc-header-cell:not(.mat-resizable)::after,
5460
.mat-resizable-handle {
5561
right: 0;
5662
}
5763

58-
[dir='rtl'] .mat-header-cell:not(.mat-resizable)::after,
59-
[dir='rtl'] .mat-resizable-handle {
60-
left: 0;
61-
right: auto;
62-
}
64+
.mat-header-row.cdk-column-resize-hover-or-active,
65+
.mat-mdc-header-row.cdk-column-resize-hover-or-active {
66+
.mat-header-cell,
67+
.mat-mdc-header-cell {
68+
border-right: none;
69+
}
6370

64-
.mat-header-row.cdk-column-resize-hover-or-active {
65-
.mat-header-cell:not(.mat-resizable)::after {
71+
.mat-header-cell:not(.mat-resizable)::after,
72+
.mat-mdc-header-cell:not(.mat-resizable)::after {
6673
background: $non-resizable-hover-divider;
6774
}
6875

@@ -71,13 +78,31 @@
7178
}
7279
}
7380

81+
[dir='rtl'] {
82+
.mat-header-cell:not(.mat-resizable)::after,
83+
.mat-mdc-header-cell:not(.mat-resizable)::after,
84+
.mat-resizable-handle {
85+
left: 0;
86+
right: auto;
87+
}
88+
89+
.mat-header-row.cdk-column-resize-hover-or-active,
90+
.mat-mdc-header-row.cdk-column-resize-hover-or-active {
91+
.mat-header-cell,
92+
.mat-mdc-header-cell {
93+
border-left: none;
94+
}
95+
}
96+
}
97+
7498
.mat-resizable.cdk-resizable-overlay-thumb-active > .mat-resizable-handle {
7599
opacity: 0;
76100
transition: none;
77101
}
78102

79103
.mat-resizable-handle:focus,
80-
.mat-header-row.cdk-column-resize-hover-or-active .mat-resizable-handle:focus {
104+
.mat-header-row.cdk-column-resize-hover-or-active .mat-resizable-handle:focus,
105+
.mat-mdc-header-row.cdk-column-resize-hover-or-active .mat-resizable-handle:focus {
81106
background: $resizable-active-divider;
82107
outline: none;
83108
}
@@ -94,11 +119,22 @@
94119
&:active {
95120
background: linear-gradient(90deg,
96121
transparent, transparent 7px,
97-
$resizable-active-divider, $resizable-active-divider 1px,
98-
transparent 8px, transparent);
122+
$resizable-active-divider 7px, $resizable-active-divider 9px,
123+
transparent 9px, transparent);
99124
will-change: transform;
125+
126+
.mat-column-resize-overlay-thumb-top {
127+
background: linear-gradient(90deg,
128+
transparent, transparent 4px,
129+
$resizable-active-divider 4px, $resizable-active-divider 12px,
130+
transparent 12px, transparent);
131+
}
100132
}
101133
}
134+
135+
.mat-column-resize-overlay-thumb-top {
136+
width: 100%;
137+
}
102138
}
103139

104140
@mixin typography($config-or-theme) {}

src/material-experimental/column-resize/column-resize.spec.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,18 @@ abstract class BaseTestComponent {
159159
dataSource = new ElementDataSource();
160160
direction = 'ltr';
161161

162+
getTableHeight(): number {
163+
return this.table.nativeElement.querySelector('.mat-table').offsetHeight;
164+
}
165+
162166
getTableWidth(): number {
163167
return this.table.nativeElement.querySelector('.mat-table').offsetWidth;
164168
}
165169

170+
getHeaderRowHeight(): number {
171+
return this.table.nativeElement.querySelector('.mat-header-row .mat-header-cell').offsetHeight;
172+
}
173+
166174
getColumnElement(index: number): HTMLElement {
167175
return this.table.nativeElement!.querySelectorAll('.mat-header-cell')[index] as HTMLElement;
168176
}
@@ -189,6 +197,10 @@ abstract class BaseTestComponent {
189197
return document.querySelectorAll('.mat-column-resize-overlay-thumb')[index] as HTMLElement;
190198
}
191199

200+
getOverlayThumbTopElement(index: number): HTMLElement {
201+
return document.querySelectorAll('.mat-column-resize-overlay-thumb-top')[index] as HTMLElement;
202+
}
203+
192204
getOverlayThumbPosition(index: number): number {
193205
const thumbPositionElement = this.getOverlayThumbElement(index)!.parentNode as HTMLElement;
194206
const left = parseInt(thumbPositionElement.style.left!, 10);
@@ -372,6 +384,9 @@ describe('Material Popover Edit', () => {
372384
it('shows resize handle overlays on header row hover and while a resize handle is in use', fakeAsync(() => {
373385
expect(component.getOverlayThumbElement(0)).toBeUndefined();
374386

387+
const headerRowHeight = component.getHeaderRowHeight();
388+
const tableHeight = component.getTableHeight();
389+
375390
component.triggerHoverState();
376391
fixture.detectChanges();
377392

@@ -382,6 +397,13 @@ describe('Material Popover Edit', () => {
382397
component.getOverlayThumbElement(2).classList.contains('mat-column-resize-overlay-thumb'),
383398
).toBe(true);
384399

400+
(expect(component.getOverlayThumbElement(0).offsetHeight) as any).isApproximately(
401+
headerRowHeight,
402+
);
403+
(expect(component.getOverlayThumbElement(2).offsetHeight) as any).isApproximately(
404+
headerRowHeight,
405+
);
406+
385407
component.beginColumnResizeWithMouse(0);
386408

387409
expect(
@@ -391,6 +413,16 @@ describe('Material Popover Edit', () => {
391413
component.getOverlayThumbElement(2).classList.contains('mat-column-resize-overlay-thumb'),
392414
).toBe(true);
393415

416+
(expect(component.getOverlayThumbElement(0).offsetHeight) as any).isApproximately(
417+
tableHeight,
418+
);
419+
(expect(component.getOverlayThumbTopElement(0).offsetHeight) as any).isApproximately(
420+
headerRowHeight,
421+
);
422+
(expect(component.getOverlayThumbElement(2).offsetHeight) as any).isApproximately(
423+
headerRowHeight,
424+
);
425+
394426
component.completeResizeWithMouseInProgress(0);
395427
component.endHoverState();
396428
fixture.detectChanges();

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
ElementRef,
1313
Inject,
1414
NgZone,
15+
ViewChild,
1516
ViewEncapsulation,
1617
} from '@angular/core';
1718
import {DOCUMENT} from '@angular/common';
@@ -39,11 +40,13 @@ import {AbstractMatColumnResize} from './column-resize-directives/common';
3940
changeDetection: ChangeDetectionStrategy.OnPush,
4041
encapsulation: ViewEncapsulation.None,
4142
host: {'class': 'mat-column-resize-overlay-thumb'},
42-
template: '',
43+
template: '<div #top class="mat-column-resize-overlay-thumb-top"></div>',
4344
})
4445
export class MatColumnResizeOverlayHandle extends ResizeOverlayHandle {
4546
protected readonly document: Document;
4647

48+
@ViewChild('top', {static: true}) topElement: ElementRef<HTMLElement>;
49+
4750
constructor(
4851
protected readonly columnDef: CdkColumnDef,
4952
protected readonly columnResize: ColumnResize,
@@ -64,10 +67,12 @@ export class MatColumnResizeOverlayHandle extends ResizeOverlayHandle {
6467
protected override updateResizeActive(active: boolean): void {
6568
super.updateResizeActive(active);
6669

70+
const originHeight = this.resizeRef.origin.nativeElement.offsetHeight;
71+
this.topElement.nativeElement.style.height = `${originHeight}px`;
6772
this.resizeRef.overlayRef.updateSize({
6873
height: active
6974
? (this.columnResize as AbstractMatColumnResize).getTableHeight()
70-
: this.resizeRef.origin.nativeElement!.offsetHeight,
75+
: originHeight,
7176
});
7277
}
7378
}

0 commit comments

Comments
 (0)