From 26b376e43e18e9941f44d4d0714696b863250507 Mon Sep 17 00:00:00 2001 From: Dmitriy Stepanenko <33101123+dmitry-stepanenko@users.noreply.github.com> Date: Thu, 29 Feb 2024 14:30:40 +0200 Subject: [PATCH] feat(material/tooltip): be able to customize the longpress delay (#27512) --- src/material/tooltip/tooltip.ts | 16 +++++++++------- tools/public_api_guard/material/tooltip.md | 1 + 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/material/tooltip/tooltip.ts b/src/material/tooltip/tooltip.ts index 597b96299d8c..9cc929e55490 100644 --- a/src/material/tooltip/tooltip.ts +++ b/src/material/tooltip/tooltip.ts @@ -128,6 +128,9 @@ export interface MatTooltipDefaultOptions { /** Default delay when hiding the tooltip on a touch device. */ touchendHideDelay: number; + /** Time between the user putting the pointer on a tooltip trigger and the long press event being fired on a touch device. */ + touchLongPressShowDelay?: number; + /** Default touch gesture handling for tooltips. */ touchGestures?: TooltipTouchGestures; @@ -156,12 +159,6 @@ const PANEL_CLASS = 'tooltip-panel'; /** Options used to bind passive event listeners. */ const passiveListenerOptions = normalizePassiveListenerOptions({passive: true}); -/** - * Time between the user putting the pointer on a tooltip - * trigger and the long press event being fired. - */ -const LONGPRESS_DELAY = 500; - // These constants were taken from MDC's `numbers` object. We can't import them from MDC, // because they have some top-level references to `window` which break during SSR. const MIN_VIEWPORT_TOOLTIP_THRESHOLD = 8; @@ -787,7 +784,12 @@ export class MatTooltip implements OnDestroy, AfterViewInit { // because it can prevent click events from firing on the element. this._setupPointerExitEventsIfNeeded(); clearTimeout(this._touchstartTimeout); - this._touchstartTimeout = setTimeout(() => this.show(undefined, origin), LONGPRESS_DELAY); + + const DEFAULT_LONGPRESS_DELAY = 500; + this._touchstartTimeout = setTimeout( + () => this.show(undefined, origin), + this._defaultOptions.touchLongPressShowDelay ?? DEFAULT_LONGPRESS_DELAY, + ); }, ]); } diff --git a/tools/public_api_guard/material/tooltip.md b/tools/public_api_guard/material/tooltip.md index bade23b1c565..f41b4073a7d8 100644 --- a/tools/public_api_guard/material/tooltip.md +++ b/tools/public_api_guard/material/tooltip.md @@ -125,6 +125,7 @@ export interface MatTooltipDefaultOptions { showDelay: number; touchendHideDelay: number; touchGestures?: TooltipTouchGestures; + touchLongPressShowDelay?: number; } // @public (undocumented)