index.d.ts 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898
  1. import { AfterContentInit } from '@angular/core';
  2. import { BooleanInput } from '@angular/cdk/coercion';
  3. import { ConnectedPosition } from '@angular/cdk/overlay';
  4. import { Directionality } from '@angular/cdk/bidi';
  5. import { ElementRef } from '@angular/core';
  6. import { EventEmitter } from '@angular/core';
  7. import { FocusableOption } from '@angular/cdk/a11y';
  8. import { FocusKeyManager } from '@angular/cdk/a11y';
  9. import { FocusOrigin } from '@angular/cdk/a11y';
  10. import * as i0 from '@angular/core';
  11. import * as i1 from '@angular/cdk/overlay';
  12. import { InjectionToken } from '@angular/core';
  13. import { Injector } from '@angular/core';
  14. import { NgZone } from '@angular/core';
  15. import { Observable } from 'rxjs';
  16. import { OnDestroy } from '@angular/core';
  17. import { Optional } from '@angular/core';
  18. import { OverlayRef } from '@angular/cdk/overlay';
  19. import { QueryList } from '@angular/core';
  20. import { Subject } from 'rxjs';
  21. import { TemplatePortal } from '@angular/cdk/portal';
  22. import { TemplateRef } from '@angular/core';
  23. import { ViewContainerRef } from '@angular/core';
  24. /** Injection token used to return classes implementing the Menu interface */
  25. export declare const CDK_MENU: InjectionToken<Menu>;
  26. /**
  27. * A directive that opens a menu when a user right-clicks within its host element.
  28. * It is aware of nested context menus and will trigger only the lowest level non-disabled context menu.
  29. */
  30. export declare class CdkContextMenuTrigger extends CdkMenuTriggerBase implements OnDestroy {
  31. /** The CDK overlay service. */
  32. private readonly _overlay;
  33. /** The directionality of the page. */
  34. private readonly _directionality;
  35. /** The app's context menu tracking registry */
  36. private readonly _contextMenuTracker;
  37. /** Whether the context menu is disabled. */
  38. get disabled(): boolean;
  39. set disabled(value: BooleanInput);
  40. private _disabled;
  41. constructor();
  42. /**
  43. * Open the attached menu at the specified location.
  44. * @param coordinates where to open the context menu
  45. */
  46. open(coordinates: ContextMenuCoordinates): void;
  47. /** Close the currently opened context menu. */
  48. close(): void;
  49. /**
  50. * Open the context menu and closes any previously open menus.
  51. * @param event the mouse event which opens the context menu.
  52. */
  53. _openOnContextMenu(event: MouseEvent): void;
  54. /**
  55. * Get the configuration object used to create the overlay.
  56. * @param coordinates the location to place the opened menu
  57. */
  58. private _getOverlayConfig;
  59. /**
  60. * Get the position strategy for the overlay which specifies where to place the menu.
  61. * @param coordinates the location to place the opened menu
  62. */
  63. private _getOverlayPositionStrategy;
  64. /** Subscribe to the menu stack close events and close this menu when requested. */
  65. private _setMenuStackCloseListener;
  66. /**
  67. * Subscribe to the overlays outside pointer events stream and handle closing out the stack if a
  68. * click occurs outside the menus.
  69. * @param ignoreFirstAuxClick Whether to ignore the first auxclick event outside the menu.
  70. */
  71. private _subscribeToOutsideClicks;
  72. /**
  73. * Open the attached menu at the specified location.
  74. * @param coordinates where to open the context menu
  75. * @param ignoreFirstOutsideAuxClick Whether to ignore the first auxclick outside the menu after opening.
  76. */
  77. private _open;
  78. static ɵfac: i0.ɵɵFactoryDeclaration<CdkContextMenuTrigger, never>;
  79. static ɵdir: i0.ɵɵDirectiveDeclaration<CdkContextMenuTrigger, "[cdkContextMenuTriggerFor]", ["cdkContextMenuTriggerFor"], { "menuTemplateRef": { "alias": "cdkContextMenuTriggerFor"; "required": false; }; "menuPosition": { "alias": "cdkContextMenuPosition"; "required": false; }; "menuData": { "alias": "cdkContextMenuTriggerData"; "required": false; }; "disabled": { "alias": "cdkContextMenuDisabled"; "required": false; }; }, { "opened": "cdkContextMenuOpened"; "closed": "cdkContextMenuClosed"; }, never, never, true, never>;
  80. }
  81. /**
  82. * Directive which configures the element as a Menu which should contain child elements marked as
  83. * CdkMenuItem or CdkMenuGroup. Sets the appropriate role and aria-attributes for a menu and
  84. * contains accessible keyboard and mouse handling logic.
  85. *
  86. * It also acts as a RadioGroup for elements marked with role `menuitemradio`.
  87. */
  88. export declare class CdkMenu extends CdkMenuBase implements AfterContentInit, OnDestroy {
  89. private _parentTrigger;
  90. /** Event emitted when the menu is closed. */
  91. readonly closed: EventEmitter<void>;
  92. /** The direction items in the menu flow. */
  93. readonly orientation = "vertical";
  94. /** Whether the menu is displayed inline (i.e. always present vs a conditional popup that the user triggers with a trigger element). */
  95. readonly isInline: boolean;
  96. constructor();
  97. ngAfterContentInit(): void;
  98. ngOnDestroy(): void;
  99. /**
  100. * Handle keyboard events for the Menu.
  101. * @param event The keyboard event to be handled.
  102. */
  103. _handleKeyEvent(event: KeyboardEvent): void;
  104. /**
  105. * Set focus the either the current, previous or next item based on the FocusNext event.
  106. * @param focusNext The element to focus.
  107. */
  108. private _toggleMenuFocus;
  109. /** Subscribe to the MenuStack emptied events. */
  110. private _subscribeToMenuStackEmptied;
  111. static ɵfac: i0.ɵɵFactoryDeclaration<CdkMenu, never>;
  112. static ɵdir: i0.ɵɵDirectiveDeclaration<CdkMenu, "[cdkMenu]", ["cdkMenu"], {}, { "closed": "closed"; }, never, never, true, never>;
  113. }
  114. /**
  115. * Directive applied to an element which configures it as a MenuBar by setting the appropriate
  116. * role, aria attributes, and accessible keyboard and mouse handling logic. The component that
  117. * this directive is applied to should contain components marked with CdkMenuItem.
  118. *
  119. */
  120. export declare class CdkMenuBar extends CdkMenuBase implements AfterContentInit {
  121. /** The direction items in the menu flow. */
  122. readonly orientation = "horizontal";
  123. /** Whether the menu is displayed inline (i.e. always present vs a conditional popup that the user triggers with a trigger element). */
  124. readonly isInline = true;
  125. ngAfterContentInit(): void;
  126. /**
  127. * Handle keyboard events for the Menu.
  128. * @param event The keyboard event to be handled.
  129. */
  130. _handleKeyEvent(event: KeyboardEvent): void;
  131. /**
  132. * Set focus to either the current, previous or next item based on the FocusNext event, then
  133. * open the previous or next item.
  134. * @param focusNext The element to focus.
  135. */
  136. private _toggleOpenMenu;
  137. /** Subscribe to the MenuStack emptied events. */
  138. private _subscribeToMenuStackEmptied;
  139. static ɵfac: i0.ɵɵFactoryDeclaration<CdkMenuBar, never>;
  140. static ɵdir: i0.ɵɵDirectiveDeclaration<CdkMenuBar, "[cdkMenuBar]", ["cdkMenuBar"], {}, {}, never, never, true, never>;
  141. }
  142. /**
  143. * Abstract directive that implements shared logic common to all menus.
  144. * This class can be extended to create custom menu types.
  145. */
  146. export declare abstract class CdkMenuBase extends CdkMenuGroup implements Menu, AfterContentInit, OnDestroy {
  147. /** The menu's native DOM host element. */
  148. readonly nativeElement: HTMLElement;
  149. /** The Angular zone. */
  150. protected ngZone: NgZone;
  151. /** The stack of menus this menu belongs to. */
  152. readonly menuStack: MenuStack;
  153. /** The menu aim service used by this menu. */
  154. protected readonly menuAim: MenuAim | null;
  155. /** The directionality (text direction) of the current page. */
  156. protected readonly dir: Directionality | null;
  157. /** The id of the menu's host element. */
  158. id: string;
  159. /** All child MenuItem elements nested in this Menu. */
  160. readonly items: QueryList<CdkMenuItem>;
  161. /** The direction items in the menu flow. */
  162. orientation: 'horizontal' | 'vertical';
  163. /**
  164. * Whether the menu is displayed inline (i.e. always present vs a conditional popup that the
  165. * user triggers with a trigger element).
  166. */
  167. isInline: boolean;
  168. /** Handles keyboard events for the menu. */
  169. protected keyManager: FocusKeyManager<CdkMenuItem>;
  170. /** Emits when the MenuBar is destroyed. */
  171. protected readonly destroyed: Subject<void>;
  172. /** The Menu Item which triggered the open submenu. */
  173. protected triggerItem?: CdkMenuItem;
  174. /** Tracks the users mouse movements over the menu. */
  175. protected pointerTracker?: PointerFocusTracker<CdkMenuItem>;
  176. /** Whether this menu's menu stack has focus. */
  177. private _menuStackHasFocus;
  178. ngAfterContentInit(): void;
  179. ngOnDestroy(): void;
  180. /**
  181. * Place focus on the first MenuItem in the menu and set the focus origin.
  182. * @param focusOrigin The origin input mode of the focus event.
  183. */
  184. focusFirstItem(focusOrigin?: FocusOrigin): void;
  185. /**
  186. * Place focus on the last MenuItem in the menu and set the focus origin.
  187. * @param focusOrigin The origin input mode of the focus event.
  188. */
  189. focusLastItem(focusOrigin?: FocusOrigin): void;
  190. /** Gets the tabindex for this menu. */
  191. _getTabIndex(): 0 | -1 | null;
  192. /**
  193. * Close the open menu if the current active item opened the requested MenuStackItem.
  194. * @param menu The menu requested to be closed.
  195. * @param options Options to configure the behavior on close.
  196. * - `focusParentTrigger` Whether to focus the parent trigger after closing the menu.
  197. */
  198. protected closeOpenMenu(menu: MenuStackItem, options?: {
  199. focusParentTrigger?: boolean;
  200. }): void;
  201. /** Setup the FocusKeyManager with the correct orientation for the menu. */
  202. private _setKeyManager;
  203. /**
  204. * Subscribe to the menu trigger's open events in order to track the trigger which opened the menu
  205. * and stop tracking it when the menu is closed.
  206. */
  207. private _subscribeToMenuOpen;
  208. /** Subscribe to the MenuStack close events. */
  209. private _subscribeToMenuStackClosed;
  210. /** Subscribe to the MenuStack hasFocus events. */
  211. private _subscribeToMenuStackHasFocus;
  212. /**
  213. * Set the PointerFocusTracker and ensure that when mouse focus changes the key manager is updated
  214. * with the latest menu item under mouse focus.
  215. */
  216. private _setUpPointerTracker;
  217. static ɵfac: i0.ɵɵFactoryDeclaration<CdkMenuBase, never>;
  218. static ɵdir: i0.ɵɵDirectiveDeclaration<CdkMenuBase, never, never, { "id": { "alias": "id"; "required": false; }; }, {}, ["items"], never, false, never>;
  219. }
  220. /**
  221. * A grouping container for `CdkMenuItemRadio` instances, similar to a `role="radiogroup"` element.
  222. */
  223. export declare class CdkMenuGroup {
  224. static ɵfac: i0.ɵɵFactoryDeclaration<CdkMenuGroup, never>;
  225. static ɵdir: i0.ɵɵDirectiveDeclaration<CdkMenuGroup, "[cdkMenuGroup]", ["cdkMenuGroup"], {}, {}, never, never, true, never>;
  226. }
  227. /**
  228. * Directive which provides the ability for an element to be focused and navigated to using the
  229. * keyboard when residing in a CdkMenu, CdkMenuBar, or CdkMenuGroup. It performs user defined
  230. * behavior when clicked.
  231. */
  232. export declare class CdkMenuItem implements FocusableOption, FocusableElement, Toggler, OnDestroy {
  233. protected readonly _dir: Directionality | null;
  234. private readonly _inputModalityDetector;
  235. readonly _elementRef: ElementRef<HTMLElement>;
  236. protected _ngZone: NgZone;
  237. /** The menu aim service used by this menu. */
  238. private readonly _menuAim;
  239. /** The stack of menus this menu belongs to. */
  240. private readonly _menuStack;
  241. /** The parent menu in which this menuitem resides. */
  242. private readonly _parentMenu;
  243. /** Reference to the CdkMenuItemTrigger directive if one is added to the same element */
  244. private readonly _menuTrigger;
  245. /** Whether the CdkMenuItem is disabled - defaults to false */
  246. get disabled(): boolean;
  247. set disabled(value: BooleanInput);
  248. private _disabled;
  249. /**
  250. * The text used to locate this item during menu typeahead. If not specified,
  251. * the `textContent` of the item will be used.
  252. */
  253. typeaheadLabel: string | null;
  254. /**
  255. * If this MenuItem is a regular MenuItem, outputs when it is triggered by a keyboard or mouse
  256. * event.
  257. */
  258. readonly triggered: EventEmitter<void>;
  259. /** Whether the menu item opens a menu. */
  260. get hasMenu(): boolean;
  261. /**
  262. * The tabindex for this menu item managed internally and used for implementing roving a
  263. * tab index.
  264. */
  265. _tabindex: 0 | -1;
  266. /** Whether the item should close the menu if triggered by the spacebar. */
  267. protected closeOnSpacebarTrigger: boolean;
  268. /** Emits when the menu item is destroyed. */
  269. protected readonly destroyed: Subject<void>;
  270. constructor();
  271. ngOnDestroy(): void;
  272. /** Place focus on the element. */
  273. focus(): void;
  274. /**
  275. * If the menu item is not disabled and the element does not have a menu trigger attached, emit
  276. * on the cdkMenuItemTriggered emitter and close all open menus.
  277. * @param options Options the configure how the item is triggered
  278. * - keepOpen: specifies that the menu should be kept open after triggering the item.
  279. */
  280. trigger(options?: {
  281. keepOpen: boolean;
  282. }): void;
  283. /** Return true if this MenuItem has an attached menu and it is open. */
  284. isMenuOpen(): boolean;
  285. /**
  286. * Get a reference to the rendered Menu if the Menu is open and it is visible in the DOM.
  287. * @return the menu if it is open, otherwise undefined.
  288. */
  289. getMenu(): Menu | undefined;
  290. /** Get the CdkMenuTrigger associated with this element. */
  291. getMenuTrigger(): CdkMenuTrigger | null;
  292. /** Get the label for this element which is required by the FocusableOption interface. */
  293. getLabel(): string;
  294. /** Reset the tabindex to -1. */
  295. _resetTabIndex(): void;
  296. /**
  297. * Set the tab index to 0 if not disabled and it's a focus event, or a mouse enter if this element
  298. * is not in a menu bar.
  299. */
  300. _setTabIndex(event?: MouseEvent): void;
  301. /**
  302. * Handles keyboard events for the menu item, specifically either triggering the user defined
  303. * callback or opening/closing the current menu based on whether the left or right arrow key was
  304. * pressed.
  305. * @param event the keyboard event to handle
  306. */
  307. _onKeydown(event: KeyboardEvent): void;
  308. /** Handles clicks on the menu item. */
  309. _handleClick(): void;
  310. /** Whether this menu item is standalone or within a menu or menu bar. */
  311. private _isStandaloneItem;
  312. /**
  313. * Handles the user pressing the back arrow key.
  314. * @param event The keyboard event.
  315. */
  316. private _backArrowPressed;
  317. /**
  318. * Handles the user pressing the forward arrow key.
  319. * @param event The keyboard event.
  320. */
  321. private _forwardArrowPressed;
  322. /**
  323. * Subscribe to the mouseenter events and close any sibling menu items if this element is moused
  324. * into.
  325. */
  326. private _setupMouseEnter;
  327. /**
  328. * Return true if the enclosing parent menu is configured in a horizontal orientation, false
  329. * otherwise or if no parent.
  330. */
  331. private _isParentVertical;
  332. /** Sets the `type` attribute of the menu item. */
  333. private _setType;
  334. static ɵfac: i0.ɵɵFactoryDeclaration<CdkMenuItem, never>;
  335. static ɵdir: i0.ɵɵDirectiveDeclaration<CdkMenuItem, "[cdkMenuItem]", ["cdkMenuItem"], { "disabled": { "alias": "cdkMenuItemDisabled"; "required": false; }; "typeaheadLabel": { "alias": "cdkMenuitemTypeaheadLabel"; "required": false; }; }, { "triggered": "cdkMenuItemTriggered"; }, never, never, true, never>;
  336. }
  337. /**
  338. * A directive providing behavior for the "menuitemcheckbox" ARIA role, which behaves similarly to a
  339. * conventional checkbox.
  340. */
  341. export declare class CdkMenuItemCheckbox extends CdkMenuItemSelectable {
  342. /**
  343. * Toggle the checked state of the checkbox.
  344. * @param options Options the configure how the item is triggered
  345. * - keepOpen: specifies that the menu should be kept open after triggering the item.
  346. */
  347. trigger(options?: {
  348. keepOpen: boolean;
  349. }): void;
  350. static ɵfac: i0.ɵɵFactoryDeclaration<CdkMenuItemCheckbox, never>;
  351. static ɵdir: i0.ɵɵDirectiveDeclaration<CdkMenuItemCheckbox, "[cdkMenuItemCheckbox]", ["cdkMenuItemCheckbox"], {}, {}, never, never, true, never>;
  352. }
  353. /**
  354. * A directive providing behavior for the "menuitemradio" ARIA role, which behaves similarly to
  355. * a conventional radio-button. Any sibling `CdkMenuItemRadio` instances within the same `CdkMenu`
  356. * or `CdkMenuGroup` comprise a radio group with unique selection enforced.
  357. */
  358. export declare class CdkMenuItemRadio extends CdkMenuItemSelectable implements OnDestroy {
  359. /** The unique selection dispatcher for this radio's `CdkMenuGroup`. */
  360. private readonly _selectionDispatcher;
  361. /** An ID to identify this radio item to the `UniqueSelectionDispatcher`. */
  362. private _id;
  363. /** Function to unregister the selection dispatcher */
  364. private _removeDispatcherListener;
  365. constructor();
  366. ngOnDestroy(): void;
  367. /**
  368. * Toggles the checked state of the radio-button.
  369. * @param options Options the configure how the item is triggered
  370. * - keepOpen: specifies that the menu should be kept open after triggering the item.
  371. */
  372. trigger(options?: {
  373. keepOpen: boolean;
  374. }): void;
  375. /** Configure the unique selection dispatcher listener in order to toggle the checked state */
  376. private _registerDispatcherListener;
  377. static ɵfac: i0.ɵɵFactoryDeclaration<CdkMenuItemRadio, never>;
  378. static ɵdir: i0.ɵɵDirectiveDeclaration<CdkMenuItemRadio, "[cdkMenuItemRadio]", ["cdkMenuItemRadio"], {}, {}, never, never, true, never>;
  379. }
  380. /** Base class providing checked state for selectable MenuItems. */
  381. export declare abstract class CdkMenuItemSelectable extends CdkMenuItem {
  382. /** Whether the element is checked */
  383. get checked(): boolean;
  384. set checked(value: BooleanInput);
  385. private _checked;
  386. /** Whether the item should close the menu if triggered by the spacebar. */
  387. protected closeOnSpacebarTrigger: boolean;
  388. static ɵfac: i0.ɵɵFactoryDeclaration<CdkMenuItemSelectable, never>;
  389. static ɵdir: i0.ɵɵDirectiveDeclaration<CdkMenuItemSelectable, never, never, { "checked": { "alias": "cdkMenuItemChecked"; "required": false; }; }, {}, never, never, false, never>;
  390. }
  391. /** Module that declares components and directives for the CDK menu. */
  392. export declare class CdkMenuModule {
  393. static ɵfac: i0.ɵɵFactoryDeclaration<CdkMenuModule, never>;
  394. static ɵmod: i0.ɵɵNgModuleDeclaration<CdkMenuModule, never, [typeof i1.OverlayModule, typeof i2.CdkMenuBar, typeof i3.CdkMenu, typeof i4.CdkMenuItem, typeof i5.CdkMenuItemRadio, typeof i6.CdkMenuItemCheckbox, typeof i7.CdkMenuTrigger, typeof i8.CdkMenuGroup, typeof i9.CdkContextMenuTrigger, typeof i10.CdkTargetMenuAim], [typeof i2.CdkMenuBar, typeof i3.CdkMenu, typeof i4.CdkMenuItem, typeof i5.CdkMenuItemRadio, typeof i6.CdkMenuItemCheckbox, typeof i7.CdkMenuTrigger, typeof i8.CdkMenuGroup, typeof i9.CdkContextMenuTrigger, typeof i10.CdkTargetMenuAim]>;
  395. static ɵinj: i0.ɵɵInjectorDeclaration<CdkMenuModule>;
  396. }
  397. /**
  398. * A directive that turns its host element into a trigger for a popup menu.
  399. * It can be combined with cdkMenuItem to create sub-menus. If the element is in a top level
  400. * MenuBar it will open the menu on click, or if a sibling is already opened it will open on hover.
  401. * If it is inside of a Menu it will open the attached Submenu on hover regardless of its sibling
  402. * state.
  403. */
  404. export declare class CdkMenuTrigger extends CdkMenuTriggerBase implements OnDestroy {
  405. private readonly _elementRef;
  406. private readonly _overlay;
  407. private readonly _ngZone;
  408. private readonly _directionality;
  409. private readonly _inputModalityDetector;
  410. /** The parent menu this trigger belongs to. */
  411. private readonly _parentMenu;
  412. /** The menu aim service used by this menu. */
  413. private readonly _menuAim;
  414. constructor();
  415. /** Toggle the attached menu. */
  416. toggle(): void;
  417. /** Open the attached menu. */
  418. open(): void;
  419. /** Close the opened menu. */
  420. close(): void;
  421. /**
  422. * Get a reference to the rendered Menu if the Menu is open and rendered in the DOM.
  423. */
  424. getMenu(): Menu | undefined;
  425. /**
  426. * Handles keyboard events for the menu item.
  427. * @param event The keyboard event to handle
  428. */
  429. _toggleOnKeydown(event: KeyboardEvent): void;
  430. /** Handles clicks on the menu trigger. */
  431. _handleClick(): void;
  432. /**
  433. * Sets whether the trigger's menu stack has focus.
  434. * @param hasFocus Whether the menu stack has focus.
  435. */
  436. _setHasFocus(hasFocus: boolean): void;
  437. /**
  438. * Subscribe to the mouseenter events and close any sibling menu items if this element is moused
  439. * into.
  440. */
  441. private _subscribeToMouseEnter;
  442. /** Close out any sibling menu trigger menus. */
  443. private _closeSiblingTriggers;
  444. /** Get the configuration object used to create the overlay. */
  445. private _getOverlayConfig;
  446. /** Build the position strategy for the overlay which specifies where to place the menu. */
  447. private _getOverlayPositionStrategy;
  448. /** Get the preferred positions for the opened menu relative to the menu item. */
  449. private _getOverlayPositions;
  450. /**
  451. * Subscribe to the MenuStack close events if this is a standalone trigger and close out the menu
  452. * this triggers when requested.
  453. */
  454. private _registerCloseHandler;
  455. /**
  456. * Subscribe to the overlays outside pointer events stream and handle closing out the stack if a
  457. * click occurs outside the menus.
  458. */
  459. private _subscribeToOutsideClicks;
  460. /** Subscribe to the MenuStack hasFocus events. */
  461. private _subscribeToMenuStackHasFocus;
  462. /** Subscribe to the MenuStack closed events. */
  463. private _subscribeToMenuStackClosed;
  464. /** Sets the role attribute for this trigger if needed. */
  465. private _setRole;
  466. /** Sets thte `type` attribute of the trigger. */
  467. private _setType;
  468. static ɵfac: i0.ɵɵFactoryDeclaration<CdkMenuTrigger, never>;
  469. static ɵdir: i0.ɵɵDirectiveDeclaration<CdkMenuTrigger, "[cdkMenuTriggerFor]", ["cdkMenuTriggerFor"], { "menuTemplateRef": { "alias": "cdkMenuTriggerFor"; "required": false; }; "menuPosition": { "alias": "cdkMenuPosition"; "required": false; }; "menuData": { "alias": "cdkMenuTriggerData"; "required": false; }; }, { "opened": "cdkMenuOpened"; "closed": "cdkMenuClosed"; }, never, never, true, never>;
  470. }
  471. /**
  472. * Abstract directive that implements shared logic common to all menu triggers.
  473. * This class can be extended to create custom menu trigger types.
  474. */
  475. export declare abstract class CdkMenuTriggerBase implements OnDestroy {
  476. /** The DI injector for this component. */
  477. readonly injector: Injector;
  478. /** The view container ref for this component */
  479. protected readonly viewContainerRef: ViewContainerRef;
  480. /** The menu stack in which this menu resides. */
  481. protected readonly menuStack: MenuStack;
  482. /**
  483. * A list of preferred menu positions to be used when constructing the
  484. * `FlexibleConnectedPositionStrategy` for this trigger's menu.
  485. */
  486. menuPosition: ConnectedPosition[];
  487. /** Emits when the attached menu is requested to open */
  488. readonly opened: EventEmitter<void>;
  489. /** Emits when the attached menu is requested to close */
  490. readonly closed: EventEmitter<void>;
  491. /** Template reference variable to the menu this trigger opens */
  492. menuTemplateRef: TemplateRef<unknown> | null;
  493. /** Context data to be passed along to the menu template */
  494. menuData: unknown;
  495. /** A reference to the overlay which manages the triggered menu */
  496. protected overlayRef: OverlayRef | null;
  497. /** Emits when this trigger is destroyed. */
  498. protected readonly destroyed: Subject<void>;
  499. /** Emits when the outside pointer events listener on the overlay should be stopped. */
  500. protected readonly stopOutsideClicksListener: Observable<void>;
  501. /** The child menu opened by this trigger. */
  502. protected childMenu?: Menu;
  503. /** The content of the menu panel opened by this trigger. */
  504. private _menuPortal;
  505. /** The injector to use for the child menu opened by this trigger. */
  506. private _childMenuInjector?;
  507. ngOnDestroy(): void;
  508. /** Whether the attached menu is open. */
  509. isOpen(): boolean;
  510. /** Registers a child menu as having been opened by this trigger. */
  511. registerChildMenu(child: Menu): void;
  512. /**
  513. * Get the portal to be attached to the overlay which contains the menu. Allows for the menu
  514. * content to change dynamically and be reflected in the application.
  515. */
  516. protected getMenuContentPortal(): TemplatePortal<any>;
  517. /**
  518. * Whether the given element is inside the scope of this trigger's menu stack.
  519. * @param element The element to check.
  520. * @return Whether the element is inside the scope of this trigger's menu stack.
  521. */
  522. protected isElementInsideMenuStack(element: Element): boolean;
  523. /** Destroy and unset the overlay reference it if exists */
  524. private _destroyOverlay;
  525. /** Gets the injector to use when creating a child menu. */
  526. private _getChildMenuInjector;
  527. static ɵfac: i0.ɵɵFactoryDeclaration<CdkMenuTriggerBase, never>;
  528. static ɵdir: i0.ɵɵDirectiveDeclaration<CdkMenuTriggerBase, never, never, {}, {}, never, never, false, never>;
  529. }
  530. /**
  531. * CdkTargetMenuAim is a provider for the TargetMenuAim service. It can be added to an
  532. * element with either the `cdkMenu` or `cdkMenuBar` directive and child menu items.
  533. */
  534. export declare class CdkTargetMenuAim {
  535. static ɵfac: i0.ɵɵFactoryDeclaration<CdkTargetMenuAim, never>;
  536. static ɵdir: i0.ɵɵDirectiveDeclaration<CdkTargetMenuAim, "[cdkTargetMenuAim]", ["cdkTargetMenuAim"], {}, {}, never, never, true, never>;
  537. }
  538. /** Options that can be provided to the close or closeAll methods. */
  539. export declare interface CloseOptions {
  540. /** The element to focus next if the close operation causes the menu stack to become empty. */
  541. focusNextOnEmpty?: FocusNext;
  542. /** Whether to focus the parent trigger after closing the menu. */
  543. focusParentTrigger?: boolean;
  544. }
  545. /** The coordinates where the context menu should open. */
  546. export declare type ContextMenuCoordinates = {
  547. x: number;
  548. y: number;
  549. };
  550. /** Tracks the last open context menu trigger across the entire application. */
  551. export declare class ContextMenuTracker {
  552. /** The last open context menu trigger. */
  553. private static _openContextMenuTrigger?;
  554. /**
  555. * Close the previous open context menu and set the given one as being open.
  556. * @param trigger The trigger for the currently open Context Menu.
  557. */
  558. update(trigger: CdkContextMenuTrigger): void;
  559. static ɵfac: i0.ɵɵFactoryDeclaration<ContextMenuTracker, never>;
  560. static ɵprov: i0.ɵɵInjectableDeclaration<ContextMenuTracker>;
  561. }
  562. /** Item to track for mouse focus events. */
  563. export declare interface FocusableElement {
  564. /** A reference to the element to be tracked. */
  565. _elementRef: ElementRef<HTMLElement>;
  566. }
  567. /** The relative item in the inline menu to focus after closing all popup menus. */
  568. export declare const enum FocusNext {
  569. nextItem = 0,
  570. previousItem = 1,
  571. currentItem = 2
  572. }
  573. declare namespace i10 {
  574. export {
  575. MenuAim,
  576. MENU_AIM,
  577. Toggler,
  578. TargetMenuAim,
  579. CdkTargetMenuAim
  580. }
  581. }
  582. declare namespace i2 {
  583. export {
  584. CdkMenuBar
  585. }
  586. }
  587. declare namespace i3 {
  588. export {
  589. CdkMenu
  590. }
  591. }
  592. declare namespace i4 {
  593. export {
  594. CdkMenuItem
  595. }
  596. }
  597. declare namespace i5 {
  598. export {
  599. CdkMenuItemRadio
  600. }
  601. }
  602. declare namespace i6 {
  603. export {
  604. CdkMenuItemCheckbox
  605. }
  606. }
  607. declare namespace i7 {
  608. export {
  609. CdkMenuTrigger
  610. }
  611. }
  612. declare namespace i8 {
  613. export {
  614. CdkMenuGroup
  615. }
  616. }
  617. declare namespace i9 {
  618. export {
  619. ContextMenuTracker,
  620. ContextMenuCoordinates,
  621. CdkContextMenuTrigger
  622. }
  623. }
  624. /** Interface which specifies Menu operations and used to break circular dependency issues */
  625. export declare interface Menu extends MenuStackItem {
  626. /** The id of the menu's host element. */
  627. id: string;
  628. /** The menu's native DOM host element. */
  629. nativeElement: HTMLElement;
  630. /** The direction items in the menu flow. */
  631. readonly orientation: 'horizontal' | 'vertical';
  632. /** Place focus on the first MenuItem in the menu. */
  633. focusFirstItem(focusOrigin: FocusOrigin): void;
  634. /** Place focus on the last MenuItem in the menu. */
  635. focusLastItem(focusOrigin: FocusOrigin): void;
  636. }
  637. /** Injection token used for an implementation of MenuAim. */
  638. export declare const MENU_AIM: InjectionToken<MenuAim>;
  639. /** Injection token used for an implementation of MenuStack. */
  640. export declare const MENU_STACK: InjectionToken<MenuStack>;
  641. /** Injection token used for an implementation of MenuStack. */
  642. export declare const MENU_TRIGGER: InjectionToken<CdkMenuTriggerBase>;
  643. /**
  644. * MenuAim is responsible for determining if a sibling menuitem's menu should be closed when a
  645. * Toggler item is hovered into. It is up to the hovered in item to call the MenuAim service in
  646. * order to determine if it may perform its close actions.
  647. */
  648. export declare interface MenuAim {
  649. /**
  650. * Set the Menu and its PointerFocusTracker.
  651. * @param menu The menu that this menu aim service controls.
  652. * @param pointerTracker The `PointerFocusTracker` for the given menu.
  653. */
  654. initialize(menu: Menu, pointerTracker: PointerFocusTracker<FocusableElement & Toggler>): void;
  655. /**
  656. * Calls the `doToggle` callback when it is deemed that the user is not moving towards
  657. * the submenu.
  658. * @param doToggle the function called when the user is not moving towards the submenu.
  659. */
  660. toggle(doToggle: () => void): void;
  661. }
  662. /**
  663. * MenuStack allows subscribers to listen for close events (when a MenuStackItem is popped off
  664. * of the stack) in order to perform closing actions. Upon the MenuStack being empty it emits
  665. * from the `empty` observable specifying the next focus action which the listener should perform
  666. * as requested by the closer.
  667. */
  668. export declare class MenuStack {
  669. /** The ID of this menu stack. */
  670. readonly id: string;
  671. /** All MenuStackItems tracked by this MenuStack. */
  672. private readonly _elements;
  673. /** Emits the element which was popped off of the stack when requested by a closer. */
  674. private readonly _close;
  675. /** Emits once the MenuStack has become empty after popping off elements. */
  676. private readonly _empty;
  677. /** Emits whether any menu in the menu stack has focus. */
  678. private readonly _hasFocus;
  679. /** Observable which emits the MenuStackItem which has been requested to close. */
  680. readonly closed: Observable<MenuStackCloseEvent>;
  681. /** Observable which emits whether any menu in the menu stack has focus. */
  682. readonly hasFocus: Observable<boolean>;
  683. /**
  684. * Observable which emits when the MenuStack is empty after popping off the last element. It
  685. * emits a FocusNext event which specifies the action the closer has requested the listener
  686. * perform.
  687. */
  688. readonly emptied: Observable<FocusNext | undefined>;
  689. /**
  690. * Whether the inline menu associated with this menu stack is vertical or horizontal.
  691. * `null` indicates there is no inline menu associated with this menu stack.
  692. */
  693. private _inlineMenuOrientation;
  694. /** Creates a menu stack that originates from an inline menu. */
  695. static inline(orientation: 'vertical' | 'horizontal'): MenuStack;
  696. /**
  697. * Adds an item to the menu stack.
  698. * @param menu the MenuStackItem to put on the stack.
  699. */
  700. push(menu: MenuStackItem): void;
  701. /**
  702. * Pop items off of the stack up to and including `lastItem` and emit each on the close
  703. * observable. If the stack is empty or `lastItem` is not on the stack it does nothing.
  704. * @param lastItem the last item to pop off the stack.
  705. * @param options Options that configure behavior on close.
  706. */
  707. close(lastItem: MenuStackItem, options?: CloseOptions): void;
  708. /**
  709. * Pop items off of the stack up to but excluding `lastItem` and emit each on the close
  710. * observable. If the stack is empty or `lastItem` is not on the stack it does nothing.
  711. * @param lastItem the element which should be left on the stack
  712. * @return whether or not an item was removed from the stack
  713. */
  714. closeSubMenuOf(lastItem: MenuStackItem): boolean;
  715. /**
  716. * Pop off all MenuStackItems and emit each one on the `close` observable one by one.
  717. * @param options Options that configure behavior on close.
  718. */
  719. closeAll(options?: CloseOptions): void;
  720. /** Return true if this stack is empty. */
  721. isEmpty(): boolean;
  722. /** Return the length of the stack. */
  723. length(): number;
  724. /** Get the top most element on the stack. */
  725. peek(): MenuStackItem | undefined;
  726. /** Whether the menu stack is associated with an inline menu. */
  727. hasInlineMenu(): boolean;
  728. /** The orientation of the associated inline menu. */
  729. inlineMenuOrientation(): "vertical" | "horizontal" | null;
  730. /** Sets whether the menu stack contains the focused element. */
  731. setHasFocus(hasFocus: boolean): void;
  732. static ɵfac: i0.ɵɵFactoryDeclaration<MenuStack, never>;
  733. static ɵprov: i0.ɵɵInjectableDeclaration<MenuStack>;
  734. }
  735. /** Event dispatched when a menu is closed. */
  736. export declare interface MenuStackCloseEvent {
  737. /** The menu being closed. */
  738. item: MenuStackItem;
  739. /** Whether to focus the parent trigger after closing the menu. */
  740. focusParentTrigger?: boolean;
  741. }
  742. /** A single item (menu) in the menu stack. */
  743. export declare interface MenuStackItem {
  744. /** A reference to the menu stack this menu stack item belongs to. */
  745. menuStack?: MenuStack;
  746. }
  747. /** Provider that provides the parent menu stack, or a new inline menu stack if there is no parent one. */
  748. export declare const PARENT_OR_NEW_INLINE_MENU_STACK_PROVIDER: (orientation: 'vertical' | 'horizontal') => {
  749. provide: InjectionToken<MenuStack>;
  750. deps: Optional[][];
  751. useFactory: (parentMenuStack?: MenuStack) => MenuStack;
  752. };
  753. /** Provider that provides the parent menu stack, or a new menu stack if there is no parent one. */
  754. export declare const PARENT_OR_NEW_MENU_STACK_PROVIDER: {
  755. provide: InjectionToken<MenuStack>;
  756. deps: Optional[][];
  757. useFactory: (parentMenuStack?: MenuStack) => MenuStack;
  758. };
  759. /**
  760. * PointerFocusTracker keeps track of the currently active item under mouse focus. It also has
  761. * observables which emit when the users mouse enters and leaves a tracked element.
  762. */
  763. export declare class PointerFocusTracker<T extends FocusableElement> {
  764. /** The list of items being tracked. */
  765. private readonly _items;
  766. /** Emits when an element is moused into. */
  767. readonly entered: Observable<T>;
  768. /** Emits when an element is moused out. */
  769. readonly exited: Observable<T>;
  770. /** The element currently under mouse focus. */
  771. activeElement?: T;
  772. /** The element previously under mouse focus. */
  773. previousElement?: T;
  774. /** Emits when this is destroyed. */
  775. private readonly _destroyed;
  776. constructor(
  777. /** The list of items being tracked. */
  778. _items: QueryList<T>);
  779. /** Stop the managers listeners. */
  780. destroy(): void;
  781. /**
  782. * Gets a stream of pointer (mouse) entries into the given items.
  783. * This should typically run outside the Angular zone.
  784. */
  785. private _getItemPointerEntries;
  786. /**
  787. * Gets a stream of pointer (mouse) exits out of the given items.
  788. * This should typically run outside the Angular zone.
  789. */
  790. private _getItemPointerExits;
  791. }
  792. /**
  793. * TargetMenuAim predicts if a user is moving into a submenu. It calculates the
  794. * trajectory of the user's mouse movement in the current menu to determine if the
  795. * mouse is moving towards an open submenu.
  796. *
  797. * The determination is made by calculating the slope of the users last NUM_POINTS moves where each
  798. * pair of points determines if the trajectory line points into the submenu. It uses consensus
  799. * approach by checking if at least NUM_POINTS / 2 pairs determine that the user is moving towards
  800. * to submenu.
  801. */
  802. export declare class TargetMenuAim implements MenuAim, OnDestroy {
  803. /** The Angular zone. */
  804. private readonly _ngZone;
  805. /** The last NUM_POINTS mouse move events. */
  806. private readonly _points;
  807. /** Reference to the root menu in which we are tracking mouse moves. */
  808. private _menu;
  809. /** Reference to the root menu's mouse manager. */
  810. private _pointerTracker;
  811. /** The id associated with the current timeout call waiting to resolve. */
  812. private _timeoutId;
  813. /** Emits when this service is destroyed. */
  814. private readonly _destroyed;
  815. ngOnDestroy(): void;
  816. /**
  817. * Set the Menu and its PointerFocusTracker.
  818. * @param menu The menu that this menu aim service controls.
  819. * @param pointerTracker The `PointerFocusTracker` for the given menu.
  820. */
  821. initialize(menu: Menu, pointerTracker: PointerFocusTracker<FocusableElement & Toggler>): void;
  822. /**
  823. * Calls the `doToggle` callback when it is deemed that the user is not moving towards
  824. * the submenu.
  825. * @param doToggle the function called when the user is not moving towards the submenu.
  826. */
  827. toggle(doToggle: () => void): void;
  828. /**
  829. * Start the delayed toggle handler if one isn't running already.
  830. *
  831. * The delayed toggle handler executes the `doToggle` callback after some period of time iff the
  832. * users mouse is on an item in the current menu.
  833. *
  834. * @param doToggle the function called when the user is not moving towards the submenu.
  835. */
  836. private _startTimeout;
  837. /** Whether the user is heading towards the open submenu. */
  838. private _isMovingToSubmenu;
  839. /** Get the bounding DOMRect for the open submenu. */
  840. private _getSubmenuBounds;
  841. /**
  842. * Check if a reference to the PointerFocusTracker and menu element is provided.
  843. * @throws an error if neither reference is provided.
  844. */
  845. private _checkConfigured;
  846. /** Subscribe to the root menus mouse move events and update the tracked mouse points. */
  847. private _subscribeToMouseMoves;
  848. static ɵfac: i0.ɵɵFactoryDeclaration<TargetMenuAim, never>;
  849. static ɵprov: i0.ɵɵInjectableDeclaration<TargetMenuAim>;
  850. }
  851. /** An element which when hovered over may open or close a menu. */
  852. export declare interface Toggler {
  853. /** Gets the open menu, or undefined if no menu is open. */
  854. getMenu(): Menu | undefined;
  855. }
  856. export { }