Skip to content

Commit

Permalink
fix(cdk): Control react to markAsTouched on Angular 18+ (#9330)
Browse files Browse the repository at this point in the history
Co-authored-by: taiga-family-bot <taiga-family-bot@users.noreply.github.com>
  • Loading branch information
waterplea and taiga-family-bot authored Oct 3, 2024
1 parent fef96a9 commit 1b732e8
Show file tree
Hide file tree
Showing 14 changed files with 129 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,12 @@ tui-dropdown-mobile._sheet {
touch-action: inherit;
visibility: inherit;
}

tui-root {
visibility: visible;

.t-root-content {
visibility: hidden;
}
}
}
5 changes: 4 additions & 1 deletion projects/cdk/classes/control.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {tuiProvide, tuiPure} from '@taiga-ui/cdk/utils';
import {
delay,
distinctUntilChanged,
EMPTY,
filter,
map,
merge,
Expand Down Expand Up @@ -71,7 +72,9 @@ export abstract class TuiControl<T> implements ControlValueAccessor {
map(() => this.control.control),
filter(Boolean),
distinctUntilChanged(),
switchMap((c) => merge(c.valueChanges, c.statusChanges)),
switchMap((c) =>
merge(c.valueChanges, c.statusChanges, (c as any).events || EMPTY),
),
takeUntilDestroyed(),
)
.subscribe(() => this.update());
Expand Down
8 changes: 8 additions & 0 deletions projects/core/styles/mixins/mixins.less
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,11 @@
}
}
}

.text-truncate() {
.text-overflow();

flex: 1;
min-inline-size: 0;
max-inline-size: max-content;
}
7 changes: 7 additions & 0 deletions projects/core/styles/mixins/mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,10 @@
}
}
}

@mixin text-truncate() {
@include text-overflow();
flex: 1;
min-inline-size: 0;
max-inline-size: max-content;
}
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<h3>Truncate</h3>
<tui-breadcrumbs>
<ng-container *ngFor="let item of items">
<button
*tuiItem
tuiHintOverflow
tuiLink
type="button"
class="link"
>
{{ item }}
</button>
</ng-container>
</tui-breadcrumbs>
<h3>Fade</h3>
<tui-breadcrumbs>
<ng-container *ngFor="let item of items">
<button
*tuiItem
tuiFade
tuiHintOverflow
tuiLink
type="button"
class="link"
>
{{ item }}
</button>
</ng-container>
</tui-breadcrumbs>
<h3>Scroll</h3>
<tui-breadcrumbs tuiFade>
<ng-container *ngFor="let item of items">
<button
*tuiItem
tuiLink
type="button"
>
{{ item }}
</button>
</ng-container>
</tui-breadcrumbs>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@import '@taiga-ui/core/styles/taiga-ui-local';

:host {
display: block;
max-inline-size: 30rem;
}

[tuiLink]:last-child {
font-weight: bold;
color: var(--tui-text-primary);
}

.link {
.text-truncate();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {NgForOf} from '@angular/common';
import {Component} from '@angular/core';
import {changeDetection} from '@demo/emulate/change-detection';
import {encapsulation} from '@demo/emulate/encapsulation';
import {TuiItem} from '@taiga-ui/cdk';
import {TuiHint, TuiLink} from '@taiga-ui/core';
import {TuiBreadcrumbs, tuiBreadcrumbsOptionsProvider, TuiFade} from '@taiga-ui/kit';

@Component({
standalone: true,
imports: [NgForOf, TuiBreadcrumbs, TuiFade, TuiHint, TuiItem, TuiLink],
templateUrl: './index.html',
styleUrls: ['./index.less'],
encapsulation,
changeDetection,
providers: [tuiBreadcrumbsOptionsProvider({icon: '/'})],
})
export default class Example {
protected readonly items = [
'Short item',
'Very very long item that must overflow',
'Another item',
'One more super long item that is never gonna fit',
];
}
1 change: 1 addition & 0 deletions projects/demo/src/modules/components/breadcrumbs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@ export default class Example {
protected readonly examples = [
{name: 'Basic'},
{name: 'More button', description: 'Plus using DI options'},
{name: 'Overflow', description: 'Different overflow strategies'},
];
}
6 changes: 5 additions & 1 deletion projects/kit/components/breadcrumbs/breadcrumbs.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {EMPTY_QUERY} from '@taiga-ui/cdk/constants';
import {TuiItem} from '@taiga-ui/cdk/directives/item';
import {TuiIcon} from '@taiga-ui/core/components/icon';
import {tuiLinkOptionsProvider} from '@taiga-ui/core/components/link';
import {tuiHintOptionsProvider} from '@taiga-ui/core/directives/hint';

import type {TuiBreadcrumbsOptions} from './breadcrumbs.options';
import {TUI_BREADCRUMBS_OPTIONS} from './breadcrumbs.options';
Expand All @@ -23,7 +24,10 @@ import {TUI_BREADCRUMBS_OPTIONS} from './breadcrumbs.options';
templateUrl: './breadcrumbs.template.html',
styleUrls: ['./breadcrumbs.style.less'],
changeDetection: ChangeDetectionStrategy.OnPush,
providers: [tuiLinkOptionsProvider({appearance: 'icon'})],
providers: [
tuiLinkOptionsProvider({appearance: 'icon'}),
tuiHintOptionsProvider({direction: 'bottom'}),
],
host: {
'[attr.data-size]': 'size',
},
Expand Down
3 changes: 1 addition & 2 deletions projects/kit/components/breadcrumbs/breadcrumbs.style.less
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
block-size: 2.5rem;
white-space: nowrap;
font: var(--tui-font-text-s);
color: var(--tui-text-primary);
color: var(--tui-text-secondary);

&[data-size='l'] {
font: var(--tui-font-text-m);
Expand All @@ -13,6 +13,5 @@

.t-icon {
margin: 0 0.25rem;
opacity: 0.4;
border: 0.25rem solid transparent;
}
13 changes: 8 additions & 5 deletions projects/kit/components/breadcrumbs/breadcrumbs.template.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<ng-container *ngIf="items.changes | async" />
<ng-container *ngFor="let item of items; let last = last">
<ng-container [ngTemplateOutlet]="item" />
<tui-icon
*ngIf="!last"
class="t-icon"
[icon]="options.icon"
/>
<ng-container *ngIf="!last">
<tui-icon
*ngIf="options.icon.length > 1; else char"
class="t-icon"
[icon]="options.icon"
/>
<ng-template #char>&nbsp;{{ options.icon }}&nbsp;</ng-template>
</ng-container>
</ng-container>
7 changes: 6 additions & 1 deletion projects/legacy/classes/control.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {tuiIsPresent, tuiProvide} from '@taiga-ui/cdk/utils/miscellaneous';
import {
delay,
distinctUntilChanged,
EMPTY,
filter,
map,
merge,
Expand Down Expand Up @@ -138,7 +139,11 @@ export abstract class AbstractTuiControl<T>
filter(tuiIsPresent),
distinctUntilChanged(),
switchMap((control) =>
merge(control.valueChanges, control.statusChanges),
merge(
control.valueChanges,
control.statusChanges,
(control as any).events || EMPTY,
),
),
takeUntilDestroyed(this.destroyRef),
)
Expand Down

0 comments on commit 1b732e8

Please sign in to comment.