Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,4 +264,4 @@ Copyright 2026 creativeLabs Łukasz Holeczek. Code released under the [MIT Licen
[npm-coreui-angular-badge-next]: https://img.shields.io/npm/v/@coreui/angular/next?style=flat-square&color=red
[npm-coreui-angular]: https://www.npmjs.com/package/@coreui/angular
[npm-coreui-angular-download]: https://img.shields.io/npm/dm/@coreui/angular.svg?style=flat-square
[angular-badge]: https://img.shields.io/badge/angular-^22.2.0-lightgrey.svg?style=flat-square&logo=angular
[angular-badge]: https://img.shields.io/badge/angular-^22.3.0-lightgrey.svg?style=flat-square&logo=angular
2 changes: 1 addition & 1 deletion projects/coreui-angular-chartjs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Featured CoreUI for Angular libraries:
[npm-badge-next]: https://img.shields.io/npm/v/@coreui/angular-chartjs/next?style=flat-square&color=red
[npm]: https://www.npmjs.com/package/@coreui/angular-chartjs
[npm-download]: https://img.shields.io/npm/dm/@coreui/angular-chartjs.svg?style=flat-square
[angular-badge]: https://img.shields.io/badge/angular-^22.2.0-lightgrey.svg?style=flat-square&logo=angular
[angular-badge]: https://img.shields.io/badge/angular-^22.3.0-lightgrey.svg?style=flat-square&logo=angular

##### install:

Expand Down
2 changes: 1 addition & 1 deletion projects/coreui-angular-chartjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"url": "https://github.com/coreui/coreui-angular/issues"
},
"peerDependencies": {
"@angular/core": "^22.2.0",
"@angular/core": "^22.3.0",
"@coreui/chartjs": "^4.2.0",
"chart.js": "^4.5.1"
},
Expand Down
2 changes: 1 addition & 1 deletion projects/coreui-angular/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,4 +264,4 @@ Copyright 2026 creativeLabs Łukasz Holeczek. Code released under the [MIT Licen
[npm-coreui-angular-badge-next]: https://img.shields.io/npm/v/@coreui/angular/next?style=flat-square&color=red
[npm-coreui-angular]: https://www.npmjs.com/package/@coreui/angular
[npm-coreui-angular-download]: https://img.shields.io/npm/dm/@coreui/angular.svg?style=flat-square
[angular-badge]: https://img.shields.io/badge/angular-^22.2.0-lightgrey.svg?style=flat-square&logo=angular
[angular-badge]: https://img.shields.io/badge/angular-^22.3.0-lightgrey.svg?style=flat-square&logo=angular
11 changes: 6 additions & 5 deletions projects/coreui-angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@
},
"sideEffects": false,
"peerDependencies": {
"@angular/aria": "^22.2.0",
"@angular/cdk": "^22.2.0",
"@angular/common": "^22.2.0",
"@angular/core": "^22.2.0",
"@angular/router": "^22.2.0",
"@angular/aria": "^22.3.0",
"@angular/cdk": "^22.3.0",
"@angular/common": "^22.3.0",
"@angular/core": "^22.3.0",
"@angular/forms": "^22.3.0",
"@angular/router": "^22.3.0",
"@coreui/coreui": "^5.9.1",
"@coreui/icons-angular": "~5.7.43",
"rxjs": "^7.8.2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
viewChild
} from '@angular/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { AsyncValidator, NG_ASYNC_VALIDATORS, NG_VALIDATORS, NgModel, Validator } from '@angular/forms';
import { NgModel } from '@angular/forms';
import { take } from 'rxjs';
import { ChipComponent } from '../chip/chip.component';
import { ChipSetRef } from '../chip/chip-set-ref';
Expand Down Expand Up @@ -45,8 +45,6 @@ import { UIDService } from '../services/uid.service';
export class ChipInputComponent implements AfterContentInit {
readonly #elementRef = inject<ElementRef<HTMLElement>>(ElementRef);
readonly #ngModel = inject(NgModel, { self: true, optional: true });
readonly #asyncValidators = inject<(AsyncValidator | unknown)[]>(NG_ASYNC_VALIDATORS, { self: true, optional: true });
readonly #validators = inject<(Validator | unknown)[]>(NG_VALIDATORS, { self: true, optional: true });
readonly #rtl = inject(RtlService);
readonly #service = inject(ChipSetService);

Expand Down Expand Up @@ -305,12 +303,10 @@ export class ChipInputComponent implements AfterContentInit {
focusFallback: () => this.focus(),
removeRequested: (value) => this.#removeChip(value)
});
this.#attachValidators();
this.#ngModel?.control.valueChanges.pipe(take(1), takeUntilDestroyed()).subscribe(() => this.#service.resync());
}

ngAfterContentInit(): void {
this.#watchValidators();
if (this.projectedChips().length > 0) {
console.warn('CoreUI [c-chip] placed inside c-chip-input is ignored - chips come from its value');
}
Expand Down Expand Up @@ -447,28 +443,6 @@ export class ChipInputComponent implements AfterContentInit {
this.#setText(this.#addChips(text.split(separator)).join(separator));
}

#attachValidators(): void {
const control = this.#ngModel?.control;
const validator = this.#ngModel?.validator;
const asyncValidator = this.#ngModel?.asyncValidator;
if (validator && control && !control.hasValidator(validator)) {
control.addValidators(validator);
}
if (asyncValidator && control && !control.hasAsyncValidator(asyncValidator)) {
control.addAsyncValidators(asyncValidator);
}
}

#watchValidators(): void {
const control = this.#ngModel?.control;
if (!control) {
return;
}
for (const item of [...(this.#validators ?? []), ...(this.#asyncValidators ?? [])]) {
(item as Validator | AsyncValidator).registerOnValidatorChange?.(() => control.updateValueAndValidity());
}
}

#leave(): void {
if (this.createOnBlur()) {
this.#createFromText();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import {
AsyncValidator,
FormsModule,
NG_ASYNC_VALIDATORS,
NG_VALIDATORS,
NgModel,
ValidationErrors
ValidationErrors,
Validator
} from '@angular/forms';
import { By } from '@angular/platform-browser';
import { AnnouncerService } from '../services/announcer.service';
Expand All @@ -30,6 +32,7 @@ class TemplateValidatorsHostComponent {
})
class TakenValidatorDirective implements AsyncValidator, OnChanges {
readonly cTaken = input('');
calls = 0;
#onChange?: () => void;

ngOnChanges(): void {
Expand All @@ -41,6 +44,7 @@ class TakenValidatorDirective implements AsyncValidator, OnChanges {
}

validate(control: AbstractControl<string[]>): Promise<ValidationErrors | null> {
this.calls++;
return Promise.resolve(control.value?.includes(this.cTaken()) ? { taken: true } : null);
}
}
Expand Down Expand Up @@ -68,6 +72,27 @@ class FirstRenderHostComponent {
tags = ['a'];
}

@Directive({
selector: '[cCounted]',
providers: [{ provide: NG_VALIDATORS, useExisting: CountedValidatorDirective, multi: true }]
})
class CountedValidatorDirective implements Validator {
calls = 0;

validate(): ValidationErrors | null {
this.calls++;
return null;
}
}

@Component({
imports: [FormsModule, ChipInputComponent, CountedValidatorDirective],
template: `<c-chip-input cCounted [(ngModel)]="tags" />`
})
class CountedValidatorHostComponent {
tags = ['a', 'b'];
}

describe('ChipInputComponent template validators', () => {
beforeEach(() => {
vi.spyOn(TestBed.inject(AnnouncerService), 'announce').mockReturnValue(vi.fn());
Expand Down Expand Up @@ -114,6 +139,19 @@ describe('ChipInputComponent template validators', () => {
expect(fixture.nativeElement.querySelector('form > button').disabled).toBe(true);
});

it('runs a validator written next to ngModel once per value change', async () => {
const fixture = TestBed.createComponent(CountedValidatorHostComponent);
await fixture.whenStable();
const validator = fixture.debugElement
.query(By.directive(CountedValidatorDirective))
.injector.get(CountedValidatorDirective);
validator.calls = 0;

fixture.nativeElement.querySelector('c-chip button.chip-remove').click();
await fixture.whenStable();
expect(validator.calls).toBe(1);
});

it('applies an async validator written next to ngModel and follows its changes', async () => {
const fixture = TestBed.createComponent(AsyncValidatorHostComponent);
const model = fixture.debugElement.query(By.directive(NgModel)).injector.get(NgModel);
Expand All @@ -126,4 +164,19 @@ describe('ChipInputComponent template validators', () => {
await new Promise((resolve) => setTimeout(resolve));
expect(model.control.errors).toBeNull();
});

it('runs an async validator written next to ngModel once per value change', async () => {
const fixture = TestBed.createComponent(AsyncValidatorHostComponent);
await fixture.whenStable();
await new Promise((resolve) => setTimeout(resolve));
const validator = fixture.debugElement
.query(By.directive(TakenValidatorDirective))
.injector.get(TakenValidatorDirective);
validator.calls = 0;

fixture.nativeElement.querySelector('c-chip button.chip-remove').click();
await fixture.whenStable();
await new Promise((resolve) => setTimeout(resolve));
expect(validator.calls).toBe(1);
});
});
2 changes: 1 addition & 1 deletion projects/coreui-icons-angular/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Featured CoreUI for Angular libraries:
[npm-coreui-icons-angular-v5-ng22]: https://img.shields.io/npm/v/@coreui/icons-angular/v5-ng22?style=flat-square&color=brightgreen
[npm-coreui-icons-angular-latest]: https://img.shields.io/npm/v/@coreui/icons-angular/latest?style=flat-square&color=brightgreen
[npm-coreui-icons-angular-next]: https://img.shields.io/npm/v/@coreui/icons-angular/next?style=flat-square&color=red
[angular-badge]: https://img.shields.io/badge/angular-^22.2.0-lightgrey.svg?style=flat-square&logo=angular
[angular-badge]: https://img.shields.io/badge/angular-^22.3.0-lightgrey.svg?style=flat-square&logo=angular

## `cIcon` directive

Expand Down
6 changes: 3 additions & 3 deletions projects/coreui-icons-angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
"url": "https://github.com/coreui/coreui-angular/issues"
},
"peerDependencies": {
"@angular/common": "^22.2.0",
"@angular/core": "^22.2.0",
"@angular/platform-browser": "^22.2.0"
"@angular/common": "^22.3.0",
"@angular/core": "^22.3.0",
"@angular/platform-browser": "^22.3.0"
},
"dependencies": {
"tslib": "^2.3.0"
Expand Down
Loading