menu-trigger.d.ts 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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 { FocusMonitor, FocusOrigin } from '@angular/cdk/a11y';
  9. import { Direction, Directionality } from '@angular/cdk/bidi';
  10. import { Overlay, ScrollStrategy } from '@angular/cdk/overlay';
  11. import { AfterContentInit, ElementRef, EventEmitter, InjectionToken, OnDestroy, ViewContainerRef } from '@angular/core';
  12. import { MatMenu } from './menu';
  13. import { MatMenuItem } from './menu-item';
  14. import { MatMenuPanel } from './menu-panel';
  15. /** Injection token that determines the scroll handling while the menu is open. */
  16. export declare const MAT_MENU_SCROLL_STRATEGY: InjectionToken<() => ScrollStrategy>;
  17. /** @docs-private */
  18. export declare function MAT_MENU_SCROLL_STRATEGY_FACTORY(overlay: Overlay): () => ScrollStrategy;
  19. /** @docs-private */
  20. export declare const MAT_MENU_SCROLL_STRATEGY_FACTORY_PROVIDER: {
  21. provide: InjectionToken<() => ScrollStrategy>;
  22. deps: (typeof Overlay)[];
  23. useFactory: typeof MAT_MENU_SCROLL_STRATEGY_FACTORY;
  24. };
  25. /** Default top padding of the menu panel. */
  26. export declare const MENU_PANEL_TOP_PADDING = 8;
  27. /**
  28. * This directive is intended to be used in conjunction with an mat-menu tag. It is
  29. * responsible for toggling the display of the provided menu instance.
  30. */
  31. export declare class MatMenuTrigger implements AfterContentInit, OnDestroy {
  32. private _overlay;
  33. private _element;
  34. private _viewContainerRef;
  35. private _parentMenu;
  36. private _menuItemInstance;
  37. private _dir;
  38. private _focusMonitor?;
  39. private _portal;
  40. private _overlayRef;
  41. private _menuOpen;
  42. private _closingActionsSubscription;
  43. private _hoverSubscription;
  44. private _menuCloseSubscription;
  45. private _scrollStrategy;
  46. /**
  47. * Handles touch start events on the trigger.
  48. * Needs to be an arrow function so we can easily use addEventListener and removeEventListener.
  49. */
  50. private _handleTouchStart;
  51. _openedBy: 'mouse' | 'touch' | null;
  52. /**
  53. * @deprecated
  54. * @breaking-change 8.0.0
  55. */
  56. _deprecatedMatMenuTriggerFor: MatMenuPanel;
  57. /** References the menu instance that the trigger is associated with. */
  58. menu: MatMenuPanel;
  59. private _menu;
  60. /** Data to be passed along to any lazily-rendered content. */
  61. menuData: any;
  62. /**
  63. * Whether focus should be restored when the menu is closed.
  64. * Note that disabling this option can have accessibility implications
  65. * and it's up to you to manage focus, if you decide to turn it off.
  66. */
  67. restoreFocus: boolean;
  68. /** Event emitted when the associated menu is opened. */
  69. readonly menuOpened: EventEmitter<void>;
  70. /**
  71. * Event emitted when the associated menu is opened.
  72. * @deprecated Switch to `menuOpened` instead
  73. * @breaking-change 8.0.0
  74. */
  75. readonly onMenuOpen: EventEmitter<void>;
  76. /** Event emitted when the associated menu is closed. */
  77. readonly menuClosed: EventEmitter<void>;
  78. /**
  79. * Event emitted when the associated menu is closed.
  80. * @deprecated Switch to `menuClosed` instead
  81. * @breaking-change 8.0.0
  82. */
  83. readonly onMenuClose: EventEmitter<void>;
  84. constructor(_overlay: Overlay, _element: ElementRef<HTMLElement>, _viewContainerRef: ViewContainerRef, scrollStrategy: any, _parentMenu: MatMenu, _menuItemInstance: MatMenuItem, _dir: Directionality, _focusMonitor?: FocusMonitor | undefined);
  85. ngAfterContentInit(): void;
  86. ngOnDestroy(): void;
  87. /** Whether the menu is open. */
  88. readonly menuOpen: boolean;
  89. /** The text direction of the containing app. */
  90. readonly dir: Direction;
  91. /** Whether the menu triggers a sub-menu or a top-level one. */
  92. triggersSubmenu(): boolean;
  93. /** Toggles the menu between the open and closed states. */
  94. toggleMenu(): void;
  95. /** Opens the menu. */
  96. openMenu(): void;
  97. /** Closes the menu. */
  98. closeMenu(): void;
  99. /**
  100. * Focuses the menu trigger.
  101. * @param origin Source of the menu trigger's focus.
  102. */
  103. focus(origin?: FocusOrigin, options?: FocusOptions): void;
  104. /** Closes the menu and does the necessary cleanup. */
  105. private _destroyMenu;
  106. /**
  107. * This method sets the menu state to open and focuses the first item if
  108. * the menu was opened via the keyboard.
  109. */
  110. private _initMenu;
  111. /** Updates the menu elevation based on the amount of parent menus that it has. */
  112. private _setMenuElevation;
  113. /**
  114. * This method resets the menu when it's closed, most importantly restoring
  115. * focus to the menu trigger if the menu was opened via the keyboard.
  116. */
  117. private _resetMenu;
  118. private _setIsMenuOpen;
  119. /**
  120. * This method checks that a valid instance of MatMenu has been passed into
  121. * matMenuTriggerFor. If not, an exception is thrown.
  122. */
  123. private _checkMenu;
  124. /**
  125. * This method creates the overlay from the provided menu's template and saves its
  126. * OverlayRef so that it can be attached to the DOM when openMenu is called.
  127. */
  128. private _createOverlay;
  129. /**
  130. * This method builds the configuration object needed to create the overlay, the OverlayState.
  131. * @returns OverlayConfig
  132. */
  133. private _getOverlayConfig;
  134. /**
  135. * Listens to changes in the position of the overlay and sets the correct classes
  136. * on the menu based on the new position. This ensures the animation origin is always
  137. * correct, even if a fallback position is used for the overlay.
  138. */
  139. private _subscribeToPositions;
  140. /**
  141. * Sets the appropriate positions on a position strategy
  142. * so the overlay connects with the trigger correctly.
  143. * @param positionStrategy Strategy whose position to update.
  144. */
  145. private _setPosition;
  146. /** Returns a stream that emits whenever an action that should close the menu occurs. */
  147. private _menuClosingActions;
  148. /** Handles mouse presses on the trigger. */
  149. _handleMousedown(event: MouseEvent): void;
  150. /** Handles key presses on the trigger. */
  151. _handleKeydown(event: KeyboardEvent): void;
  152. /** Handles click events on the trigger. */
  153. _handleClick(event: MouseEvent): void;
  154. /** Handles the cases where the user hovers over the trigger. */
  155. private _handleHover;
  156. /** Gets the portal that should be attached to the overlay. */
  157. private _getPortal;
  158. }