From c2dd34de57952c448dbe593dae4723c39ea48223 Mon Sep 17 00:00:00 2001 From: waterplea Date: Tue, 3 Sep 2024 19:02:13 +0400 Subject: [PATCH 1/2] fix(core): `Textfield` fix expression change error --- projects/core/components/textfield/select.directive.ts | 2 +- .../core/components/textfield/textfield.component.ts | 9 +++++++-- .../core/components/textfield/textfield.directive.ts | 4 +--- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/projects/core/components/textfield/select.directive.ts b/projects/core/components/textfield/select.directive.ts index c419e35bf904..07a7779426aa 100644 --- a/projects/core/components/textfield/select.directive.ts +++ b/projects/core/components/textfield/select.directive.ts @@ -19,7 +19,7 @@ import {TuiTextfieldBase, TuiTextfieldDirective} from './textfield.directive'; providers: [tuiProvide(TuiTextfieldDirective, TuiSelect)], hostDirectives: [TuiNativeValidator, TuiAppearance], host: { - '[id]': 'el.id || autoId', + '[id]': 'textfield.id', '[attr.data-mode]': 'mode', '[class._empty]': 'value === ""', '(input)': '0', diff --git a/projects/core/components/textfield/textfield.component.ts b/projects/core/components/textfield/textfield.component.ts index 829aa7bed8b2..57af3ec19e0f 100644 --- a/projects/core/components/textfield/textfield.component.ts +++ b/projects/core/components/textfield/textfield.component.ts @@ -14,6 +14,7 @@ import { } from '@angular/core'; import {NgControl} from '@angular/forms'; import {WaResizeObserver} from '@ng-web-apis/resize-observer'; +import {tuiInjectId} from '@taiga-ui/cdk'; import {TuiNativeValidator} from '@taiga-ui/cdk/directives/native-validator'; import type {TuiContext, TuiStringHandler} from '@taiga-ui/cdk/types'; import {tuiInjectElement} from '@taiga-ui/cdk/utils/dom'; @@ -80,12 +81,16 @@ export class TuiTextfieldComponent implements TuiDataListHost { protected side = 0; protected readonly options = inject(TUI_TEXTFIELD_OPTIONS); + protected readonly autoId = tuiInjectId(); protected readonly icons = inject(TUI_COMMON_ICONS); @ViewChild('vcr', {read: ViewContainerRef, static: true}) public readonly vcr?: ViewContainerRef; - @ContentChild(forwardRef(() => TuiTextfieldDirective), {read: ElementRef}) + @ContentChild(forwardRef(() => TuiTextfieldDirective), { + read: ElementRef, + static: true, + }) public readonly el?: ElementRef; @Input() @@ -100,7 +105,7 @@ export class TuiTextfieldComponent implements TuiDataListHost { public readonly focused = computed(() => this.open() || this.focusedIn()); public get id(): string { - return this.el?.nativeElement.id || ''; + return this.el?.nativeElement.id || this.autoId; } public get size(): TuiSizeL | TuiSizeS { diff --git a/projects/core/components/textfield/textfield.directive.ts b/projects/core/components/textfield/textfield.directive.ts index 4f04b1137e56..864e3283d724 100644 --- a/projects/core/components/textfield/textfield.directive.ts +++ b/projects/core/components/textfield/textfield.directive.ts @@ -1,6 +1,5 @@ import {computed, Directive, inject, Input, signal} from '@angular/core'; import {TuiNativeValidator} from '@taiga-ui/cdk/directives/native-validator'; -import {tuiInjectId} from '@taiga-ui/cdk/services'; import {tuiInjectElement} from '@taiga-ui/cdk/utils/dom'; import { TuiAppearance, @@ -25,7 +24,6 @@ export class TuiTextfieldBase { ); protected readonly textfield = inject(TuiTextfieldComponent); - protected readonly autoId = tuiInjectId(); protected readonly el = tuiInjectElement(); @Input() @@ -71,7 +69,7 @@ export class TuiTextfieldBase { selector: 'input[tuiTextfield]', hostDirectives: [TuiNativeValidator, TuiAppearance], host: { - '[id]': 'el.id || autoId', + '[id]': 'textfield.id', '[readOnly]': 'readOnly', '[class._empty]': 'el.value === ""', '[attr.data-mode]': 'mode', From c8051de930671229c7530ec8f6f2410920fadb9f Mon Sep 17 00:00:00 2001 From: taiga-family-bot Date: Tue, 3 Sep 2024 15:21:28 +0000 Subject: [PATCH 2/2] chore: apply changes after linting [bot] --- projects/core/components/textfield/textfield.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/core/components/textfield/textfield.component.ts b/projects/core/components/textfield/textfield.component.ts index 57af3ec19e0f..77224e2ed474 100644 --- a/projects/core/components/textfield/textfield.component.ts +++ b/projects/core/components/textfield/textfield.component.ts @@ -14,8 +14,8 @@ import { } from '@angular/core'; import {NgControl} from '@angular/forms'; import {WaResizeObserver} from '@ng-web-apis/resize-observer'; -import {tuiInjectId} from '@taiga-ui/cdk'; import {TuiNativeValidator} from '@taiga-ui/cdk/directives/native-validator'; +import {tuiInjectId} from '@taiga-ui/cdk/services'; import type {TuiContext, TuiStringHandler} from '@taiga-ui/cdk/types'; import {tuiInjectElement} from '@taiga-ui/cdk/utils/dom'; import {tuiFocusedIn} from '@taiga-ui/cdk/utils/focus';