Skip to content

Commit

Permalink
fix(legacy): MultiSelect fix pristine and updateOn: blur issues (#9900
Browse files Browse the repository at this point in the history
)
  • Loading branch information
waterplea authored Dec 4, 2024
1 parent b2933f4 commit d70edfb
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 16 deletions.
4 changes: 4 additions & 0 deletions projects/legacy/classes/control.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ export abstract class AbstractTuiControl<T>
@Input()
public pseudoInvalid: boolean | null = null;

// Workaround for legacy control to notify of internal change in case updateOn: 'blur' is used
public readonly update$ = new Subject<void>();

constructor() {
super();

Expand Down Expand Up @@ -89,6 +92,7 @@ export abstract class AbstractTuiControl<T>

public set value(value: T) {
this.updateValue(value);
this.update$.next();
}

public get safeCurrentValue(): T {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Directive, forwardRef, Optional} from '@angular/core';
import {Directive, inject} from '@angular/core';
import {NG_VALUE_ACCESSOR, NgControl} from '@angular/forms';
import {EMPTY_FUNCTION} from '@taiga-ui/cdk/constants';
import {tuiArrayToggle} from '@taiga-ui/cdk/utils/miscellaneous';
Expand All @@ -7,6 +7,7 @@ import {
TUI_DATA_LIST_HOST,
tuiAsOptionContent,
} from '@taiga-ui/core/components/data-list';
import {AbstractTuiControl} from '@taiga-ui/legacy/classes';
import {TuiMultiSelectOptionComponent} from '@taiga-ui/legacy/components/multi-select-option';
import {PolymorpheusComponent} from '@taiga-ui/polymorpheus';

Expand All @@ -23,20 +24,25 @@ export const TUI_MULTI_SELECT_OPTION = new PolymorpheusComponent(
tuiAsOptionContent(TUI_MULTI_SELECT_OPTION),
{
provide: TUI_DATA_LIST_HOST,
deps: [
NgControl,
[new Optional(), forwardRef(() => TuiMultiSelectComponent)],
],
useFactory: <T>(
control: NgControl,
host: TuiDataListHost<T> | null,
): TuiDataListHost<T> =>
host || {
handleOption: (option) =>
control.control?.setValue(
tuiArrayToggle(control.value || [], option),
),
},
useFactory: <T>(): TuiDataListHost<T> => {
const multiSelect = inject(TuiMultiSelectComponent, {optional: true});
const {control} = inject(NgControl);
const host = inject(AbstractTuiControl, {optional: true});

return (
multiSelect || {
handleOption: (option) => {
if (host) {
host.value = tuiArrayToggle(host.value, option);
} else {
control?.setValue(
tuiArrayToggle(control.value || [], option),
);
}
},
}
);
},
},
{
provide: NG_VALUE_ACCESSOR,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,13 @@ textarea:host {
:host-context(tui-text-area._ios) {
padding-left: 0.8125rem; // compensation of unkillable padding in mobile safari
}

:host-context(tui-textarea[data-size='s']),
:host-context(tui-textarea[data-size='m']) {
font: var(--tui-font-text-s);
}

:host-context(tui-textarea[data-size='l']) {
font: var(--tui-font-text-m);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ export class TuiSelectOptionComponent<T> implements OnInit, DoCheck {
protected readonly context =
injectContext<TuiContext<TemplateRef<Record<string, unknown>>>>();

protected readonly selected$ = merge(
protected readonly selected$ = merge<unknown[]>(
this.abstractControl?.update$ || EMPTY,
this.changeDetection$,
this.control.valueChanges || EMPTY,
tuiTypedFromEvent(this.el, 'animationstart'),
Expand Down

0 comments on commit d70edfb

Please sign in to comment.