From a60ada0daf8568c2a1008053a5f190e8fe27244b Mon Sep 17 00:00:00 2001 From: Svyatoslav Zaytsev Date: Thu, 15 Feb 2024 20:13:13 +0600 Subject: [PATCH] feat(experimental): add autoClose when another element is focused --- .../experimental/swipe-action/examples/5/index.less | 8 -------- .../swipe-action/swipe-actions-auto-close.directive.ts | 9 +++++---- .../components/swipe-action/swipe-actions.style.less | 4 ++++ 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/projects/demo/src/modules/experimental/swipe-action/examples/5/index.less b/projects/demo/src/modules/experimental/swipe-action/examples/5/index.less index 15f9b01403b8..00f4c750612d 100644 --- a/projects/demo/src/modules/experimental/swipe-action/examples/5/index.less +++ b/projects/demo/src/modules/experimental/swipe-action/examples/5/index.less @@ -5,10 +5,6 @@ width: 20rem; } -tui-swipe-actions { - overflow: hidden; -} - .fallback { .center-top(); right: 2rem; @@ -26,8 +22,4 @@ button[tuiSwipeAction] { .fallback { display: none; } - - tui-swipe-actions { - overflow-x: scroll; - } } diff --git a/projects/experimental/components/swipe-action/swipe-actions-auto-close.directive.ts b/projects/experimental/components/swipe-action/swipe-actions-auto-close.directive.ts index cf1a38820baf..aca31acafa16 100644 --- a/projects/experimental/components/swipe-action/swipe-actions-auto-close.directive.ts +++ b/projects/experimental/components/swipe-action/swipe-actions-auto-close.directive.ts @@ -4,19 +4,20 @@ import {tuiGetActualTarget} from '@taiga-ui/cdk'; @Directive({ selector: 'tui-swipe-actions[autoClose]', host: { - '(document:pointerdown.silent)': 'onPointer($event)', + '(document:pointerdown.silent)': 'handleEvent($event)', + '(document:focusin.silent)': 'handleEvent($event)', }, }) export class TuiSwipeActionsAutoCloseDirective { @Input() - autoClose = true; + autoClose: boolean | string = true; constructor(@Inject(ElementRef) private readonly el: ElementRef) {} - onPointer(event: PointerEvent): void { + handleEvent(event: Event): void { const target = tuiGetActualTarget(event); - if (this.autoClose && !this.el.nativeElement.contains(target)) { + if (this.autoClose !== false && !this.el.nativeElement.contains(target)) { this.close(); } } diff --git a/projects/experimental/components/swipe-action/swipe-actions.style.less b/projects/experimental/components/swipe-action/swipe-actions.style.less index 861a99902c2c..c7f15fc6e280 100644 --- a/projects/experimental/components/swipe-action/swipe-actions.style.less +++ b/projects/experimental/components/swipe-action/swipe-actions.style.less @@ -37,6 +37,10 @@ ::ng-deep & > * { .loop(6); } + + @media (hover: hover) and (pointer: fine) { + display: none; + } } .loop (@i) when (@i > 1) {