Skip to content

Commit ef07a6b

Browse files
feat(material/tooltip): be able to customize the longpress delay
1 parent 0c4f947 commit ef07a6b

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/material/tooltip/tooltip.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ export interface MatTooltipDefaultOptions {
121121
/** Default delay when hiding the tooltip on a touch device. */
122122
touchendHideDelay: number;
123123

124+
/** Time between the user putting the pointer on a tooltip trigger and the long press event being fired on a touch device. */
125+
touchLongPressShowDelay?: number;
126+
124127
/** Default touch gesture handling for tooltips. */
125128
touchGestures?: TooltipTouchGestures;
126129

@@ -149,12 +152,6 @@ const PANEL_CLASS = 'tooltip-panel';
149152
/** Options used to bind passive event listeners. */
150153
const passiveListenerOptions = normalizePassiveListenerOptions({passive: true});
151154

152-
/**
153-
* Time between the user putting the pointer on a tooltip
154-
* trigger and the long press event being fired.
155-
*/
156-
const LONGPRESS_DELAY = 500;
157-
158155
// These constants were taken from MDC's `numbers` object. We can't import them from MDC,
159156
// because they have some top-level references to `window` which break during SSR.
160157
const MIN_VIEWPORT_TOOLTIP_THRESHOLD = 8;
@@ -751,7 +748,12 @@ export abstract class _MatTooltipBase<T extends _TooltipComponentBase>
751748
// because it can prevent click events from firing on the element.
752749
this._setupPointerExitEventsIfNeeded();
753750
clearTimeout(this._touchstartTimeout);
754-
this._touchstartTimeout = setTimeout(() => this.show(undefined, origin), LONGPRESS_DELAY);
751+
752+
const DEFAULT_LONGPRESS_DELAY = 500;
753+
this._touchstartTimeout = setTimeout(
754+
() => this.show(undefined, origin),
755+
this._defaultOptions.touchLongPressShowDelay ?? DEFAULT_LONGPRESS_DELAY,
756+
);
755757
},
756758
]);
757759
}

0 commit comments

Comments
 (0)