From 1f8947d47d483c6e1d3ad355eaf61321762b6acb Mon Sep 17 00:00:00 2001 From: splincode Date: Wed, 11 Dec 2024 12:26:55 +0300 Subject: [PATCH] fix(core): `tuiLabel` should use fallback' id from projected textfield --- projects/core/components/label/label.directive.ts | 11 +++++++++-- .../modules/components/textarea/examples/3/index.html | 4 +++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/projects/core/components/label/label.directive.ts b/projects/core/components/label/label.directive.ts index bec677011d69..72bc27455f81 100644 --- a/projects/core/components/label/label.directive.ts +++ b/projects/core/components/label/label.directive.ts @@ -1,3 +1,4 @@ +import type {AfterViewInit} from '@angular/core'; import { ChangeDetectionStrategy, Component, @@ -28,11 +29,11 @@ class TuiLabelStyles {} standalone: true, selector: 'label[tuiLabel]', host: { - '[attr.for]': 'el.htmlFor || parent?.id', + '[attr.for]': 'el.htmlFor || parent?.id || projectionId', '[attr.data-orientation]': 'textfield ? "vertical" : "horizontal"', }, }) -export class TuiLabel { +export class TuiLabel implements AfterViewInit { @ContentChild(forwardRef(() => TUI_DATA_LIST_HOST)) protected readonly textfield?: unknown; @@ -42,4 +43,10 @@ export class TuiLabel { forwardRef(() => TUI_DATA_LIST_HOST), {optional: true}, ); + + protected projectionId?: string; + + public ngAfterViewInit(): void { + this.projectionId = this.el.querySelector('[tuiTextfieldLegacy]')?.id; + } } diff --git a/projects/demo/src/modules/components/textarea/examples/3/index.html b/projects/demo/src/modules/components/textarea/examples/3/index.html index 21d1dd56c3ef..6899df95e2f2 100644 --- a/projects/demo/src/modules/components/textarea/examples/3/index.html +++ b/projects/demo/src/modules/components/textarea/examples/3/index.html @@ -9,6 +9,8 @@ + > + +