Skip to content

Commit a9b0cb9

Browse files
authored
fix: check includes on init and known reference issues (#516)
1 parent ab236ce commit a9b0cb9

File tree

5 files changed

+18
-17
lines changed

5 files changed

+18
-17
lines changed

.changeset/young-buttons-cross.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@alauda/ui": patch
3+
---
4+
5+
fix: check includes on init and known reference issues

src/anchor/anchor.component.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import {
2626
import { buildBem, isTemplateRef, last } from '../utils';
2727

2828
import { AnchorDirectiveChild } from './anchor.directive';
29-
import { AnchorModule } from './anchor.module';
3029
import { AnchorItem, AnchorTreeItem } from './types';
3130
import { getAnchorTreeItems } from './utils';
3231

@@ -38,7 +37,7 @@ const bem = buildBem('aui-anchor');
3837
encapsulation: ViewEncapsulation.None,
3938
changeDetection: ChangeDetectionStrategy.OnPush,
4039
standalone: true,
41-
imports: [NgFor, NgIf, NgTemplateOutlet, AnchorModule],
40+
imports: [NgFor, NgIf, NgTemplateOutlet],
4241
})
4342
export class AnchorTreeComponent
4443
extends AnchorDirectiveChild

src/paginator/paginator.component.spec.ts

+1-7
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import { Component, DebugElement, ViewChild } from '@angular/core';
22
import { ComponentFixture, TestBed } from '@angular/core/testing';
33
import { By } from '@angular/platform-browser';
44

5-
import { SelectComponent } from '../select/select.component';
6-
75
import { PaginatorComponent } from './paginator.component';
86

97
describe('PaginatorComponent', () => {
@@ -116,11 +114,7 @@ describe('PaginatorComponent', () => {
116114
</aui-paginator>
117115
`,
118116
standalone: true,
119-
imports: [
120-
PaginatorComponent,
121-
// https://github.com/angular/angular/issues/51568
122-
SelectComponent,
123-
],
117+
imports: [PaginatorComponent],
124118
})
125119
class TestComponent {
126120
currentPage = 1;

src/select/base-select.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
QueryList,
1313
ViewChild,
1414
ViewChildren,
15+
forwardRef,
1516
} from '@angular/core';
1617
import {
1718
BehaviorSubject,
@@ -143,10 +144,10 @@ export abstract class BaseSelect<T, V = T>
143144
@ContentChild(OptionContentDirective)
144145
protected optionContent?: OptionContentDirective;
145146

146-
@ViewChildren(OptionComponent)
147+
@ViewChildren(forwardRef(() => OptionComponent))
147148
customOptions: QueryList<OptionComponent<T>>;
148149

149-
@ContentChildren(OptionComponent, { descendants: true })
150+
@ContentChildren(forwardRef(() => OptionComponent), { descendants: true })
150151
contentOptions: QueryList<OptionComponent<T>>;
151152

152153
isTemplateRef = isTemplateRef;

src/select/validators.ts

+8-6
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ import {
66
Validator,
77
ValidatorFn,
88
} from '@angular/forms';
9+
import { startWith } from 'rxjs';
910

1011
import { coerceAttrBoolean } from '../utils';
1112

1213
import { SelectComponent } from './select.component';
1314
import { TrackFn } from './select.types';
1415

15-
// @dynamic
1616
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
1717
export class AuiSelectValidators {
1818
static includes<T>(
@@ -64,11 +64,13 @@ export class IncludesDirective<T> implements Validator, AfterContentInit {
6464
constructor(private readonly selectRef: SelectComponent<T>) {}
6565

6666
ngAfterContentInit() {
67-
this.selectRef.contentOptions.changes.subscribe(() => {
68-
if (this.onValidatorChange) {
69-
this.onValidatorChange();
70-
}
71-
});
67+
this.selectRef.contentOptions.changes
68+
.pipe(startWith(this.selectRef.contentOptions))
69+
.subscribe(() => {
70+
if (this.onValidatorChange) {
71+
this.onValidatorChange();
72+
}
73+
});
7274
}
7375

7476
registerOnValidatorChange(fn: () => void) {

0 commit comments

Comments
 (0)