Skip to content

feat(material/tooltip): be able to customize the longpress delay #27512

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions src/material/tooltip/tooltip.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export interface MatTooltipDefaultOptions {
showDelay: number;
touchendHideDelay: number;
touchGestures?: TooltipTouchGestures;
touchLongPressShowDelay?: number;
}

// @public (undocumented)
Expand Down