Skip to content
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

feat(checkbox,switch): more output signals #236

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 6 additions & 5 deletions libs/ui/checkbox/brain/src/lib/brn-checkbox.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ import {
computed,
effect,
ElementRef,
EventEmitter,
forwardRef,
inject,
input,
Input,
OnDestroy,
Output,
output,
PLATFORM_ID,
Renderer2,
signal,
ViewChild,
ViewEncapsulation,
} from '@angular/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { NG_VALUE_ACCESSOR } from '@angular/forms';
import { rxHostPressedListener } from '@spartan-ng/ui-core';

Expand Down Expand Up @@ -160,11 +160,12 @@ export class BrnCheckboxComponent implements AfterContentInit, OnDestroy {
@ViewChild('checkBox', { static: true })
public checkbox?: ElementRef<HTMLInputElement>;

@Output()
public readonly changed = new EventEmitter<boolean | 'indeterminate'>();
public readonly changed = output<boolean | 'indeterminate'>();

constructor() {
rxHostPressedListener().subscribe(() => this.handleChange());
rxHostPressedListener()
.pipe(takeUntilDestroyed())
.subscribe(() => this.handleChange());
effect(() => {
const parent = this._renderer.parentNode(this._elementRef.nativeElement);
if (!parent) return;
Expand Down
15 changes: 2 additions & 13 deletions libs/ui/checkbox/helm/src/lib/hlm-checkbox.component.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
import {
Component,
EventEmitter,
Input,
Output,
booleanAttribute,
computed,
forwardRef,
input,
signal,
} from '@angular/core';
import { Component, Input, booleanAttribute, computed, forwardRef, input, output, signal } from '@angular/core';
import { NG_VALUE_ACCESSOR } from '@angular/forms';
import { BrnCheckboxComponent, indeterminateBooleanAttribute } from '@spartan-ng/ui-checkbox-brain';
import { hlm } from '@spartan-ng/ui-core';
Expand Down Expand Up @@ -82,8 +72,7 @@ export class HlmCheckboxComponent {
public readonly checkIconName = input<string>('lucideCheck');
public readonly checkIconClass = input<string>('');

@Output()
public changed = new EventEmitter<boolean>();
public readonly changed = output<boolean>();

protected _handleChange(): void {
if (this.disabled()) return;
Expand Down
2 changes: 0 additions & 2 deletions libs/ui/switch/brain/src/lib/brn-switch-ng-model.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,9 @@ describe('BrnSwitchComponentNgModelIntegration', () => {
expect(container.fixture.componentInstance.airplaneMode).toBe(true);
});

// TODO - why does this test not fail? it should be setup(false, true) but setup(false, false) still passes
Celtian marked this conversation as resolved.
Show resolved Hide resolved
it('should do nothing when disabled', async () => {
const { labelElement, user, container } = await setup(false, false);

// TODO - using fireEvent.click here causes the test to fail, not sure why.
await user.click(labelElement);
await screen.findByDisplayValue('off');
expect(container.fixture.componentInstance.airplaneMode).toBe(false);
Expand Down
14 changes: 7 additions & 7 deletions libs/ui/switch/brain/src/lib/brn-switch.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ import {
Component,
effect,
ElementRef,
EventEmitter,
forwardRef,
HostBinding,
inject,
Input,
OnDestroy,
Output,
output,
PLATFORM_ID,
Renderer2,
signal,
ViewChild,
ViewEncapsulation,
} from '@angular/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { NG_VALUE_ACCESSOR } from '@angular/forms';
import { rxHostPressedListener } from '@spartan-ng/ui-core';

Expand Down Expand Up @@ -152,13 +152,13 @@ export class BrnSwitchComponent implements AfterContentInit, OnDestroy {
@ViewChild('checkBox', { static: true })
public checkbox?: ElementRef<HTMLInputElement>;

@Output()
public changed = new EventEmitter<boolean>();
@Output()
public touched = new EventEmitter<void>();
public readonly changed = output<boolean>();
public readonly touched = output<void>();

constructor() {
rxHostPressedListener().subscribe(() => this.handleChange());
rxHostPressedListener()
.pipe(takeUntilDestroyed())
.subscribe(() => this.handleChange());
effect(() => {
/** search for the label and set the disabled state */
let parent = this._renderer.parentNode(this._elementRef.nativeElement);
Expand Down
15 changes: 2 additions & 13 deletions libs/ui/switch/helm/src/lib/hlm-switch.component.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
import {
Component,
EventEmitter,
Input,
Output,
booleanAttribute,
computed,
forwardRef,
input,
signal,
} from '@angular/core';
import { Component, Input, booleanAttribute, computed, forwardRef, input, output, signal } from '@angular/core';
import { NG_VALUE_ACCESSOR } from '@angular/forms';
import { hlm } from '@spartan-ng/ui-core';
import { BrnSwitchComponent, BrnSwitchThumbComponent } from '@spartan-ng/ui-switch-brain';
Expand Down Expand Up @@ -59,8 +49,7 @@ export class HlmSwitchComponent {
),
);

@Output()
public changed = new EventEmitter<boolean>();
public readonly changed = output<boolean>();

protected _handleChange(value: boolean): void {
this._checked.set(value);
Expand Down