Skip to content

Commit 88ae57e

Browse files
committed
refactor(cdk/stepper): use ID generator
Switches to using the ID generator service to create unique IDs.
1 parent 2af6e74 commit 88ae57e

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

src/cdk/stepper/stepper.ts

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

9-
import {FocusableOption, FocusKeyManager} from '@angular/cdk/a11y';
9+
import {_IdGenerator, FocusableOption, FocusKeyManager} from '@angular/cdk/a11y';
1010
import {Direction, Directionality} from '@angular/cdk/bidi';
1111
import {ENTER, hasModifierKey, SPACE} from '@angular/cdk/keycodes';
1212
import {
@@ -46,9 +46,6 @@ import {startWith, takeUntil} from 'rxjs/operators';
4646
import {CdkStepHeader} from './step-header';
4747
import {CdkStepLabel} from './step-label';
4848

49-
/** Used to generate unique ID for each stepper component. */
50-
let nextId = 0;
51-
5249
/**
5350
* Position state of the content of each step in stepper that is used for transitioning
5451
* the content into correct position upon step selection change.
@@ -324,7 +321,7 @@ export class CdkStepper implements AfterContentInit, AfterViewInit, OnDestroy {
324321
@Output() readonly selectedIndexChange: EventEmitter<number> = new EventEmitter<number>();
325322

326323
/** Used to track unique ID for each stepper component. */
327-
_groupId = nextId++;
324+
private _groupId = inject(_IdGenerator).getId('cdk-stepper-');
328325

329326
/** Orientation of the stepper. */
330327
@Input()
@@ -434,12 +431,12 @@ export class CdkStepper implements AfterContentInit, AfterViewInit, OnDestroy {
434431

435432
/** Returns a unique id for each step label element. */
436433
_getStepLabelId(i: number): string {
437-
return `cdk-step-label-${this._groupId}-${i}`;
434+
return `${this._groupId}-label-${i}`;
438435
}
439436

440437
/** Returns unique id for each step content element. */
441438
_getStepContentId(i: number): string {
442-
return `cdk-step-content-${this._groupId}-${i}`;
439+
return `${this._groupId}-content-${i}`;
443440
}
444441

445442
/** Marks the component to be change detected. */

tools/public_api_guard/cdk/stepper.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ export class CdkStepper implements AfterContentInit, AfterViewInit, OnDestroy {
100100
_getIndicatorType(index: number, state?: StepState): StepState;
101101
_getStepContentId(i: number): string;
102102
_getStepLabelId(i: number): string;
103-
_groupId: number;
104103
linear: boolean;
105104
next(): void;
106105
// (undocumented)

0 commit comments

Comments
 (0)