From 8d7917e9885ebd547a0f0bdb69e5cb6f0c779fb6 Mon Sep 17 00:00:00 2001 From: Vladimir Potekhin <46284632+vladimirpotekhin@users.noreply.github.com> Date: Tue, 5 Mar 2024 17:38:41 +0300 Subject: [PATCH] fix(kit): `InputDateMulti` fix disableItemHandler (#6946) --- .../input-date-multi/input-date-multi.component.ts | 10 ++++++++-- .../input-date-multi/input-date-multi.template.html | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/projects/kit/components/input-date-multi/input-date-multi.component.ts b/projects/kit/components/input-date-multi/input-date-multi.component.ts index 062b473ed068..4a337e703f31 100644 --- a/projects/kit/components/input-date-multi/input-date-multi.component.ts +++ b/projects/kit/components/input-date-multi/input-date-multi.component.ts @@ -27,6 +27,7 @@ import { tuiIsString, type TuiMapper, TuiMonth, + TuiTypedMapper, } from '@taiga-ui/cdk'; import { TUI_DEFAULT_MARKER_HANDLER, @@ -239,6 +240,11 @@ export class TuiInputDateMultiComponent > = handler => stringifiable => tuiIsString(stringifiable) || handler(stringifiable.item); + protected readonly valueMapper: TuiTypedMapper< + [readonly TuiDay[]], + ReadonlyArray> + > = value => value.map(item => new TuiStringifiableItem(item, item => String(item))); + protected onEnter(search: string): void { if (!this.tagValidator(search)) { return; @@ -256,14 +262,14 @@ export class TuiInputDateMultiComponent this.done(); } - protected onValueChange(value: readonly TuiDay[]): void { + protected onValueChange(value: ReadonlyArray>): void { this.control?.updateValueAndValidity({emitEvent: false}); if (!value.length) { this.onOpenChange(true); } - this.value = value; + this.value = value.map(({item}) => item); } protected onDayClick(value: TuiDay): void { diff --git a/projects/kit/components/input-date-multi/input-date-multi.template.html b/projects/kit/components/input-date-multi/input-date-multi.template.html index a48cc62e6eaa..3f986a35ab14 100644 --- a/projects/kit/components/input-date-multi/input-date-multi.template.html +++ b/projects/kit/components/input-date-multi/input-date-multi.template.html @@ -14,7 +14,7 @@ [inputHidden]="inputHidden" [maskito]="maskitoOptions" [nativeId]="nativeId" - [ngModel]="value" + [ngModel]="value | tuiMapper: valueMapper" [placeholder]="placeholder" [pseudoFocus]="pseudoFocus" [pseudoHover]="pseudoHover" @@ -22,7 +22,7 @@ [readOnly]="readOnly" [removable]="!nativeDropdownMode" [rows]="rows" - [tagValidator]="tagValidator" + [tagValidator]="tagValidator | tuiMapper: disabledItemHandlerWrapper" [tuiTextfieldFiller]="(filler$ | async) || ''" [tuiTextfieldIcon]="calendarIcon && iconContent" (keydown.enter)="onEnter(inputTag.search || '')"