Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): enable TuiHint hover when TuiHintManual is null #9955

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions projects/core/directives/hint/hint-manual.directive.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type {OnChanges} from '@angular/core';
import {Directive, inject, Input} from '@angular/core';
import {tuiAsDriver, TuiDriver} from '@taiga-ui/core/classes';
import type {Subscriber} from 'rxjs';
import {BehaviorSubject} from 'rxjs';

import {TuiHintHover} from './hint-hover.directive';
Expand All @@ -12,19 +13,22 @@ import {TuiHintHover} from './hint-hover.directive';
})
export class TuiHintManual extends TuiDriver implements OnChanges {
private readonly hover = inject(TuiHintHover);
private readonly stream$ = new BehaviorSubject(false);
private readonly stream$ = new BehaviorSubject<boolean | null>(false);
splincode marked this conversation as resolved.
Show resolved Hide resolved

@Input()
public tuiHintManual = false;
public tuiHintManual: boolean | null = false;

public readonly type = 'hint';

constructor() {
super((subscriber) => this.stream$.subscribe(subscriber));
super((subscriber: Subscriber<boolean | null>) =>
this.stream$.subscribe(subscriber),
);
this.hover.enabled = false;
}

public ngOnChanges(): void {
this.stream$.next(this.tuiHintManual);
this.hover.enabled = this.tuiHintManual === null;
}
}
11 changes: 10 additions & 1 deletion projects/core/directives/hint/test/hint.directive.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type {TemplateRef} from '@angular/core';
import {ChangeDetectionStrategy, Component} from '@angular/core';
import type {ComponentFixture} from '@angular/core/testing';
import {discardPeriodicTasks, fakeAsync, TestBed, tick} from '@angular/core/testing';
import {TuiHint, TuiRoot} from '@taiga-ui/core';
import {TuiHint, TuiHintManual, TuiRoot} from '@taiga-ui/core';

type Hint = TemplateRef<Record<string, unknown>> | string | null | undefined;

Expand Down Expand Up @@ -95,6 +95,15 @@ describe('Hint', () => {

expect(getTooltip()).toBeNull();
}));

it('enables hover when tuiHintManual is null', () => {
const hintManualDirective = TestBed.inject(TuiHintManual);

hintManualDirective.tuiHintManual = null;
hintManualDirective.ngOnChanges();

expect(hintManualDirective['hover'].enabled).toBeTruthy();
});
});

describe('Hint is not shown', () => {
Expand Down
Loading