From d6751cdacf53262e8bdc32485dc61af21b333a32 Mon Sep 17 00:00:00 2001 From: Vladimir Potekhin <46284632+vladimirpotekhin@users.noreply.github.com> Date: Fri, 13 Oct 2023 16:58:42 +0300 Subject: [PATCH] fix(kit): `LineClamp` fix unexpected closing (#5630) --- .../core/directives/hint/hint-hover.directive.ts | 5 +++-- projects/core/directives/hint/hint.component.ts | 5 ++--- projects/core/utils/miscellaneous/index.ts | 1 + projects/core/utils/miscellaneous/is-obscured.ts | 11 +++++++++++ .../cypress/tests/kit/line-clamp/line-clamp.cy.ts | 15 +++++++++++++++ 5 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 projects/core/utils/miscellaneous/is-obscured.ts diff --git a/projects/core/directives/hint/hint-hover.directive.ts b/projects/core/directives/hint/hint-hover.directive.ts index 12ad76d2958c..5b428d622822 100644 --- a/projects/core/directives/hint/hint-hover.directive.ts +++ b/projects/core/directives/hint/hint-hover.directive.ts @@ -1,7 +1,8 @@ /* eslint-disable rxjs/no-unsafe-takeuntil */ import {Directive, ElementRef, Inject, Input} from '@angular/core'; -import {tuiGetElementObscures, TuiHoveredService} from '@taiga-ui/cdk'; +import {TuiHoveredService} from '@taiga-ui/cdk'; import {tuiAsDriver, TuiDriver} from '@taiga-ui/core/abstract'; +import {tuiIsObscured} from '@taiga-ui/core/utils'; import {merge, Observable, of, Subject} from 'rxjs'; import {delay, filter, map, repeat, switchMap, takeUntil, tap} from 'rxjs/operators'; @@ -30,7 +31,7 @@ export class TuiHintHoverDirective extends TuiDriver { ), ).pipe( filter(() => this.enabled), - map(value => value && !tuiGetElementObscures(this.el.nativeElement)?.length), + map(value => value && !tuiIsObscured(this.el.nativeElement)), tap(visible => { this.visible = visible; }), diff --git a/projects/core/directives/hint/hint.component.ts b/projects/core/directives/hint/hint.component.ts index 946aba107f55..3aace9400ba3 100644 --- a/projects/core/directives/hint/hint.component.ts +++ b/projects/core/directives/hint/hint.component.ts @@ -14,7 +14,6 @@ import { tuiClamp, TuiContextWithImplicit, TuiDestroyService, - tuiGetElementObscures, TuiHoveredService, tuiPure, tuiPx, @@ -30,11 +29,11 @@ import {TuiPortalItem} from '@taiga-ui/core/interfaces'; import {TuiPositionService, TuiVisualViewportService} from '@taiga-ui/core/services'; import {TUI_ANIMATION_OPTIONS, TUI_VIEWPORT} from '@taiga-ui/core/tokens'; import {TuiPoint} from '@taiga-ui/core/types'; +import {tuiIsObscured} from '@taiga-ui/core/utils'; import {POLYMORPHEUS_CONTEXT, PolymorpheusContent} from '@tinkoff/ng-polymorpheus'; import {Observable} from 'rxjs'; import {map, takeUntil} from 'rxjs/operators'; -// eslint-disable-next-line import/no-cycle import {TuiHintDirective} from './hint.directive'; import {TuiHintHoverDirective} from './hint-hover.directive'; import {TuiHintPointerDirective} from './hint-pointer.directive'; @@ -111,7 +110,7 @@ export class TuiHintComponent { if ( (!this.el.nativeElement.contains(target) && !this.hover.el.nativeElement.contains(target)) || - tuiGetElementObscures(this.hover.el.nativeElement)?.length + tuiIsObscured(this.hover.el.nativeElement) ) { this.hover.toggle(false); } diff --git a/projects/core/utils/miscellaneous/index.ts b/projects/core/utils/miscellaneous/index.ts index f948d6127c27..d644ce703393 100644 --- a/projects/core/utils/miscellaneous/index.ts +++ b/projects/core/utils/miscellaneous/index.ts @@ -1,6 +1,7 @@ export * from './get-border'; export * from './icons-path-factory'; export * from './is-editing-key'; +export * from './is-obscured'; export * from './is-presumed-html-string'; export * from './override-options'; export * from './size-bigger'; diff --git a/projects/core/utils/miscellaneous/is-obscured.ts b/projects/core/utils/miscellaneous/is-obscured.ts new file mode 100644 index 000000000000..b54b144cb213 --- /dev/null +++ b/projects/core/utils/miscellaneous/is-obscured.ts @@ -0,0 +1,11 @@ +import {tuiGetElementObscures} from '@taiga-ui/cdk'; + +/** + * @internal + */ +export function tuiIsObscured( + el: HTMLElement, + exceptSelector = `tui-hints-host`, +): boolean { + return !!tuiGetElementObscures(el)?.some(el => !el.closest(exceptSelector)); +} diff --git a/projects/demo-cypress/cypress/tests/kit/line-clamp/line-clamp.cy.ts b/projects/demo-cypress/cypress/tests/kit/line-clamp/line-clamp.cy.ts index d55b81ecfb00..36fe36909e41 100644 --- a/projects/demo-cypress/cypress/tests/kit/line-clamp/line-clamp.cy.ts +++ b/projects/demo-cypress/cypress/tests/kit/line-clamp/line-clamp.cy.ts @@ -64,4 +64,19 @@ describe(`LineClamp`, () => { }); } }); + + describe(`Hovered`, () => { + const basicText = `Lorem ipsum Gaudeamus igiturCarpe diem Veni, vidi, vici`; + + it(`linesLimit=2 hovered`, () => { + cy.tuiVisit(`/components/line-clamp/API?content=${basicText}&linesLimit=2`); + + cy.get(`#demo-content tui-line-clamp`).realHover(); + + cy.get(`tui-line-clamp-box`) + .should(`be.visible`) + .tuiWaitBeforeScreenshot() + .matchImageSnapshot(`02-[linesLimit=2]-basicText-hover`); + }); + }); });