Skip to content

Commit abbc5c1

Browse files
committed
refactor(cdk-experimental/column-resize): use ID generator
Switches to using the ID generator service to create unique IDs.
1 parent af71c31 commit abbc5c1

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
* found in the LICENSE file at https://angular.dev/license
77
*/
88

9-
import {AfterViewInit, Directive, ElementRef, NgZone, OnDestroy} from '@angular/core';
9+
import {AfterViewInit, Directive, ElementRef, inject, NgZone, OnDestroy} from '@angular/core';
10+
import {_IdGenerator} from '@angular/cdk/a11y';
1011
import {fromEvent, merge, Subject} from 'rxjs';
1112
import {filter, map, mapTo, pairwise, startWith, take, takeUntil} from 'rxjs/operators';
1213

@@ -19,14 +20,13 @@ import {HeaderRowEventDispatcher} from './event-dispatcher';
1920
const HOVER_OR_ACTIVE_CLASS = 'cdk-column-resize-hover-or-active';
2021
const WITH_RESIZED_COLUMN_CLASS = 'cdk-column-resize-with-resized-column';
2122

22-
let nextId = 0;
23-
2423
/**
2524
* Base class for ColumnResize directives which attach to mat-table elements to
2625
* provide common events and services for column resizing.
2726
*/
2827
@Directive()
2928
export abstract class ColumnResize implements AfterViewInit, OnDestroy {
29+
private _idGenerator = inject(_IdGenerator);
3030
protected readonly destroyed = new Subject<void>();
3131

3232
/* Publicly accessible interface for triggering and being notified of resizes. */
@@ -40,7 +40,7 @@ export abstract class ColumnResize implements AfterViewInit, OnDestroy {
4040
protected abstract readonly notifier: ColumnResizeNotifierSource;
4141

4242
/** Unique ID for this table instance. */
43-
protected readonly selectorId = `${++nextId}`;
43+
protected readonly selectorId = this._idGenerator.getId('cdk-column-resize-');
4444

4545
/** The id attribute of the table, if specified. */
4646
id?: string;
@@ -60,7 +60,7 @@ export abstract class ColumnResize implements AfterViewInit, OnDestroy {
6060

6161
/** Gets the unique CSS class name for this table instance. */
6262
getUniqueCssClass() {
63-
return `cdk-column-resize-${this.selectorId}`;
63+
return this.selectorId;
6464
}
6565

6666
/** Called when a column in the table is resized. Applies a css class to the table element. */

0 commit comments

Comments
 (0)