Skip to content

Commit

Permalink
fix(kit): Tree fix control chevron rotation programmatically (#7476)
Browse files Browse the repository at this point in the history
  • Loading branch information
0x083 committed May 20, 2024
1 parent 50b3d5e commit ba90b0d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import {
ChangeDetectionStrategy,
Component,
DoCheck,
forwardRef,
HostBinding,
Inject,
} from '@angular/core';
import {TUI_COMMON_ICONS, TuiCommonIcons} from '@taiga-ui/core';
import {POLYMORPHEUS_CONTEXT} from '@tinkoff/ng-polymorpheus';
import {Subject} from 'rxjs';
import {distinctUntilChanged, map, startWith} from 'rxjs/operators';

import {TUI_DEFAULT_TREE_CONTROLLER} from '../../misc/tree.constants';
import type {TuiTreeController, TuiTreeItemContext} from '../../misc/tree.interfaces';
Expand All @@ -18,7 +21,15 @@ import {TUI_TREE_CONTROLLER} from '../../misc/tree.tokens';
styleUrls: ['./tree-item-content.style.less'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class TuiTreeItemContentComponent {
export class TuiTreeItemContentComponent implements DoCheck {
private readonly change$ = new Subject<void>();

readonly expanded$ = this.change$.pipe(
startWith(null),
map(() => this.isExpanded),
distinctUntilChanged(),
);

constructor(
@Inject(TUI_COMMON_ICONS) readonly icons: TuiCommonIcons,
@Inject(POLYMORPHEUS_CONTEXT) readonly context: TuiTreeItemContext,
Expand All @@ -41,4 +52,8 @@ export class TuiTreeItemContentComponent {
onClick(): void {
this.controller.toggle(this.context.$implicit);
}

ngDoCheck(): void {
this.change$.next();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
tuiIconButton
type="button"
class="t-button"
[class.t-button_expanded]="isExpanded"
[class.t-button_expanded]="expanded$ | async"
[icon]="icons.more"
(click)="onClick()"
></button>
Expand Down

0 comments on commit ba90b0d

Please sign in to comment.