Skip to content

Commit

Permalink
fix: check includes on init and known reference issues (#516)
Browse files Browse the repository at this point in the history
  • Loading branch information
JounQin authored Oct 20, 2023
1 parent ab236ce commit a9b0cb9
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 17 deletions.
5 changes: 5 additions & 0 deletions .changeset/young-buttons-cross.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@alauda/ui": patch
---

fix: check includes on init and known reference issues
3 changes: 1 addition & 2 deletions src/anchor/anchor.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import {
import { buildBem, isTemplateRef, last } from '../utils';

import { AnchorDirectiveChild } from './anchor.directive';
import { AnchorModule } from './anchor.module';
import { AnchorItem, AnchorTreeItem } from './types';
import { getAnchorTreeItems } from './utils';

Expand All @@ -38,7 +37,7 @@ const bem = buildBem('aui-anchor');
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true,
imports: [NgFor, NgIf, NgTemplateOutlet, AnchorModule],
imports: [NgFor, NgIf, NgTemplateOutlet],
})
export class AnchorTreeComponent
extends AnchorDirectiveChild
Expand Down
8 changes: 1 addition & 7 deletions src/paginator/paginator.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { Component, DebugElement, ViewChild } from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';

import { SelectComponent } from '../select/select.component';

import { PaginatorComponent } from './paginator.component';

describe('PaginatorComponent', () => {
Expand Down Expand Up @@ -116,11 +114,7 @@ describe('PaginatorComponent', () => {
</aui-paginator>
`,
standalone: true,
imports: [
PaginatorComponent,
// https://github.com/angular/angular/issues/51568
SelectComponent,
],
imports: [PaginatorComponent],
})
class TestComponent {
currentPage = 1;
Expand Down
5 changes: 3 additions & 2 deletions src/select/base-select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
QueryList,
ViewChild,
ViewChildren,
forwardRef,
} from '@angular/core';
import {
BehaviorSubject,
Expand Down Expand Up @@ -143,10 +144,10 @@ export abstract class BaseSelect<T, V = T>
@ContentChild(OptionContentDirective)
protected optionContent?: OptionContentDirective;

@ViewChildren(OptionComponent)
@ViewChildren(forwardRef(() => OptionComponent))
customOptions: QueryList<OptionComponent<T>>;

@ContentChildren(OptionComponent, { descendants: true })
@ContentChildren(forwardRef(() => OptionComponent), { descendants: true })
contentOptions: QueryList<OptionComponent<T>>;

isTemplateRef = isTemplateRef;
Expand Down
14 changes: 8 additions & 6 deletions src/select/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import {
Validator,
ValidatorFn,
} from '@angular/forms';
import { startWith } from 'rxjs';

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

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

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

ngAfterContentInit() {
this.selectRef.contentOptions.changes.subscribe(() => {
if (this.onValidatorChange) {
this.onValidatorChange();
}
});
this.selectRef.contentOptions.changes
.pipe(startWith(this.selectRef.contentOptions))
.subscribe(() => {
if (this.onValidatorChange) {
this.onValidatorChange();
}
});
}

registerOnValidatorChange(fn: () => void) {
Expand Down

0 comments on commit a9b0cb9

Please sign in to comment.