File tree Expand file tree Collapse file tree 2 files changed +4
-7
lines changed
src/material/slide-toggle Expand file tree Collapse file tree 2 files changed +4
-7
lines changed Original file line number Diff line number Diff line change @@ -173,7 +173,7 @@ describe('MatSlideToggle without forms', () => {
173
173
fixture . detectChanges ( ) ;
174
174
175
175
// Once the id binding is set to null, the id property should auto-generate a unique id.
176
- expect ( buttonElement . id ) . toMatch ( / m a t - m d c - s l i d e - t o g g l e - \d + - b u t t o n / ) ;
176
+ expect ( buttonElement . id ) . toMatch ( / m a t - m d c - s l i d e - t o g g l e - \w + \ d+ - b u t t o n / ) ;
177
177
} ) ;
178
178
179
179
it ( 'should forward the tabIndex to the underlying element' , ( ) => {
@@ -235,7 +235,7 @@ describe('MatSlideToggle without forms', () => {
235
235
236
236
// We fall back to pointing to the label if a value isn't provided.
237
237
expect ( buttonElement . getAttribute ( 'aria-labelledby' ) ) . toMatch (
238
- / m a t - m d c - s l i d e - t o g g l e - \d + - l a b e l / ,
238
+ / m a t - m d c - s l i d e - t o g g l e - \w + \ d+ - l a b e l / ,
239
239
) ;
240
240
} ) ;
241
241
Original file line number Diff line number Diff line change @@ -35,7 +35,7 @@ import {
35
35
ValidationErrors ,
36
36
Validator ,
37
37
} from '@angular/forms' ;
38
- import { FocusMonitor } from '@angular/cdk/a11y' ;
38
+ import { _IdGenerator , FocusMonitor } from '@angular/cdk/a11y' ;
39
39
import {
40
40
MAT_SLIDE_TOGGLE_DEFAULT_OPTIONS ,
41
41
MatSlideToggleDefaultOptions ,
@@ -63,9 +63,6 @@ export class MatSlideToggleChange {
63
63
) { }
64
64
}
65
65
66
- // Increasing integer for generating unique ids for slide-toggle components.
67
- let nextUniqueId = 0 ;
68
-
69
66
@Component ( {
70
67
selector : 'mat-slide-toggle' ,
71
68
templateUrl : 'slide-toggle.html' ,
@@ -220,7 +217,7 @@ export class MatSlideToggle
220
217
this . tabIndex = tabIndex == null ? 0 : parseInt ( tabIndex ) || 0 ;
221
218
this . color = defaults . color || 'accent' ;
222
219
this . _noopAnimations = animationMode === 'NoopAnimations' ;
223
- this . id = this . _uniqueId = ` mat-mdc-slide-toggle-${ ++ nextUniqueId } ` ;
220
+ this . id = this . _uniqueId = inject ( _IdGenerator ) . getId ( ' mat-mdc-slide-toggle-' ) ;
224
221
this . hideIcon = defaults . hideIcon ?? false ;
225
222
this . disabledInteractive = defaults . disabledInteractive ?? false ;
226
223
this . _labelId = this . _uniqueId + '-label' ;
You can’t perform that action at this time.
0 commit comments