Skip to content

refactor(material-experimental): avoid unique id conflicts #19046

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/material-experimental/mdc-chips/chip-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class MatChipInput implements MatChipTextControl, OnChanges {
@Input() placeholder: string = '';

/** Unique id for the input. */
@Input() id: string = `mat-chip-list-input-${nextUniqueId++}`;
@Input() id: string = `mat-mdc-chip-list-input-${nextUniqueId++}`;

/** Whether the input is disabled. */
@Input()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ let nextUniqueId = 0;
}
})
export class MatError {
@Input() id: string = `mat-error-${nextUniqueId++}`;
@Input() id: string = `mat-mdc-error-${nextUniqueId++}`;
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ export class MatHint {
@Input() align: 'start' | 'end' = 'start';

/** Unique ID for the hint. Used for the aria-describedby on the form field control. */
@Input() id: string = `mat-hint-${nextUniqueId++}`;
@Input() id: string = `mat-mdc-hint-${nextUniqueId++}`;
}
6 changes: 3 additions & 3 deletions src/material-experimental/mdc-form-field/form-field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,13 @@ export class MatFormField implements AfterViewInit, OnDestroy, AfterContentCheck
private _hintLabel = '';

// Unique id for the hint label.
_hintLabelId: string = `mat-hint-${nextUniqueId++}`;
_hintLabelId = `mat-mdc-hint-${nextUniqueId++}`;

// Unique id for the internal form field label.
_labelId = `mat-form-field-label-${nextUniqueId++}`;
_labelId = `mat-mdc-form-field-label-${nextUniqueId++}`;

/** State of the mat-hint and mat-error animations. */
_subscriptAnimationState: string = '';
_subscriptAnimationState = '';

/** Width of the outline notch. */
_outlineNotchWidth: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ describe('MDC-based MatSlideToggle without forms', () => {
fixture.detectChanges();

// Once the id binding is set to null, the id property should auto-generate a unique id.
expect(inputElement.id).toMatch(/mat-slide-toggle-\d+-input/);
expect(inputElement.id).toMatch(/mat-mdc-slide-toggle-\d+-input/);
});

it('should forward the tabIndex to the underlying input', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/material-experimental/mdc-slide-toggle/slide-toggle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export class MatSlideToggle implements ControlValueAccessor, AfterViewInit, OnDe
private _onChange = (_: any) => {};
private _onTouched = () => {};

private _uniqueId: string = `mat-slide-toggle-${++nextUniqueId}`;
private _uniqueId: string = `mat-mdc-slide-toggle-${++nextUniqueId}`;
private _required: boolean = false;
private _checked: boolean = false;
private _foundation: MDCSwitchFoundation;
Expand Down