Skip to content

Commit

Permalink
feat(material/tooltip): be able to customize the longpress delay (#27512
Browse files Browse the repository at this point in the history
)
  • Loading branch information
dmitry-stepanenko committed Feb 29, 2024
1 parent f6e8584 commit 26b376e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/material/tooltip/tooltip.ts
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
);
},
]);
}
Expand Down
1 change: 1 addition & 0 deletions tools/public_api_guard/material/tooltip.md
Expand Up @@ -125,6 +125,7 @@ export interface MatTooltipDefaultOptions {
showDelay: number;
touchendHideDelay: number;
touchGestures?: TooltipTouchGestures;
touchLongPressShowDelay?: number;
}

// @public (undocumented)
Expand Down

0 comments on commit 26b376e

Please sign in to comment.