Skip to content

Commit

Permalink
feat(components/switcher): move logic from ngonchanges to function #1476
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed Jul 8, 2024
1 parent 88739e2 commit d994b9d
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,7 @@ export class PrizmSwitcherComponent extends PrizmAbstractTestId implements Contr
}
ngOnChanges(changes: SimpleChanges): void {
if (prizmHasChanges(changes, 'selectedSwitcherIdx') && prizmHasChanges(changes, 'switchers')) {
const idx =
this.selectedSwitcherIdx <= this.switchers.length ? this.selectedSwitcherIdx : INITIAL_SWITHCER_INDEX;
const item = this.switchers[idx];
if (item) this.selectSwitcher(item, idx);
this.setActiveSwitcherOnChange();
}
}
public selectSwitcher(item: PrizmSwitcherItem, idx: number): void {
Expand All @@ -97,4 +94,11 @@ export class PrizmSwitcherComponent extends PrizmAbstractTestId implements Contr
public setDisabledState(isDisabled: boolean): void {
this.cdRef.markForCheck();
}

private setActiveSwitcherOnChange(): void {
const idx =
this.selectedSwitcherIdx <= this.switchers.length ? this.selectedSwitcherIdx : INITIAL_SWITHCER_INDEX;
const item = this.switchers[idx];
if (item) this.selectSwitcher(item, idx);
}
}

0 comments on commit d994b9d

Please sign in to comment.