| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- /**
- * @license
- * Copyright Google LLC All Rights Reserved.
- *
- * Use of this source code is governed by an MIT-style license that can be
- * found in the LICENSE file at https://angular.io/license
- */
- import { FocusMonitor, FocusOrigin } from '@angular/cdk/a11y';
- import { Direction, Directionality } from '@angular/cdk/bidi';
- import { Overlay, ScrollStrategy } from '@angular/cdk/overlay';
- import { AfterContentInit, ElementRef, EventEmitter, InjectionToken, OnDestroy, ViewContainerRef } from '@angular/core';
- import { MatMenu } from './menu';
- import { MatMenuItem } from './menu-item';
- import { MatMenuPanel } from './menu-panel';
- /** Injection token that determines the scroll handling while the menu is open. */
- export declare const MAT_MENU_SCROLL_STRATEGY: InjectionToken<() => ScrollStrategy>;
- /** @docs-private */
- export declare function MAT_MENU_SCROLL_STRATEGY_FACTORY(overlay: Overlay): () => ScrollStrategy;
- /** @docs-private */
- export declare const MAT_MENU_SCROLL_STRATEGY_FACTORY_PROVIDER: {
- provide: InjectionToken<() => ScrollStrategy>;
- deps: (typeof Overlay)[];
- useFactory: typeof MAT_MENU_SCROLL_STRATEGY_FACTORY;
- };
- /** Default top padding of the menu panel. */
- export declare const MENU_PANEL_TOP_PADDING = 8;
- /**
- * This directive is intended to be used in conjunction with an mat-menu tag. It is
- * responsible for toggling the display of the provided menu instance.
- */
- export declare class MatMenuTrigger implements AfterContentInit, OnDestroy {
- private _overlay;
- private _element;
- private _viewContainerRef;
- private _parentMenu;
- private _menuItemInstance;
- private _dir;
- private _focusMonitor?;
- private _portal;
- private _overlayRef;
- private _menuOpen;
- private _closingActionsSubscription;
- private _hoverSubscription;
- private _menuCloseSubscription;
- private _scrollStrategy;
- /**
- * Handles touch start events on the trigger.
- * Needs to be an arrow function so we can easily use addEventListener and removeEventListener.
- */
- private _handleTouchStart;
- _openedBy: 'mouse' | 'touch' | null;
- /**
- * @deprecated
- * @breaking-change 8.0.0
- */
- _deprecatedMatMenuTriggerFor: MatMenuPanel;
- /** References the menu instance that the trigger is associated with. */
- menu: MatMenuPanel;
- private _menu;
- /** Data to be passed along to any lazily-rendered content. */
- menuData: any;
- /**
- * Whether focus should be restored when the menu is closed.
- * Note that disabling this option can have accessibility implications
- * and it's up to you to manage focus, if you decide to turn it off.
- */
- restoreFocus: boolean;
- /** Event emitted when the associated menu is opened. */
- readonly menuOpened: EventEmitter<void>;
- /**
- * Event emitted when the associated menu is opened.
- * @deprecated Switch to `menuOpened` instead
- * @breaking-change 8.0.0
- */
- readonly onMenuOpen: EventEmitter<void>;
- /** Event emitted when the associated menu is closed. */
- readonly menuClosed: EventEmitter<void>;
- /**
- * Event emitted when the associated menu is closed.
- * @deprecated Switch to `menuClosed` instead
- * @breaking-change 8.0.0
- */
- readonly onMenuClose: EventEmitter<void>;
- constructor(_overlay: Overlay, _element: ElementRef<HTMLElement>, _viewContainerRef: ViewContainerRef, scrollStrategy: any, _parentMenu: MatMenu, _menuItemInstance: MatMenuItem, _dir: Directionality, _focusMonitor?: FocusMonitor | undefined);
- ngAfterContentInit(): void;
- ngOnDestroy(): void;
- /** Whether the menu is open. */
- readonly menuOpen: boolean;
- /** The text direction of the containing app. */
- readonly dir: Direction;
- /** Whether the menu triggers a sub-menu or a top-level one. */
- triggersSubmenu(): boolean;
- /** Toggles the menu between the open and closed states. */
- toggleMenu(): void;
- /** Opens the menu. */
- openMenu(): void;
- /** Closes the menu. */
- closeMenu(): void;
- /**
- * Focuses the menu trigger.
- * @param origin Source of the menu trigger's focus.
- */
- focus(origin?: FocusOrigin, options?: FocusOptions): void;
- /** Closes the menu and does the necessary cleanup. */
- private _destroyMenu;
- /**
- * This method sets the menu state to open and focuses the first item if
- * the menu was opened via the keyboard.
- */
- private _initMenu;
- /** Updates the menu elevation based on the amount of parent menus that it has. */
- private _setMenuElevation;
- /**
- * This method resets the menu when it's closed, most importantly restoring
- * focus to the menu trigger if the menu was opened via the keyboard.
- */
- private _resetMenu;
- private _setIsMenuOpen;
- /**
- * This method checks that a valid instance of MatMenu has been passed into
- * matMenuTriggerFor. If not, an exception is thrown.
- */
- private _checkMenu;
- /**
- * This method creates the overlay from the provided menu's template and saves its
- * OverlayRef so that it can be attached to the DOM when openMenu is called.
- */
- private _createOverlay;
- /**
- * This method builds the configuration object needed to create the overlay, the OverlayState.
- * @returns OverlayConfig
- */
- private _getOverlayConfig;
- /**
- * Listens to changes in the position of the overlay and sets the correct classes
- * on the menu based on the new position. This ensures the animation origin is always
- * correct, even if a fallback position is used for the overlay.
- */
- private _subscribeToPositions;
- /**
- * Sets the appropriate positions on a position strategy
- * so the overlay connects with the trigger correctly.
- * @param positionStrategy Strategy whose position to update.
- */
- private _setPosition;
- /** Returns a stream that emits whenever an action that should close the menu occurs. */
- private _menuClosingActions;
- /** Handles mouse presses on the trigger. */
- _handleMousedown(event: MouseEvent): void;
- /** Handles key presses on the trigger. */
- _handleKeydown(event: KeyboardEvent): void;
- /** Handles click events on the trigger. */
- _handleClick(event: MouseEvent): void;
- /** Handles the cases where the user hovers over the trigger. */
- private _handleHover;
- /** Gets the portal that should be attached to the overlay. */
- private _getPortal;
- }
|