Skip to content

Commit

Permalink
fix(switcher): add random id to prevent id collide (#596)
Browse files Browse the repository at this point in the history
  • Loading branch information
vt-allianz authored and GitHub Enterprise committed May 24, 2022
1 parent 4a9a555 commit 178b782
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions projects/ng-aquila/src/switcher/switcher.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
ViewChild,
} from '@angular/core';
import { ControlValueAccessor, FormControl, FormGroupDirective, NgControl, NgForm } from '@angular/forms';
import { ErrorStateMatcher } from '@aposin/ng-aquila/utils';
import { ErrorStateMatcher, randomString } from '@aposin/ng-aquila/utils';

let nextId = 0;
/** Options for placement of the label */
Expand Down Expand Up @@ -45,7 +45,7 @@ export type LABEL_SIZE = 'small' | 'large';
},
})
export class NxSwitcherComponent implements ControlValueAccessor, DoCheck, AfterViewInit, OnDestroy {
private _id = `nx-switcher-${nextId++}`;
private _id = `nx-switcher-${nextId++}-${randomString()}`;
/** @docs-private */
errorState = false;

Expand Down
4 changes: 4 additions & 0 deletions projects/ng-aquila/src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ export function clamp(value: number, min = 0, max = 1) {
return Math.max(min, Math.min(max, value));
}

export function randomString() {
return Math.random().toString(36);
}

/** Provider that defines when form controls have an error. */
@Injectable({ providedIn: 'root' })
export class ErrorStateMatcher {
Expand Down

0 comments on commit 178b782

Please sign in to comment.