Skip to content

Commit 26b376e

Browse files
feat(material/tooltip): be able to customize the longpress delay (#27512)
1 parent f6e8584 commit 26b376e

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/material/tooltip/tooltip.ts

+9-7
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ export interface MatTooltipDefaultOptions {
128128
/** Default delay when hiding the tooltip on a touch device. */
129129
touchendHideDelay: number;
130130

131+
/** Time between the user putting the pointer on a tooltip trigger and the long press event being fired on a touch device. */
132+
touchLongPressShowDelay?: number;
133+
131134
/** Default touch gesture handling for tooltips. */
132135
touchGestures?: TooltipTouchGestures;
133136

@@ -156,12 +159,6 @@ const PANEL_CLASS = 'tooltip-panel';
156159
/** Options used to bind passive event listeners. */
157160
const passiveListenerOptions = normalizePassiveListenerOptions({passive: true});
158161

159-
/**
160-
* Time between the user putting the pointer on a tooltip
161-
* trigger and the long press event being fired.
162-
*/
163-
const LONGPRESS_DELAY = 500;
164-
165162
// These constants were taken from MDC's `numbers` object. We can't import them from MDC,
166163
// because they have some top-level references to `window` which break during SSR.
167164
const MIN_VIEWPORT_TOOLTIP_THRESHOLD = 8;
@@ -787,7 +784,12 @@ export class MatTooltip implements OnDestroy, AfterViewInit {
787784
// because it can prevent click events from firing on the element.
788785
this._setupPointerExitEventsIfNeeded();
789786
clearTimeout(this._touchstartTimeout);
790-
this._touchstartTimeout = setTimeout(() => this.show(undefined, origin), LONGPRESS_DELAY);
787+
788+
const DEFAULT_LONGPRESS_DELAY = 500;
789+
this._touchstartTimeout = setTimeout(
790+
() => this.show(undefined, origin),
791+
this._defaultOptions.touchLongPressShowDelay ?? DEFAULT_LONGPRESS_DELAY,
792+
);
791793
},
792794
]);
793795
}

tools/public_api_guard/material/tooltip.md

+1
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ export interface MatTooltipDefaultOptions {
125125
showDelay: number;
126126
touchendHideDelay: number;
127127
touchGestures?: TooltipTouchGestures;
128+
touchLongPressShowDelay?: number;
128129
}
129130

130131
// @public (undocumented)

0 commit comments

Comments
 (0)