component.d.ts 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /**
  2. * @license
  3. * Copyright 2018 Google Inc.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a copy
  6. * of this software and associated documentation files (the "Software"), to deal
  7. * in the Software without restriction, including without limitation the rights
  8. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. * copies of the Software, and to permit persons to whom the Software is
  10. * furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in
  13. * all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. * THE SOFTWARE.
  22. */
  23. import { MDCComponent } from '@material/base/component';
  24. import { MDCListFactory } from '@material/list/component';
  25. import { MDCListIndex } from '@material/list/types';
  26. import { MDCMenuSurfaceFactory } from '@material/menu-surface/component';
  27. import { Corner } from '@material/menu-surface/constants';
  28. import { MDCMenuDistance } from '@material/menu-surface/types';
  29. import { DefaultFocusState } from './constants';
  30. import { MDCMenuFoundation } from './foundation';
  31. /** MDC Menu Factory */
  32. export declare type MDCMenuFactory = (el: HTMLElement, foundation?: MDCMenuFoundation) => MDCMenu;
  33. /** MDC Menu */
  34. export declare class MDCMenu extends MDCComponent<MDCMenuFoundation> {
  35. static attachTo(root: HTMLElement): MDCMenu;
  36. private menuSurfaceFactory;
  37. private listFactory;
  38. private menuSurface;
  39. private list;
  40. private handleKeydown;
  41. private handleItemAction;
  42. private handleMenuSurfaceOpened;
  43. initialize(menuSurfaceFactory?: MDCMenuSurfaceFactory, listFactory?: MDCListFactory): void;
  44. initialSyncWithDOM(): void;
  45. destroy(): void;
  46. get open(): boolean;
  47. set open(value: boolean);
  48. get wrapFocus(): boolean;
  49. set wrapFocus(value: boolean);
  50. /**
  51. * Sets whether the menu has typeahead functionality.
  52. * @param value Whether typeahead is enabled.
  53. */
  54. set hasTypeahead(value: boolean);
  55. /**
  56. * @return Whether typeahead logic is currently matching some user prefix.
  57. */
  58. get typeaheadInProgress(): boolean;
  59. /**
  60. * Given the next desired character from the user, adds it to the typeahead
  61. * buffer. Then, attempts to find the next option matching the buffer. Wraps
  62. * around if at the end of options.
  63. *
  64. * @param nextChar The next character to add to the prefix buffer.
  65. * @param startingIndex The index from which to start matching. Only relevant
  66. * when starting a new match sequence. To start a new match sequence,
  67. * clear the buffer using `clearTypeaheadBuffer`, or wait for the buffer
  68. * to clear after a set interval defined in list foundation. Defaults to
  69. * the currently focused index.
  70. * @return The index of the matched item, or -1 if no match.
  71. */
  72. typeaheadMatchItem(nextChar: string, startingIndex?: number): number;
  73. /**
  74. * Layout the underlying list element in the case of any dynamic updates
  75. * to its structure.
  76. */
  77. layout(): void;
  78. /**
  79. * Return the items within the menu. Note that this only contains the set of
  80. * elements within the items container that are proper list items, and not
  81. * supplemental / presentational DOM elements.
  82. */
  83. get items(): HTMLElement[];
  84. /**
  85. * Turns on/off the underlying list's single selection mode. Used mainly
  86. * by select menu.
  87. *
  88. * @param singleSelection Whether to enable single selection mode.
  89. */
  90. set singleSelection(singleSelection: boolean);
  91. /**
  92. * Retrieves the selected index. Only applicable to select menus.
  93. * @return The selected index, which is a number for single selection and
  94. * radio lists, and an array of numbers for checkbox lists.
  95. */
  96. get selectedIndex(): MDCListIndex;
  97. /**
  98. * Sets the selected index of the list. Only applicable to select menus.
  99. * @param index The selected index, which is a number for single selection and
  100. * radio lists, and an array of numbers for checkbox lists.
  101. */
  102. set selectedIndex(index: MDCListIndex);
  103. set quickOpen(quickOpen: boolean);
  104. /**
  105. * Sets default focus state where the menu should focus every time when menu
  106. * is opened. Focuses the list root (`DefaultFocusState.LIST_ROOT`) element by
  107. * default.
  108. * @param focusState Default focus state.
  109. */
  110. setDefaultFocusState(focusState: DefaultFocusState): void;
  111. /**
  112. * @param corner Default anchor corner alignment of top-left menu corner.
  113. */
  114. setAnchorCorner(corner: Corner): void;
  115. setAnchorMargin(margin: Partial<MDCMenuDistance>): void;
  116. /**
  117. * Sets the list item as the selected row at the specified index.
  118. * @param index Index of list item within menu.
  119. */
  120. setSelectedIndex(index: number): void;
  121. /**
  122. * Sets the enabled state to isEnabled for the menu item at the given index.
  123. * @param index Index of the menu item
  124. * @param isEnabled The desired enabled state of the menu item.
  125. */
  126. setEnabled(index: number, isEnabled: boolean): void;
  127. /**
  128. * @return The item within the menu at the index specified.
  129. */
  130. getOptionByIndex(index: number): Element | null;
  131. /**
  132. * @param index A menu item's index.
  133. * @return The primary text within the menu at the index specified.
  134. */
  135. getPrimaryTextAtIndex(index: number): string;
  136. setFixedPosition(isFixed: boolean): void;
  137. setIsHoisted(isHoisted: boolean): void;
  138. setAbsolutePosition(x: number, y: number): void;
  139. /**
  140. * Sets the element that the menu-surface is anchored to.
  141. */
  142. setAnchorElement(element: Element): void;
  143. getDefaultFoundation(): MDCMenuFoundation;
  144. }