[6a3a178] | 1 | /**
|
---|
| 2 | * @license
|
---|
| 3 | * Copyright Google LLC All Rights Reserved.
|
---|
| 4 | *
|
---|
| 5 | * Use of this source code is governed by an MIT-style license that can be
|
---|
| 6 | * found in the LICENSE file at https://angular.io/license
|
---|
| 7 | */
|
---|
| 8 | import { AnimationEvent } from '@angular/animations';
|
---|
| 9 | import { AriaDescriber, FocusMonitor } from '@angular/cdk/a11y';
|
---|
| 10 | import { Directionality } from '@angular/cdk/bidi';
|
---|
| 11 | import { BooleanInput, NumberInput } from '@angular/cdk/coercion';
|
---|
| 12 | import { BreakpointObserver, BreakpointState } from '@angular/cdk/layout';
|
---|
| 13 | import { ConnectedPosition, OriginConnectionPosition, Overlay, OverlayConnectionPosition, OverlayRef, ScrollStrategy } from '@angular/cdk/overlay';
|
---|
| 14 | import { Platform } from '@angular/cdk/platform';
|
---|
| 15 | import { ComponentType } from '@angular/cdk/portal';
|
---|
| 16 | import { ScrollDispatcher } from '@angular/cdk/scrolling';
|
---|
| 17 | import { ChangeDetectorRef, ElementRef, InjectionToken, NgZone, OnDestroy, ViewContainerRef, AfterViewInit } from '@angular/core';
|
---|
| 18 | import { Observable } from 'rxjs';
|
---|
| 19 | /** Possible positions for a tooltip. */
|
---|
| 20 | export declare type TooltipPosition = 'left' | 'right' | 'above' | 'below' | 'before' | 'after';
|
---|
| 21 | /**
|
---|
| 22 | * Options for how the tooltip trigger should handle touch gestures.
|
---|
| 23 | * See `MatTooltip.touchGestures` for more information.
|
---|
| 24 | */
|
---|
| 25 | export declare type TooltipTouchGestures = 'auto' | 'on' | 'off';
|
---|
| 26 | /** Possible visibility states of a tooltip. */
|
---|
| 27 | export declare type TooltipVisibility = 'initial' | 'visible' | 'hidden';
|
---|
| 28 | /** Time in ms to throttle repositioning after scroll events. */
|
---|
| 29 | export declare const SCROLL_THROTTLE_MS = 20;
|
---|
| 30 | /**
|
---|
| 31 | * CSS class that will be attached to the overlay panel.
|
---|
| 32 | * @deprecated
|
---|
| 33 | * @breaking-change 13.0.0 remove this variable
|
---|
| 34 | */
|
---|
| 35 | export declare const TOOLTIP_PANEL_CLASS = "mat-tooltip-panel";
|
---|
| 36 | /**
|
---|
| 37 | * Creates an error to be thrown if the user supplied an invalid tooltip position.
|
---|
| 38 | * @docs-private
|
---|
| 39 | */
|
---|
| 40 | export declare function getMatTooltipInvalidPositionError(position: string): Error;
|
---|
| 41 | /** Injection token that determines the scroll handling while a tooltip is visible. */
|
---|
| 42 | export declare const MAT_TOOLTIP_SCROLL_STRATEGY: InjectionToken<() => ScrollStrategy>;
|
---|
| 43 | /** @docs-private */
|
---|
| 44 | export declare function MAT_TOOLTIP_SCROLL_STRATEGY_FACTORY(overlay: Overlay): () => ScrollStrategy;
|
---|
| 45 | /** @docs-private */
|
---|
| 46 | export declare const MAT_TOOLTIP_SCROLL_STRATEGY_FACTORY_PROVIDER: {
|
---|
| 47 | provide: InjectionToken<() => ScrollStrategy>;
|
---|
| 48 | deps: (typeof Overlay)[];
|
---|
| 49 | useFactory: typeof MAT_TOOLTIP_SCROLL_STRATEGY_FACTORY;
|
---|
| 50 | };
|
---|
| 51 | /** Default `matTooltip` options that can be overridden. */
|
---|
| 52 | export interface MatTooltipDefaultOptions {
|
---|
| 53 | showDelay: number;
|
---|
| 54 | hideDelay: number;
|
---|
| 55 | touchendHideDelay: number;
|
---|
| 56 | touchGestures?: TooltipTouchGestures;
|
---|
| 57 | position?: TooltipPosition;
|
---|
| 58 | }
|
---|
| 59 | /** Injection token to be used to override the default options for `matTooltip`. */
|
---|
| 60 | export declare const MAT_TOOLTIP_DEFAULT_OPTIONS: InjectionToken<MatTooltipDefaultOptions>;
|
---|
| 61 | /** @docs-private */
|
---|
| 62 | export declare function MAT_TOOLTIP_DEFAULT_OPTIONS_FACTORY(): MatTooltipDefaultOptions;
|
---|
| 63 | export declare abstract class _MatTooltipBase<T extends _TooltipComponentBase> implements OnDestroy, AfterViewInit {
|
---|
| 64 | private _overlay;
|
---|
| 65 | private _elementRef;
|
---|
| 66 | private _scrollDispatcher;
|
---|
| 67 | private _viewContainerRef;
|
---|
| 68 | private _ngZone;
|
---|
| 69 | private _platform;
|
---|
| 70 | private _ariaDescriber;
|
---|
| 71 | private _focusMonitor;
|
---|
| 72 | protected _dir: Directionality;
|
---|
| 73 | private _defaultOptions;
|
---|
| 74 | _overlayRef: OverlayRef | null;
|
---|
| 75 | _tooltipInstance: T | null;
|
---|
| 76 | private _portal;
|
---|
| 77 | private _position;
|
---|
| 78 | private _disabled;
|
---|
| 79 | private _tooltipClass;
|
---|
| 80 | private _scrollStrategy;
|
---|
| 81 | private _viewInitialized;
|
---|
| 82 | private _pointerExitEventsInitialized;
|
---|
| 83 | protected abstract readonly _tooltipComponent: ComponentType<T>;
|
---|
| 84 | protected _viewportMargin: number;
|
---|
| 85 | private _currentPosition;
|
---|
| 86 | protected readonly _cssClassPrefix: string;
|
---|
| 87 | /** Allows the user to define the position of the tooltip relative to the parent element */
|
---|
| 88 | get position(): TooltipPosition;
|
---|
| 89 | set position(value: TooltipPosition);
|
---|
| 90 | /** Disables the display of the tooltip. */
|
---|
| 91 | get disabled(): boolean;
|
---|
| 92 | set disabled(value: boolean);
|
---|
| 93 | /** The default delay in ms before showing the tooltip after show is called */
|
---|
| 94 | showDelay: number;
|
---|
| 95 | /** The default delay in ms before hiding the tooltip after hide is called */
|
---|
| 96 | hideDelay: number;
|
---|
| 97 | /**
|
---|
| 98 | * How touch gestures should be handled by the tooltip. On touch devices the tooltip directive
|
---|
| 99 | * uses a long press gesture to show and hide, however it can conflict with the native browser
|
---|
| 100 | * gestures. To work around the conflict, Angular Material disables native gestures on the
|
---|
| 101 | * trigger, but that might not be desirable on particular elements (e.g. inputs and draggable
|
---|
| 102 | * elements). The different values for this option configure the touch event handling as follows:
|
---|
| 103 | * - `auto` - Enables touch gestures for all elements, but tries to avoid conflicts with native
|
---|
| 104 | * browser gestures on particular elements. In particular, it allows text selection on inputs
|
---|
| 105 | * and textareas, and preserves the native browser dragging on elements marked as `draggable`.
|
---|
| 106 | * - `on` - Enables touch gestures for all elements and disables native
|
---|
| 107 | * browser gestures with no exceptions.
|
---|
| 108 | * - `off` - Disables touch gestures. Note that this will prevent the tooltip from
|
---|
| 109 | * showing on touch devices.
|
---|
| 110 | */
|
---|
| 111 | touchGestures: TooltipTouchGestures;
|
---|
| 112 | /** The message to be displayed in the tooltip */
|
---|
| 113 | get message(): string;
|
---|
| 114 | set message(value: string);
|
---|
| 115 | private _message;
|
---|
| 116 | /** Classes to be passed to the tooltip. Supports the same syntax as `ngClass`. */
|
---|
| 117 | get tooltipClass(): string | string[] | Set<string> | {
|
---|
| 118 | [key: string]: any;
|
---|
| 119 | };
|
---|
| 120 | set tooltipClass(value: string | string[] | Set<string> | {
|
---|
| 121 | [key: string]: any;
|
---|
| 122 | });
|
---|
| 123 | /** Manually-bound passive event listeners. */
|
---|
| 124 | private readonly _passiveListeners;
|
---|
| 125 | /** Reference to the current document. */
|
---|
| 126 | private _document;
|
---|
| 127 | /** Timer started at the last `touchstart` event. */
|
---|
| 128 | private _touchstartTimeout;
|
---|
| 129 | /** Emits when the component is destroyed. */
|
---|
| 130 | private readonly _destroyed;
|
---|
| 131 | constructor(_overlay: Overlay, _elementRef: ElementRef<HTMLElement>, _scrollDispatcher: ScrollDispatcher, _viewContainerRef: ViewContainerRef, _ngZone: NgZone, _platform: Platform, _ariaDescriber: AriaDescriber, _focusMonitor: FocusMonitor, scrollStrategy: any, _dir: Directionality, _defaultOptions: MatTooltipDefaultOptions, _document: any);
|
---|
| 132 | ngAfterViewInit(): void;
|
---|
| 133 | /**
|
---|
| 134 | * Dispose the tooltip when destroyed.
|
---|
| 135 | */
|
---|
| 136 | ngOnDestroy(): void;
|
---|
| 137 | /** Shows the tooltip after the delay in ms, defaults to tooltip-delay-show or 0ms if no input */
|
---|
| 138 | show(delay?: number): void;
|
---|
| 139 | /** Hides the tooltip after the delay in ms, defaults to tooltip-delay-hide or 0ms if no input */
|
---|
| 140 | hide(delay?: number): void;
|
---|
| 141 | /** Shows/hides the tooltip */
|
---|
| 142 | toggle(): void;
|
---|
| 143 | /** Returns true if the tooltip is currently visible to the user */
|
---|
| 144 | _isTooltipVisible(): boolean;
|
---|
| 145 | /**
|
---|
| 146 | * Handles the keydown events on the host element.
|
---|
| 147 | * Needs to be an arrow function so that we can use it in addEventListener.
|
---|
| 148 | */
|
---|
| 149 | private _handleKeydown;
|
---|
| 150 | /** Create the overlay config and position strategy */
|
---|
| 151 | private _createOverlay;
|
---|
| 152 | /** Detaches the currently-attached tooltip. */
|
---|
| 153 | private _detach;
|
---|
| 154 | /** Updates the position of the current tooltip. */
|
---|
| 155 | private _updatePosition;
|
---|
| 156 | /** Adds the configured offset to a position. Used as a hook for child classes. */
|
---|
| 157 | protected _addOffset(position: ConnectedPosition): ConnectedPosition;
|
---|
| 158 | /**
|
---|
| 159 | * Returns the origin position and a fallback position based on the user's position preference.
|
---|
| 160 | * The fallback position is the inverse of the origin (e.g. `'below' -> 'above'`).
|
---|
| 161 | */
|
---|
| 162 | _getOrigin(): {
|
---|
| 163 | main: OriginConnectionPosition;
|
---|
| 164 | fallback: OriginConnectionPosition;
|
---|
| 165 | };
|
---|
| 166 | /** Returns the overlay position and a fallback position based on the user's preference */
|
---|
| 167 | _getOverlayPosition(): {
|
---|
| 168 | main: OverlayConnectionPosition;
|
---|
| 169 | fallback: OverlayConnectionPosition;
|
---|
| 170 | };
|
---|
| 171 | /** Updates the tooltip message and repositions the overlay according to the new message length */
|
---|
| 172 | private _updateTooltipMessage;
|
---|
| 173 | /** Updates the tooltip class */
|
---|
| 174 | private _setTooltipClass;
|
---|
| 175 | /** Inverts an overlay position. */
|
---|
| 176 | private _invertPosition;
|
---|
| 177 | /** Updates the class on the overlay panel based on the current position of the tooltip. */
|
---|
| 178 | private _updateCurrentPositionClass;
|
---|
| 179 | /** Binds the pointer events to the tooltip trigger. */
|
---|
| 180 | private _setupPointerEnterEventsIfNeeded;
|
---|
| 181 | private _setupPointerExitEventsIfNeeded;
|
---|
| 182 | private _addListeners;
|
---|
| 183 | private _platformSupportsMouseEvents;
|
---|
| 184 | /** Listener for the `wheel` event on the element. */
|
---|
| 185 | private _wheelListener;
|
---|
| 186 | /** Disables the native browser gestures, based on how the tooltip has been configured. */
|
---|
| 187 | private _disableNativeGesturesIfNecessary;
|
---|
| 188 | static ngAcceptInputType_disabled: BooleanInput;
|
---|
| 189 | static ngAcceptInputType_hideDelay: NumberInput;
|
---|
| 190 | static ngAcceptInputType_showDelay: NumberInput;
|
---|
| 191 | }
|
---|
| 192 | /**
|
---|
| 193 | * Directive that attaches a material design tooltip to the host element. Animates the showing and
|
---|
| 194 | * hiding of a tooltip provided position (defaults to below the element).
|
---|
| 195 | *
|
---|
| 196 | * https://material.io/design/components/tooltips.html
|
---|
| 197 | */
|
---|
| 198 | export declare class MatTooltip extends _MatTooltipBase<TooltipComponent> {
|
---|
| 199 | protected readonly _tooltipComponent: typeof TooltipComponent;
|
---|
| 200 | constructor(overlay: Overlay, elementRef: ElementRef<HTMLElement>, scrollDispatcher: ScrollDispatcher, viewContainerRef: ViewContainerRef, ngZone: NgZone, platform: Platform, ariaDescriber: AriaDescriber, focusMonitor: FocusMonitor, scrollStrategy: any, dir: Directionality, defaultOptions: MatTooltipDefaultOptions, _document: any);
|
---|
| 201 | }
|
---|
| 202 | export declare abstract class _TooltipComponentBase implements OnDestroy {
|
---|
| 203 | private _changeDetectorRef;
|
---|
| 204 | /** Message to display in the tooltip */
|
---|
| 205 | message: string;
|
---|
| 206 | /** Classes to be added to the tooltip. Supports the same syntax as `ngClass`. */
|
---|
| 207 | tooltipClass: string | string[] | Set<string> | {
|
---|
| 208 | [key: string]: any;
|
---|
| 209 | };
|
---|
| 210 | /** The timeout ID of any current timer set to show the tooltip */
|
---|
| 211 | _showTimeoutId: any;
|
---|
| 212 | /** The timeout ID of any current timer set to hide the tooltip */
|
---|
| 213 | _hideTimeoutId: any;
|
---|
| 214 | /** Property watched by the animation framework to show or hide the tooltip */
|
---|
| 215 | _visibility: TooltipVisibility;
|
---|
| 216 | /** Whether interactions on the page should close the tooltip */
|
---|
| 217 | private _closeOnInteraction;
|
---|
| 218 | /** Subject for notifying that the tooltip has been hidden from the view */
|
---|
| 219 | private readonly _onHide;
|
---|
| 220 | constructor(_changeDetectorRef: ChangeDetectorRef);
|
---|
| 221 | /**
|
---|
| 222 | * Shows the tooltip with an animation originating from the provided origin
|
---|
| 223 | * @param delay Amount of milliseconds to the delay showing the tooltip.
|
---|
| 224 | */
|
---|
| 225 | show(delay: number): void;
|
---|
| 226 | /**
|
---|
| 227 | * Begins the animation to hide the tooltip after the provided delay in ms.
|
---|
| 228 | * @param delay Amount of milliseconds to delay showing the tooltip.
|
---|
| 229 | */
|
---|
| 230 | hide(delay: number): void;
|
---|
| 231 | /** Returns an observable that notifies when the tooltip has been hidden from view. */
|
---|
| 232 | afterHidden(): Observable<void>;
|
---|
| 233 | /** Whether the tooltip is being displayed. */
|
---|
| 234 | isVisible(): boolean;
|
---|
| 235 | ngOnDestroy(): void;
|
---|
| 236 | _animationStart(): void;
|
---|
| 237 | _animationDone(event: AnimationEvent): void;
|
---|
| 238 | /**
|
---|
| 239 | * Interactions on the HTML body should close the tooltip immediately as defined in the
|
---|
| 240 | * material design spec.
|
---|
| 241 | * https://material.io/design/components/tooltips.html#behavior
|
---|
| 242 | */
|
---|
| 243 | _handleBodyInteraction(): void;
|
---|
| 244 | /**
|
---|
| 245 | * Marks that the tooltip needs to be checked in the next change detection run.
|
---|
| 246 | * Mainly used for rendering the initial text before positioning a tooltip, which
|
---|
| 247 | * can be problematic in components with OnPush change detection.
|
---|
| 248 | */
|
---|
| 249 | _markForCheck(): void;
|
---|
| 250 | /**
|
---|
| 251 | * Callback for when the timeout in this.show() gets completed.
|
---|
| 252 | * This method is only needed by the mdc-tooltip, and so it is only implemented
|
---|
| 253 | * in the mdc-tooltip, not here.
|
---|
| 254 | */
|
---|
| 255 | protected _onShow(): void;
|
---|
| 256 | }
|
---|
| 257 | /**
|
---|
| 258 | * Internal component that wraps the tooltip's content.
|
---|
| 259 | * @docs-private
|
---|
| 260 | */
|
---|
| 261 | export declare class TooltipComponent extends _TooltipComponentBase {
|
---|
| 262 | private _breakpointObserver;
|
---|
| 263 | /** Stream that emits whether the user has a handset-sized display. */
|
---|
| 264 | _isHandset: Observable<BreakpointState>;
|
---|
| 265 | constructor(changeDetectorRef: ChangeDetectorRef, _breakpointObserver: BreakpointObserver);
|
---|
| 266 | }
|
---|