Skip to content

Commit

Permalink
refactor(toggle): migrate to signals
Browse files Browse the repository at this point in the history
  • Loading branch information
ashley-hunter committed Nov 12, 2024
1 parent cadd24c commit d7723a9
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion libs/ui/toggle/brain/src/lib/brn-toggle.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ import { injectBrnToggleGroup } from './brn-toggle-group.token';
export class BrnToggleDirective<T> {
private static uniqueId = 0;

/** Access the change detector. */
private readonly changeDetector = inject(ChangeDetectorRef);

/** Access the toggle group if available. */
protected readonly group = injectBrnToggleGroup<T>();

/** The id of the toggle. */
readonly id = input(`brn-toggle-${BrnToggleDirective.uniqueId++}`);

/** The value this toggle represents. */
Expand Down Expand Up @@ -54,6 +54,9 @@ export class BrnToggleDirective<T> {
}
}

/**
* @internal
*/
toggleOff(): void {
// if we are already off, do nothing
if (this.state() === 'off' || (this.group && !this.group.canDeselect(this.value()))) return;
Expand All @@ -71,6 +74,9 @@ export class BrnToggleDirective<T> {
this.changeDetector.detectChanges();
}

/**
* @internal
*/
toggleOn(): void {
// if we are already on, do nothing
if (this.state() === 'on') return;
Expand Down

0 comments on commit d7723a9

Please sign in to comment.