goetzrobin / spartan

Cutting-edge tools powering Angular full-stack development.
https://spartan.ng
MIT License
1.09k stars 120 forks source link

bug: select doesn't recognize changes if the initial value and the first change is the same #303

Closed eneajaho closed 4 weeks ago

eneajaho commented 4 weeks ago

Please provide the environment you discovered this bug in.


@Component({
    selector: 'spartan-select-preview',
    standalone: true,
    imports: [BrnSelectImports, HlmSelectImports, ReactiveFormsModule],
    template: `
        <form [formGroup]="form">
        <brn-select class="inline-block" formControlName="value" placeholder="Select an option">
            <hlm-select-trigger class="w-56">
                <hlm-select-value />
            </hlm-select-trigger>
            <hlm-select-content>
                <hlm-option value="Refresh">Refresh</hlm-option>
                <hlm-option value="Settings">Settings</hlm-option>
                <hlm-option value="Help">Help</hlm-option>
                <hlm-option value="Signout">Sign out</hlm-option>
            </hlm-select-content>
        </brn-select>
</form>
    `,
})
export class SelectPreviewComponent {
    form = new FormGroup({
        value: new FormControl('Help'), // we have an initial value here
    });

    constructor() {
        this.form.valueChanges.subscribe((value) => {
            console.log(value); // the value you select will be skipped the first time
        });
    }

    ngOnInit() {
        setTimeout(() => {
            this.form.patchValue({ value: 'Help' }); // we set the same value again here asynchronously
        });
    }
}

Which area/package is the issue in?

select

Description

If we update the value asynchronously and set the same value as in the initial form value. The first selection will be skipped.

Please provide the exception or error you saw

No response

Other information

No response

I would be willing to submit a PR to fix this issue