index.d.ts 38 KB

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