Skip to content

Commit f9fffab

Browse files
authored
refactor(column-resize): simplify RTL handling (#18835)
The various column resize components had a ton of boilerplate just to apply an ltr/rtl class. We can avoid it altogether by using `[dir='rtl']` like we do in all of the other components.
1 parent cc09ad8 commit f9fffab

File tree

12 files changed

+6
-36
lines changed

12 files changed

+6
-36
lines changed

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,18 @@
77
*/
88

99
import {Directive, ElementRef, NgZone} from '@angular/core';
10-
import {Directionality} from '@angular/cdk/bidi';
1110

1211
import {ColumnResize} from '../column-resize';
1312
import {ColumnResizeNotifier, ColumnResizeNotifierSource} from '../column-resize-notifier';
1413
import {HeaderRowEventDispatcher} from '../event-dispatcher';
15-
import {HOST_BINDINGS, FLEX_PROVIDERS} from './constants';
14+
import {FLEX_PROVIDERS} from './constants';
1615

1716
/**
1817
* Explicitly enables column resizing for a flexbox-based cdk-table.
1918
* Individual columns must be annotated specifically.
2019
*/
2120
@Directive({
2221
selector: 'cdk-table[columnResize]',
23-
host: HOST_BINDINGS,
2422
providers: [
2523
...FLEX_PROVIDERS,
2624
{provide: ColumnResize, useExisting: CdkColumnResizeFlex},
@@ -29,7 +27,6 @@ import {HOST_BINDINGS, FLEX_PROVIDERS} from './constants';
2927
export class CdkColumnResizeFlex extends ColumnResize {
3028
constructor(
3129
readonly columnResizeNotifier: ColumnResizeNotifier,
32-
readonly directionality: Directionality,
3330
protected readonly elementRef: ElementRef,
3431
protected readonly eventDispatcher: HeaderRowEventDispatcher,
3532
protected readonly ngZone: NgZone,

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,18 @@
77
*/
88

99
import {Directive, ElementRef, NgZone} from '@angular/core';
10-
import {Directionality} from '@angular/cdk/bidi';
1110

1211
import {ColumnResize} from '../column-resize';
1312
import {ColumnResizeNotifier, ColumnResizeNotifierSource} from '../column-resize-notifier';
1413
import {HeaderRowEventDispatcher} from '../event-dispatcher';
15-
import {HOST_BINDINGS, TABLE_PROVIDERS} from './constants';
14+
import {TABLE_PROVIDERS} from './constants';
1615

1716
/**
1817
* Explicitly enables column resizing for a table-based cdk-table.
1918
* Individual columns must be annotated specifically.
2019
*/
2120
@Directive({
2221
selector: 'table[cdk-table][columnResize]',
23-
host: HOST_BINDINGS,
2422
providers: [
2523
...TABLE_PROVIDERS,
2624
{provide: ColumnResize, useExisting: CdkColumnResize},
@@ -29,7 +27,6 @@ import {HOST_BINDINGS, TABLE_PROVIDERS} from './constants';
2927
export class CdkColumnResize extends ColumnResize {
3028
constructor(
3129
readonly columnResizeNotifier: ColumnResizeNotifier,
32-
readonly directionality: Directionality,
3330
protected readonly elementRef: ElementRef,
3431
protected readonly eventDispatcher: HeaderRowEventDispatcher,
3532
protected readonly ngZone: NgZone,

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,3 @@ export const TABLE_PROVIDERS: Provider[] = [
2525
TABLE_LAYOUT_FIXED_RESIZE_STRATEGY_PROVIDER,
2626
];
2727
export const FLEX_PROVIDERS: Provider[] = [...PROVIDERS, FLEX_RESIZE_STRATEGY_PROVIDER];
28-
export const HOST_BINDINGS = {
29-
'[class.cdk-column-resize-rtl]': 'directionality.value === "rtl"',
30-
};

src/cdk-experimental/column-resize/column-resize-directives/default-enabled-column-resize-flex.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,18 @@
77
*/
88

99
import {Directive, ElementRef, NgZone} from '@angular/core';
10-
import {Directionality} from '@angular/cdk/bidi';
1110

1211
import {ColumnResize} from '../column-resize';
1312
import {ColumnResizeNotifier, ColumnResizeNotifierSource} from '../column-resize-notifier';
1413
import {HeaderRowEventDispatcher} from '../event-dispatcher';
15-
import {HOST_BINDINGS, FLEX_PROVIDERS} from './constants';
14+
import {FLEX_PROVIDERS} from './constants';
1615

1716
/**
1817
* Implicitly enables column resizing for a flex cdk-table.
1918
* Individual columns will be resizable unless opted out.
2019
*/
2120
@Directive({
2221
selector: 'cdk-table',
23-
host: HOST_BINDINGS,
2422
providers: [
2523
...FLEX_PROVIDERS,
2624
{provide: ColumnResize, useExisting: CdkDefaultEnabledColumnResizeFlex},
@@ -29,7 +27,6 @@ import {HOST_BINDINGS, FLEX_PROVIDERS} from './constants';
2927
export class CdkDefaultEnabledColumnResizeFlex extends ColumnResize {
3028
constructor(
3129
readonly columnResizeNotifier: ColumnResizeNotifier,
32-
readonly directionality: Directionality,
3330
protected readonly elementRef: ElementRef,
3431
protected readonly eventDispatcher: HeaderRowEventDispatcher,
3532
protected readonly ngZone: NgZone,

src/cdk-experimental/column-resize/column-resize-directives/default-enabled-column-resize.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,18 @@
77
*/
88

99
import {Directive, ElementRef, NgZone} from '@angular/core';
10-
import {Directionality} from '@angular/cdk/bidi';
1110

1211
import {ColumnResize} from '../column-resize';
1312
import {ColumnResizeNotifier, ColumnResizeNotifierSource} from '../column-resize-notifier';
1413
import {HeaderRowEventDispatcher} from '../event-dispatcher';
15-
import {HOST_BINDINGS, TABLE_PROVIDERS} from './constants';
14+
import {TABLE_PROVIDERS} from './constants';
1615

1716
/**
1817
* Implicitly enables column resizing for a table-based cdk-table.
1918
* Individual columns will be resizable unless opted out.
2019
*/
2120
@Directive({
2221
selector: 'table[cdk-table]',
23-
host: HOST_BINDINGS,
2422
providers: [
2523
...TABLE_PROVIDERS,
2624
{provide: ColumnResize, useExisting: CdkDefaultEnabledColumnResize},
@@ -29,7 +27,6 @@ import {HOST_BINDINGS, TABLE_PROVIDERS} from './constants';
2927
export class CdkDefaultEnabledColumnResize extends ColumnResize {
3028
constructor(
3129
readonly columnResizeNotifier: ColumnResizeNotifier,
32-
readonly directionality: Directionality,
3330
protected readonly elementRef: ElementRef,
3431
protected readonly eventDispatcher: HeaderRowEventDispatcher,
3532
protected readonly ngZone: NgZone,

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
*/
88

99
import {AfterViewInit, Directive, ElementRef, NgZone, OnDestroy} from '@angular/core';
10-
import {Directionality} from '@angular/cdk/bidi';
1110
import {fromEvent, merge, ReplaySubject} from 'rxjs';
1211
import {filter, map, mapTo, pairwise, startWith, take, takeUntil} from 'rxjs/operators';
1312

@@ -33,7 +32,6 @@ export abstract class ColumnResize implements AfterViewInit, OnDestroy {
3332
/* Publicly accessible interface for triggering and being notified of resizes. */
3433
abstract readonly columnResizeNotifier: ColumnResizeNotifier;
3534

36-
abstract readonly directionality: Directionality;
3735
protected abstract readonly elementRef: ElementRef<HTMLElement>;
3836
protected abstract readonly eventDispatcher: HeaderRowEventDispatcher;
3937
protected abstract readonly ngZone: NgZone;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@
5151
right: 0;
5252
}
5353

54-
.mat-column-resize-rtl .mat-header-cell:not(.mat-resizable)::after,
55-
.mat-column-resize-rtl .mat-resizable-handle {
54+
[dir='rtl'] .mat-header-cell:not(.mat-resizable)::after,
55+
[dir='rtl'] .mat-resizable-handle {
5656
left: 0;
5757
right: auto;
5858
}

src/material-experimental/column-resize/column-resize-directives/column-resize-flex.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
*/
88

99
import {Directive, ElementRef, NgZone} from '@angular/core';
10-
import {Directionality} from '@angular/cdk/bidi';
1110
import {
1211
ColumnResize,
1312
ColumnResizeNotifier,
@@ -32,7 +31,6 @@ import {AbstractMatColumnResize, FLEX_HOST_BINDINGS, FLEX_PROVIDERS} from './com
3231
export class MatColumnResizeFlex extends AbstractMatColumnResize {
3332
constructor(
3433
readonly columnResizeNotifier: ColumnResizeNotifier,
35-
readonly directionality: Directionality,
3634
protected readonly elementRef: ElementRef,
3735
protected readonly eventDispatcher: HeaderRowEventDispatcher,
3836
protected readonly ngZone: NgZone,

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
*/
88

99
import {Directive, ElementRef, NgZone} from '@angular/core';
10-
import {Directionality} from '@angular/cdk/bidi';
1110
import {
1211
ColumnResize,
1312
ColumnResizeNotifier,
@@ -32,7 +31,6 @@ import {AbstractMatColumnResize, TABLE_HOST_BINDINGS, TABLE_PROVIDERS} from './c
3231
export class MatColumnResize extends AbstractMatColumnResize {
3332
constructor(
3433
readonly columnResizeNotifier: ColumnResizeNotifier,
35-
readonly directionality: Directionality,
3634
protected readonly elementRef: ElementRef,
3735
protected readonly eventDispatcher: HeaderRowEventDispatcher,
3836
protected readonly ngZone: NgZone,

src/material-experimental/column-resize/column-resize-directives/common.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,10 @@ export const TABLE_PROVIDERS: Provider[] = [
3131
];
3232
export const FLEX_PROVIDERS: Provider[] = [...PROVIDERS, FLEX_RESIZE_STRATEGY_PROVIDER];
3333

34-
const HOST_BINDINGS = {
35-
'[class.mat-column-resize-rtl]': 'directionality.value === "rtl"',
36-
};
3734
export const TABLE_HOST_BINDINGS = {
38-
...HOST_BINDINGS,
3935
'class': 'mat-column-resize-table',
4036
};
4137
export const FLEX_HOST_BINDINGS = {
42-
...HOST_BINDINGS,
4338
'class': 'mat-column-resize-flex',
4439
};
4540

src/material-experimental/column-resize/column-resize-directives/default-enabled-column-resize-flex.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
*/
88

99
import {Directive, ElementRef, NgZone} from '@angular/core';
10-
import {Directionality} from '@angular/cdk/bidi';
1110
import {
1211
ColumnResize,
1312
ColumnResizeNotifier,
@@ -32,7 +31,6 @@ import {AbstractMatColumnResize, FLEX_HOST_BINDINGS, FLEX_PROVIDERS} from './com
3231
export class MatDefaultEnabledColumnResizeFlex extends AbstractMatColumnResize {
3332
constructor(
3433
readonly columnResizeNotifier: ColumnResizeNotifier,
35-
readonly directionality: Directionality,
3634
protected readonly elementRef: ElementRef,
3735
protected readonly eventDispatcher: HeaderRowEventDispatcher,
3836
protected readonly ngZone: NgZone,

src/material-experimental/column-resize/column-resize-directives/default-enabled-column-resize.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
*/
88

99
import {Directive, ElementRef, NgZone} from '@angular/core';
10-
import {Directionality} from '@angular/cdk/bidi';
1110
import {
1211
ColumnResize,
1312
ColumnResizeNotifier,
@@ -32,7 +31,6 @@ import {AbstractMatColumnResize, TABLE_HOST_BINDINGS, TABLE_PROVIDERS} from './c
3231
export class MatDefaultEnabledColumnResize extends AbstractMatColumnResize {
3332
constructor(
3433
readonly columnResizeNotifier: ColumnResizeNotifier,
35-
readonly directionality: Directionality,
3634
protected readonly elementRef: ElementRef,
3735
protected readonly eventDispatcher: HeaderRowEventDispatcher,
3836
protected readonly ngZone: NgZone,

0 commit comments

Comments
 (0)