@material/web 1.3.0 → 1.3.1-nightly.c6ffd70.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (138) hide show
  1. package/button/elevated-button.d.ts +2 -1
  2. package/button/elevated-button.js.map +1 -1
  3. package/button/filled-button.d.ts +2 -1
  4. package/button/filled-button.js +5 -1
  5. package/button/filled-button.js.map +1 -1
  6. package/button/filled-tonal-button.d.ts +2 -1
  7. package/button/filled-tonal-button.js +5 -1
  8. package/button/filled-tonal-button.js.map +1 -1
  9. package/button/outlined-button.d.ts +2 -1
  10. package/button/outlined-button.js.map +1 -1
  11. package/button/text-button.d.ts +2 -1
  12. package/button/text-button.js.map +1 -1
  13. package/checkbox/checkbox.d.ts +2 -1
  14. package/checkbox/checkbox.js.map +1 -1
  15. package/chips/assist-chip.d.ts +2 -1
  16. package/chips/assist-chip.js.map +1 -1
  17. package/chips/chip-set.d.ts +2 -1
  18. package/chips/chip-set.js.map +1 -1
  19. package/chips/filter-chip.d.ts +2 -1
  20. package/chips/filter-chip.js.map +1 -1
  21. package/chips/input-chip.d.ts +2 -1
  22. package/chips/input-chip.js.map +1 -1
  23. package/chips/suggestion-chip.d.ts +2 -1
  24. package/chips/suggestion-chip.js.map +1 -1
  25. package/dialog/dialog.d.ts +2 -1
  26. package/dialog/dialog.js.map +1 -1
  27. package/dialog/internal/dialog.d.ts +5 -0
  28. package/dialog/internal/dialog.js +24 -2
  29. package/dialog/internal/dialog.js.map +1 -1
  30. package/divider/divider.d.ts +2 -1
  31. package/divider/divider.js.map +1 -1
  32. package/elevation/elevation.d.ts +5 -1
  33. package/elevation/elevation.js +3 -0
  34. package/elevation/elevation.js.map +1 -1
  35. package/fab/branded-fab.d.ts +2 -1
  36. package/fab/branded-fab.js.map +1 -1
  37. package/fab/fab.d.ts +2 -1
  38. package/fab/fab.js.map +1 -1
  39. package/field/filled-field.d.ts +2 -1
  40. package/field/filled-field.js.map +1 -1
  41. package/field/outlined-field.d.ts +2 -1
  42. package/field/outlined-field.js.map +1 -1
  43. package/focus/md-focus-ring.d.ts +2 -1
  44. package/focus/md-focus-ring.js.map +1 -1
  45. package/icon/icon.d.ts +2 -1
  46. package/icon/icon.js.map +1 -1
  47. package/iconbutton/filled-icon-button.d.ts +5 -1
  48. package/iconbutton/filled-icon-button.js +3 -0
  49. package/iconbutton/filled-icon-button.js.map +1 -1
  50. package/iconbutton/filled-tonal-icon-button.d.ts +5 -1
  51. package/iconbutton/filled-tonal-icon-button.js +3 -0
  52. package/iconbutton/filled-tonal-icon-button.js.map +1 -1
  53. package/iconbutton/icon-button.d.ts +5 -1
  54. package/iconbutton/icon-button.js +3 -0
  55. package/iconbutton/icon-button.js.map +1 -1
  56. package/iconbutton/outlined-icon-button.d.ts +5 -1
  57. package/iconbutton/outlined-icon-button.js +3 -0
  58. package/iconbutton/outlined-icon-button.js.map +1 -1
  59. package/labs/badge/badge.d.ts +2 -1
  60. package/labs/badge/badge.js.map +1 -1
  61. package/labs/card/elevated-card.d.ts +2 -1
  62. package/labs/card/elevated-card.js.map +1 -1
  63. package/labs/card/filled-card.d.ts +2 -1
  64. package/labs/card/filled-card.js.map +1 -1
  65. package/labs/card/outlined-card.d.ts +2 -1
  66. package/labs/card/outlined-card.js.map +1 -1
  67. package/labs/item/item.d.ts +5 -1
  68. package/labs/item/item.js +3 -0
  69. package/labs/item/item.js.map +1 -1
  70. package/labs/navigationbar/navigation-bar.d.ts +2 -1
  71. package/labs/navigationbar/navigation-bar.js.map +1 -1
  72. package/labs/navigationtab/navigation-tab.d.ts +2 -1
  73. package/labs/navigationtab/navigation-tab.js.map +1 -1
  74. package/labs/segmentedbutton/outlined-segmented-button.d.ts +2 -1
  75. package/labs/segmentedbutton/outlined-segmented-button.js.map +1 -1
  76. package/labs/segmentedbuttonset/outlined-segmented-button-set.d.ts +2 -1
  77. package/labs/segmentedbuttonset/outlined-segmented-button-set.js.map +1 -1
  78. package/list/internal/list-controller.d.ts +6 -0
  79. package/list/internal/list-controller.js +16 -10
  80. package/list/internal/list-controller.js.map +1 -1
  81. package/list/internal/list-navigation-helpers.d.ts +8 -4
  82. package/list/internal/list-navigation-helpers.js +18 -6
  83. package/list/internal/list-navigation-helpers.js.map +1 -1
  84. package/list/list-item.d.ts +2 -1
  85. package/list/list-item.js.map +1 -1
  86. package/list/list.d.ts +2 -1
  87. package/list/list.js.map +1 -1
  88. package/menu/internal/menu.d.ts +6 -0
  89. package/menu/internal/menu.js +10 -0
  90. package/menu/internal/menu.js.map +1 -1
  91. package/menu/menu-item.d.ts +2 -1
  92. package/menu/menu-item.js.map +1 -1
  93. package/menu/menu.d.ts +3 -2
  94. package/menu/menu.js +1 -1
  95. package/menu/menu.js.map +1 -1
  96. package/menu/sub-menu.d.ts +2 -1
  97. package/menu/sub-menu.js +1 -1
  98. package/menu/sub-menu.js.map +1 -1
  99. package/package.json +1 -1
  100. package/progress/circular-progress.d.ts +5 -1
  101. package/progress/circular-progress.js +3 -0
  102. package/progress/circular-progress.js.map +1 -1
  103. package/progress/internal/linear-progress.d.ts +1 -0
  104. package/progress/internal/linear-progress.js +7 -3
  105. package/progress/internal/linear-progress.js.map +1 -1
  106. package/progress/linear-progress.d.ts +5 -1
  107. package/progress/linear-progress.js +3 -0
  108. package/progress/linear-progress.js.map +1 -1
  109. package/radio/radio.d.ts +2 -1
  110. package/radio/radio.js.map +1 -1
  111. package/ripple/ripple.d.ts +2 -1
  112. package/ripple/ripple.js.map +1 -1
  113. package/select/filled-select.d.ts +2 -1
  114. package/select/filled-select.js.map +1 -1
  115. package/select/internal/select.js +1 -0
  116. package/select/internal/select.js.map +1 -1
  117. package/select/outlined-select.d.ts +2 -1
  118. package/select/outlined-select.js.map +1 -1
  119. package/select/select-option.d.ts +2 -1
  120. package/select/select-option.js.map +1 -1
  121. package/slider/slider.d.ts +5 -1
  122. package/slider/slider.js +3 -0
  123. package/slider/slider.js.map +1 -1
  124. package/switch/switch.d.ts +2 -1
  125. package/switch/switch.js.map +1 -1
  126. package/tabs/primary-tab.d.ts +4 -1
  127. package/tabs/primary-tab.js +2 -0
  128. package/tabs/primary-tab.js.map +1 -1
  129. package/tabs/secondary-tab.d.ts +4 -1
  130. package/tabs/secondary-tab.js +2 -0
  131. package/tabs/secondary-tab.js.map +1 -1
  132. package/tabs/tabs.d.ts +4 -1
  133. package/tabs/tabs.js +2 -0
  134. package/tabs/tabs.js.map +1 -1
  135. package/textfield/filled-text-field.d.ts +2 -1
  136. package/textfield/filled-text-field.js.map +1 -1
  137. package/textfield/outlined-text-field.d.ts +2 -1
  138. package/textfield/outlined-text-field.js.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"outlined-segmented-button-set.js","sourceRoot":"","sources":["outlined-segmented-button-set.ts"],"names":[],"mappings":"AAAA;;;;GAIG;;AAEH,OAAO,EAAC,aAAa,EAAC,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAC,0BAA0B,EAAC,MAAM,6CAA6C,CAAC;AACvF,OAAO,EAAC,MAAM,IAAI,cAAc,EAAC,MAAM,mCAAmC,CAAC;AAC3E,OAAO,EAAC,MAAM,IAAI,YAAY,EAAC,MAAM,iCAAiC,CAAC;AAQvE;;;;;GAKG;AAEI,WAAM,4BAA4B,GAAlC,MAAM,4BAA6B,SAAQ,0BAA0B;;AAC1D,mCAAM,GAAG,CAAC,YAAY,EAAE,cAAc,CAAC,AAAjC,CAAkC;AAD7C,4BAA4B;IADxC,aAAa,CAAC,kCAAkC,CAAC;GACrC,4BAA4B,CAExC","sourcesContent":["/**\n * @license\n * Copyright 2022 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {customElement} from 'lit/decorators.js';\n\nimport {OutlinedSegmentedButtonSet} from './internal/outlined-segmented-button-set.js';\nimport {styles as outlinedStyles} from './internal/outlined-styles.css.js';\nimport {styles as sharedStyles} from './internal/shared-styles.css.js';\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'md-outlined-segmented-button-set': MdOutlinedSegmentedButtonSet;\n }\n}\n\n/**\n * MdOutlinedSegmentedButtonSet is the custom element for the Material\n * Design outlined segmented button set component.\n * @final\n * @suppress {visibility}\n */\n@customElement('md-outlined-segmented-button-set')\nexport class MdOutlinedSegmentedButtonSet extends OutlinedSegmentedButtonSet {\n static override styles = [sharedStyles, outlinedStyles];\n}\n"]}
1
+ {"version":3,"file":"outlined-segmented-button-set.js","sourceRoot":"","sources":["outlined-segmented-button-set.ts"],"names":[],"mappings":"AAAA;;;;GAIG;;AAGH,OAAO,EAAC,aAAa,EAAC,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAC,0BAA0B,EAAC,MAAM,6CAA6C,CAAC;AACvF,OAAO,EAAC,MAAM,IAAI,cAAc,EAAC,MAAM,mCAAmC,CAAC;AAC3E,OAAO,EAAC,MAAM,IAAI,YAAY,EAAC,MAAM,iCAAiC,CAAC;AAQvE;;;;;GAKG;AAEI,WAAM,4BAA4B,GAAlC,MAAM,4BAA6B,SAAQ,0BAA0B;;AAC1D,mCAAM,GAAwB,CAAC,YAAY,EAAE,cAAc,CAAC,AAAtD,CAAuD;AADlE,4BAA4B;IADxC,aAAa,CAAC,kCAAkC,CAAC;GACrC,4BAA4B,CAExC","sourcesContent":["/**\n * @license\n * Copyright 2022 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {CSSResultOrNative} from 'lit';\nimport {customElement} from 'lit/decorators.js';\n\nimport {OutlinedSegmentedButtonSet} from './internal/outlined-segmented-button-set.js';\nimport {styles as outlinedStyles} from './internal/outlined-styles.css.js';\nimport {styles as sharedStyles} from './internal/shared-styles.css.js';\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'md-outlined-segmented-button-set': MdOutlinedSegmentedButtonSet;\n }\n}\n\n/**\n * MdOutlinedSegmentedButtonSet is the custom element for the Material\n * Design outlined segmented button set component.\n * @final\n * @suppress {visibility}\n */\n@customElement('md-outlined-segmented-button-set')\nexport class MdOutlinedSegmentedButtonSet extends OutlinedSegmentedButtonSet {\n static override styles: CSSResultOrNative[] = [sharedStyles, outlinedStyles];\n}\n"]}
@@ -55,6 +55,11 @@ export interface ListControllerConfig<Item extends ListItem> {
55
55
  * disabled.
56
56
  */
57
57
  isActivatable?: (item: Item) => boolean;
58
+ /**
59
+ * Whether or not navigating past the end of the list wraps to the beginning
60
+ * and vice versa. Defaults to true.
61
+ */
62
+ wrapNavigation?: () => boolean;
58
63
  }
59
64
  /**
60
65
  * A controller that handles list keyboard navigation and item management.
@@ -67,6 +72,7 @@ export declare class ListController<Item extends ListItem> {
67
72
  private readonly activateItem;
68
73
  private readonly isNavigableKey;
69
74
  private readonly isActivatable?;
75
+ private readonly wrapNavigation;
70
76
  constructor(config: ListControllerConfig<Item>);
71
77
  /**
72
78
  * The items being managed by the list. Additionally, attempts to see if the
@@ -38,9 +38,6 @@ export class ListController {
38
38
  return;
39
39
  }
40
40
  const activeItemRecord = getActiveItem(items, this.isActivatable);
41
- if (activeItemRecord) {
42
- activeItemRecord.item.tabIndex = -1;
43
- }
44
41
  event.preventDefault();
45
42
  const isRtl = this.isRtl();
46
43
  const inlinePrevious = isRtl
@@ -49,28 +46,36 @@ export class ListController {
49
46
  const inlineNext = isRtl
50
47
  ? NavigableKeys.ArrowLeft
51
48
  : NavigableKeys.ArrowRight;
49
+ let nextActiveItem = null;
52
50
  switch (key) {
53
51
  // Activate the next item
54
52
  case NavigableKeys.ArrowDown:
55
53
  case inlineNext:
56
- activateNextItem(items, activeItemRecord, this.isActivatable);
54
+ nextActiveItem = activateNextItem(items, activeItemRecord, this.isActivatable, this.wrapNavigation());
57
55
  break;
58
56
  // Activate the previous item
59
57
  case NavigableKeys.ArrowUp:
60
58
  case inlinePrevious:
61
- activatePreviousItem(items, activeItemRecord, this.isActivatable);
59
+ nextActiveItem = activatePreviousItem(items, activeItemRecord, this.isActivatable, this.wrapNavigation());
62
60
  break;
63
61
  // Activate the first item
64
62
  case NavigableKeys.Home:
65
- activateFirstItem(items, this.isActivatable);
63
+ nextActiveItem = activateFirstItem(items, this.isActivatable);
66
64
  break;
67
65
  // Activate the last item
68
66
  case NavigableKeys.End:
69
- activateLastItem(items, this.isActivatable);
67
+ nextActiveItem = activateLastItem(items, this.isActivatable);
70
68
  break;
71
69
  default:
72
70
  break;
73
71
  }
72
+ if (nextActiveItem &&
73
+ activeItemRecord &&
74
+ activeItemRecord.item !== nextActiveItem) {
75
+ // If a new item was activated, remove the tabindex of the previous
76
+ // activated item.
77
+ activeItemRecord.item.tabIndex = -1;
78
+ }
74
79
  };
75
80
  /**
76
81
  * Listener to be bound to the `deactivate-items` item event.
@@ -117,7 +122,7 @@ export class ListController {
117
122
  }
118
123
  firstActivatableItem.tabIndex = 0;
119
124
  };
120
- const { isItem, getPossibleItems, isRtl, deactivateItem, activateItem, isNavigableKey, isActivatable, } = config;
125
+ const { isItem, getPossibleItems, isRtl, deactivateItem, activateItem, isNavigableKey, isActivatable, wrapNavigation, } = config;
121
126
  this.isItem = isItem;
122
127
  this.getPossibleItems = getPossibleItems;
123
128
  this.isRtl = isRtl;
@@ -125,6 +130,7 @@ export class ListController {
125
130
  this.activateItem = activateItem;
126
131
  this.isNavigableKey = isNavigableKey;
127
132
  this.isActivatable = isActivatable;
133
+ this.wrapNavigation = wrapNavigation ?? (() => true);
128
134
  }
129
135
  /**
130
136
  * The items being managed by the list. Additionally, attempts to see if the
@@ -160,7 +166,7 @@ export class ListController {
160
166
  if (activeItemRecord) {
161
167
  activeItemRecord.item.tabIndex = -1;
162
168
  }
163
- return activateNextItem(items, activeItemRecord, this.isActivatable);
169
+ return activateNextItem(items, activeItemRecord, this.isActivatable, this.wrapNavigation());
164
170
  }
165
171
  /**
166
172
  * Activates the previous item in the list. If at the start of the list, the
@@ -174,7 +180,7 @@ export class ListController {
174
180
  if (activeItemRecord) {
175
181
  activeItemRecord.item.tabIndex = -1;
176
182
  }
177
- return activatePreviousItem(items, activeItemRecord, this.isActivatable);
183
+ return activatePreviousItem(items, activeItemRecord, this.isActivatable, this.wrapNavigation());
178
184
  }
179
185
  }
180
186
  //# sourceMappingURL=list-controller.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"list-controller.js","sourceRoot":"","sources":["list-controller.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,oBAAoB,EACpB,aAAa,EACb,uBAAuB,GAExB,MAAM,8BAA8B,CAAC;AAEtC,sDAAsD;AAEtD;;GAEG;AACH,0DAA0D;AAC1D,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,SAAS,EAAE,WAAW;IACtB,SAAS,EAAE,WAAW;IACtB,OAAO,EAAE,SAAS;IAClB,UAAU,EAAE,YAAY;IACxB,IAAI,EAAE,MAAM;IACZ,GAAG,EAAE,KAAK;CACF,CAAC;AA8CX;;GAEG;AACH,MAAM,OAAO,cAAc;IASzB,YAAY,MAAkC;QA6C9C;;;WAGG;QACH,kBAAa,GAAG,CAAC,KAAoB,EAAE,EAAE;YACvC,MAAM,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC;YACtB,IAAI,KAAK,CAAC,gBAAgB,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE;gBACvD,OAAO;aACR;YACD,sEAAsE;YACtE,iCAAiC;YACjC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;YAEzB,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE;gBACjB,OAAO;aACR;YAED,MAAM,gBAAgB,GAAG,aAAa,CAAC,KAAK,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;YAElE,IAAI,gBAAgB,EAAE;gBACpB,gBAAgB,CAAC,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC;aACrC;YAED,KAAK,CAAC,cAAc,EAAE,CAAC;YAEvB,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC;YAC3B,MAAM,cAAc,GAAG,KAAK;gBAC1B,CAAC,CAAC,a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E,CAAC;CA4DF","sourcesContent":["/**\n * @license\n * Copyright 2023 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n activateFirstItem,\n activateLastItem,\n activateNextItem,\n activatePreviousItem,\n getActiveItem,\n getFirstActivatableItem,\n ListItem,\n} from './list-navigation-helpers.js';\n\n// TODO: move this file to List and make List use this\n\n/**\n * Default keys that trigger navigation.\n */\n// tslint:disable:enforce-name-casing Following Enum style\nexport const NavigableKeys = {\n ArrowDown: 'ArrowDown',\n ArrowLeft: 'ArrowLeft',\n ArrowUp: 'ArrowUp',\n ArrowRight: 'ArrowRight',\n Home: 'Home',\n End: 'End',\n} as const;\n// tslint:enable:enforce-name-casing\n\n/**\n * Default set of navigable keys.\n */\nexport type NavigableKeys = (typeof NavigableKeys)[keyof typeof NavigableKeys];\n\n/**\n * The configuration object to customize the behavior of the List Controller\n */\nexport interface ListControllerConfig<Item extends ListItem> {\n /**\n * A function that determines whether or not the given element is an Item\n */\n isItem: (item: HTMLElement) => item is Item;\n /**\n * A function that returns an array of elements to consider as items. For\n * example, all the slotted elements.\n */\n getPossibleItems: () => HTMLElement[];\n /**\n * A function that returns whether or not the list is in an RTL context.\n */\n isRtl: () => boolean;\n /**\n * Deactivates an item such as setting the tabindex to -1 and or sets selected\n * to false.\n */\n deactivateItem: (item: Item) => void;\n /**\n * Activates an item such as setting the tabindex to 1 and or sets selected to\n * true (but does not focus).\n */\n activateItem: (item: Item) => void;\n /**\n * Whether or not the key should be handled by the list for navigation.\n */\n isNavigableKey: (key: string) => boolean;\n /**\n * Whether or not the item can be activated. Defaults to items that are not\n * disabled.\n */\n isActivatable?: (item: Item) => boolean;\n}\n\n/**\n * A controller that handles list keyboard navigation and item management.\n */\nexport class ListController<Item extends ListItem> {\n isItem: (item: HTMLElement) => item is Item;\n private readonly getPossibleItems: () => HTMLElement[];\n private readonly isRtl: () => boolean;\n private readonly deactivateItem: (item: Item) => void;\n private readonly activateItem: (item: Item) => void;\n private readonly isNavigableKey: (key: string) => boolean;\n private readonly isActivatable?: (item: Item) => boolean;\n\n constructor(config: ListControllerConfig<Item>) {\n const {\n isItem,\n getPossibleItems,\n isRtl,\n deactivateItem,\n activateItem,\n isNavigableKey,\n isActivatable,\n } = config;\n this.isItem = isItem;\n this.getPossibleItems = getPossibleItems;\n this.isRtl = isRtl;\n this.deactivateItem = deactivateItem;\n this.activateItem = activateItem;\n this.isNavigableKey = isNavigableKey;\n this.isActivatable = isActivatable;\n }\n\n /**\n * The items being managed by the list. Additionally, attempts to see if the\n * object has a sub-item in the `.item` property.\n */\n get items(): Item[] {\n const maybeItems = this.getPossibleItems();\n const items: Item[] = [];\n\n for (const itemOrParent of maybeItems) {\n const isItem = this.isItem(itemOrParent);\n // if the item is a list item, add it to the list of items\n if (isItem) {\n items.push(itemOrParent);\n continue;\n }\n\n // If the item exposes an `item` property check if it is a list item.\n const subItem = (itemOrParent as HTMLElement & {item?: Item}).item;\n if (subItem && this.isItem(subItem)) {\n items.push(subItem);\n }\n }\n\n return items;\n }\n\n /**\n * Handles keyboard navigation. Should be bound to the node that will act as\n * the List.\n */\n handleKeydown = (event: KeyboardEvent) => {\n const key = event.key;\n if (event.defaultPrevented || !this.isNavigableKey(key)) {\n return;\n }\n // do not use this.items directly in upcoming calculations so we don't\n // re-query the DOM unnecessarily\n const items = this.items;\n\n if (!items.length) {\n return;\n }\n\n const activeItemRecord = getActiveItem(items, this.isActivatable);\n\n if (activeItemRecord) {\n activeItemRecord.item.tabIndex = -1;\n }\n\n event.preventDefault();\n\n const isRtl = this.isRtl();\n const inlinePrevious = isRtl\n ? NavigableKeys.ArrowRight\n : NavigableKeys.ArrowLeft;\n const inlineNext = isRtl\n ? NavigableKeys.ArrowLeft\n : NavigableKeys.ArrowRight;\n\n switch (key) {\n // Activate the next item\n case NavigableKeys.ArrowDown:\n case inlineNext:\n activateNextItem(items, activeItemRecord, this.isActivatable);\n break;\n\n // Activate the previous item\n case NavigableKeys.ArrowUp:\n case inlinePrevious:\n activatePreviousItem(items, activeItemRecord, this.isActivatable);\n break;\n\n // Activate the first item\n case NavigableKeys.Home:\n activateFirstItem(items, this.isActivatable);\n break;\n\n // Activate the last item\n case NavigableKeys.End:\n activateLastItem(items, this.isActivatable);\n break;\n\n default:\n break;\n }\n };\n\n /**\n * Activates the next item in the list. If at the end of the list, the first\n * item will be activated.\n *\n * @return The activated list item or `null` if there are no items.\n */\n activateNextItem(): Item | null {\n const items = this.items;\n const activeItemRecord = getActiveItem(items, this.isActivatable);\n if (activeItemRecord) {\n activeItemRecord.item.tabIndex = -1;\n }\n return activateNextItem(items, activeItemRecord, this.isActivatable);\n }\n\n /**\n * Activates the previous item in the list. If at the start of the list, the\n * last item will be activated.\n *\n * @return The activated list item or `null` if there are no items.\n */\n activatePreviousItem(): Item | null {\n const items = this.items;\n const activeItemRecord = getActiveItem(items, this.isActivatable);\n if (activeItemRecord) {\n activeItemRecord.item.tabIndex = -1;\n }\n return activatePreviousItem(items, activeItemRecord, this.isActivatable);\n }\n\n /**\n * Listener to be bound to the `deactivate-items` item event.\n */\n onDeactivateItems = () => {\n const items = this.items;\n\n for (const item of items) {\n this.deactivateItem(item);\n }\n };\n\n /**\n * Listener to be bound to the `request-activation` item event..\n */\n onRequestActivation = (event: Event) => {\n this.onDeactivateItems();\n const target = event.target as Item;\n this.activateItem(target);\n target.focus();\n };\n\n /**\n * Listener to be bound to the `slotchange` event for the slot that renders\n * the items.\n */\n onSlotchange = () => {\n const items = this.items;\n // Whether we have encountered an item that has been activated\n let encounteredActivated = false;\n\n for (const item of items) {\n const isActivated = !item.disabled && item.tabIndex > -1;\n\n if (isActivated && !encounteredActivated) {\n encounteredActivated = true;\n item.tabIndex = 0;\n continue;\n }\n\n // Deactivate the rest including disabled\n item.tabIndex = -1;\n }\n\n if (encounteredActivated) {\n return;\n }\n\n const firstActivatableItem = getFirstActivatableItem(\n items,\n this.isActivatable,\n );\n\n if (!firstActivatableItem) {\n return;\n }\n\n firstActivatableItem.tabIndex = 0;\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AAG,IAAI,CAAC,KAAK,CAAC;QACzB,MAAM,gBAAgB,GAAG,aAAa,CAAC,KAAK,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;QAClE,IAAI,gBAAgB,EAAE;YACpB,gBAAgB,CAAC,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC;SACrC;QACD,OAAO,oBAAoB,CACzB,KAAK,EACL,gBAAgB,EAChB,IAAI,CAAC,aAAa,EAClB,IAAI,CAAC,cAAc,EAAE,CACtB,CAAC;IACJ,CAAC;CA4DF","sourcesContent":["/**\n * @license\n * Copyright 2023 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n activateFirstItem,\n activateLastItem,\n activateNextItem,\n activatePreviousItem,\n getActiveItem,\n getFirstActivatableItem,\n ListItem,\n} from './list-navigation-helpers.js';\n\n// TODO: move this file to List and make List use this\n\n/**\n * Default keys that trigger navigation.\n */\n// tslint:disable:enforce-name-casing Following Enum style\nexport const NavigableKeys = {\n ArrowDown: 'ArrowDown',\n ArrowLeft: 'ArrowLeft',\n ArrowUp: 'ArrowUp',\n ArrowRight: 'ArrowRight',\n Home: 'Home',\n End: 'End',\n} as const;\n// tslint:enable:enforce-name-casing\n\n/**\n * Default set of navigable keys.\n */\nexport type NavigableKeys = (typeof NavigableKeys)[keyof typeof NavigableKeys];\n\n/**\n * The configuration object to customize the behavior of the List Controller\n */\nexport interface ListControllerConfig<Item extends ListItem> {\n /**\n * A function that determines whether or not the given element is an Item\n */\n isItem: (item: HTMLElement) => item is Item;\n /**\n * A function that returns an array of elements to consider as items. For\n * example, all the slotted elements.\n */\n getPossibleItems: () => HTMLElement[];\n /**\n * A function that returns whether or not the list is in an RTL context.\n */\n isRtl: () => boolean;\n /**\n * Deactivates an item such as setting the tabindex to -1 and or sets selected\n * to false.\n */\n deactivateItem: (item: Item) => void;\n /**\n * Activates an item such as setting the tabindex to 1 and or sets selected to\n * true (but does not focus).\n */\n activateItem: (item: Item) => void;\n /**\n * Whether or not the key should be handled by the list for navigation.\n */\n isNavigableKey: (key: string) => boolean;\n /**\n * Whether or not the item can be activated. Defaults to items that are not\n * disabled.\n */\n isActivatable?: (item: Item) => boolean;\n /**\n * Whether or not navigating past the end of the list wraps to the beginning\n * and vice versa. Defaults to true.\n */\n wrapNavigation?: () => boolean;\n}\n\n/**\n * A controller that handles list keyboard navigation and item management.\n */\nexport class ListController<Item extends ListItem> {\n isItem: (item: HTMLElement) => item is Item;\n private readonly getPossibleItems: () => HTMLElement[];\n private readonly isRtl: () => boolean;\n private readonly deactivateItem: (item: Item) => void;\n private readonly activateItem: (item: Item) => void;\n private readonly isNavigableKey: (key: string) => boolean;\n private readonly isActivatable?: (item: Item) => boolean;\n private readonly wrapNavigation: () => boolean;\n\n constructor(config: ListControllerConfig<Item>) {\n const {\n isItem,\n getPossibleItems,\n isRtl,\n deactivateItem,\n activateItem,\n isNavigableKey,\n isActivatable,\n wrapNavigation,\n } = config;\n this.isItem = isItem;\n this.getPossibleItems = getPossibleItems;\n this.isRtl = isRtl;\n this.deactivateItem = deactivateItem;\n this.activateItem = activateItem;\n this.isNavigableKey = isNavigableKey;\n this.isActivatable = isActivatable;\n this.wrapNavigation = wrapNavigation ?? (() => true);\n }\n\n /**\n * The items being managed by the list. Additionally, attempts to see if the\n * object has a sub-item in the `.item` property.\n */\n get items(): Item[] {\n const maybeItems = this.getPossibleItems();\n const items: Item[] = [];\n\n for (const itemOrParent of maybeItems) {\n const isItem = this.isItem(itemOrParent);\n // if the item is a list item, add it to the list of items\n if (isItem) {\n items.push(itemOrParent);\n continue;\n }\n\n // If the item exposes an `item` property check if it is a list item.\n const subItem = (itemOrParent as HTMLElement & {item?: Item}).item;\n if (subItem && this.isItem(subItem)) {\n items.push(subItem);\n }\n }\n\n return items;\n }\n\n /**\n * Handles keyboard navigation. Should be bound to the node that will act as\n * the List.\n */\n handleKeydown = (event: KeyboardEvent) => {\n const key = event.key;\n if (event.defaultPrevented || !this.isNavigableKey(key)) {\n return;\n }\n // do not use this.items directly in upcoming calculations so we don't\n // re-query the DOM unnecessarily\n const items = this.items;\n\n if (!items.length) {\n return;\n }\n\n const activeItemRecord = getActiveItem(items, this.isActivatable);\n\n event.preventDefault();\n\n const isRtl = this.isRtl();\n const inlinePrevious = isRtl\n ? NavigableKeys.ArrowRight\n : NavigableKeys.ArrowLeft;\n const inlineNext = isRtl\n ? NavigableKeys.ArrowLeft\n : NavigableKeys.ArrowRight;\n\n let nextActiveItem: Item | null = null;\n switch (key) {\n // Activate the next item\n case NavigableKeys.ArrowDown:\n case inlineNext:\n nextActiveItem = activateNextItem(\n items,\n activeItemRecord,\n this.isActivatable,\n this.wrapNavigation(),\n );\n break;\n\n // Activate the previous item\n case NavigableKeys.ArrowUp:\n case inlinePrevious:\n nextActiveItem = activatePreviousItem(\n items,\n activeItemRecord,\n this.isActivatable,\n this.wrapNavigation(),\n );\n break;\n\n // Activate the first item\n case NavigableKeys.Home:\n nextActiveItem = activateFirstItem(items, this.isActivatable);\n break;\n\n // Activate the last item\n case NavigableKeys.End:\n nextActiveItem = activateLastItem(items, this.isActivatable);\n break;\n\n default:\n break;\n }\n\n if (\n nextActiveItem &&\n activeItemRecord &&\n activeItemRecord.item !== nextActiveItem\n ) {\n // If a new item was activated, remove the tabindex of the previous\n // activated item.\n activeItemRecord.item.tabIndex = -1;\n }\n };\n\n /**\n * Activates the next item in the list. If at the end of the list, the first\n * item will be activated.\n *\n * @return The activated list item or `null` if there are no items.\n */\n activateNextItem(): Item | null {\n const items = this.items;\n const activeItemRecord = getActiveItem(items, this.isActivatable);\n if (activeItemRecord) {\n activeItemRecord.item.tabIndex = -1;\n }\n return activateNextItem(\n items,\n activeItemRecord,\n this.isActivatable,\n this.wrapNavigation(),\n );\n }\n\n /**\n * Activates the previous item in the list. If at the start of the list, the\n * last item will be activated.\n *\n * @return The activated list item or `null` if there are no items.\n */\n activatePreviousItem(): Item | null {\n const items = this.items;\n const activeItemRecord = getActiveItem(items, this.isActivatable);\n if (activeItemRecord) {\n activeItemRecord.item.tabIndex = -1;\n }\n return activatePreviousItem(\n items,\n activeItemRecord,\n this.isActivatable,\n this.wrapNavigation(),\n );\n }\n\n /**\n * Listener to be bound to the `deactivate-items` item event.\n */\n onDeactivateItems = () => {\n const items = this.items;\n\n for (const item of items) {\n this.deactivateItem(item);\n }\n };\n\n /**\n * Listener to be bound to the `request-activation` item event..\n */\n onRequestActivation = (event: Event) => {\n this.onDeactivateItems();\n const target = event.target as Item;\n this.activateItem(target);\n target.focus();\n };\n\n /**\n * Listener to be bound to the `slotchange` event for the slot that renders\n * the items.\n */\n onSlotchange = () => {\n const items = this.items;\n // Whether we have encountered an item that has been activated\n let encounteredActivated = false;\n\n for (const item of items) {\n const isActivated = !item.disabled && item.tabIndex > -1;\n\n if (isActivated && !encounteredActivated) {\n encounteredActivated = true;\n item.tabIndex = 0;\n continue;\n }\n\n // Deactivate the rest including disabled\n item.tabIndex = -1;\n }\n\n if (encounteredActivated) {\n return;\n }\n\n const firstActivatableItem = getFirstActivatableItem(\n items,\n this.isActivatable,\n );\n\n if (!firstActivatableItem) {\n return;\n }\n\n firstActivatableItem.tabIndex = 0;\n };\n}\n"]}
@@ -84,9 +84,11 @@ export declare function getLastActivatableItem<Item extends ListItem>(items: Ite
84
84
  * @param index {{index: number}} The index to search from.
85
85
  * @param isActivatable Function to determine if an item can be activated.
86
86
  * Defaults to non-disabled items.
87
+ * @param wrap If true, then the next item at the end of the list is the first
88
+ * item. Defaults to true.
87
89
  * @return The next activatable item or `null` if none are activatable.
88
90
  */
89
- export declare function getNextItem<Item extends ListItem>(items: Item[], index: number, isActivatable?: (item: Item) => boolean): Item;
91
+ export declare function getNextItem<Item extends ListItem>(items: Item[], index: number, isActivatable?: (item: Item) => boolean, wrap?: boolean): Item;
90
92
  /**
91
93
  * Retrieves the previous non-disabled item of a given array of items.
92
94
  *
@@ -94,19 +96,21 @@ export declare function getNextItem<Item extends ListItem>(items: Item[], index:
94
96
  * @param index {{index: number}} The index to search from.
95
97
  * @param isActivatable Function to determine if an item can be activated.
96
98
  * Defaults to non-disabled items.
99
+ * @param wrap If true, then the previous item at the beginning of the list is
100
+ * the last item. Defaults to true.
97
101
  * @return The previous activatable item or `null` if none are activatable.
98
102
  */
99
- export declare function getPrevItem<Item extends ListItem>(items: Item[], index: number, isActivatable?: (item: Item) => boolean): Item;
103
+ export declare function getPrevItem<Item extends ListItem>(items: Item[], index: number, isActivatable?: (item: Item) => boolean, wrap?: boolean): Item;
100
104
  /**
101
105
  * Activates the next item and focuses it. If nothing is currently activated,
102
106
  * activates the first item.
103
107
  */
104
- export declare function activateNextItem<Item extends ListItem>(items: Item[], activeItemRecord: null | ItemRecord<Item>, isActivatable?: (item: Item) => boolean): Item | null;
108
+ export declare function activateNextItem<Item extends ListItem>(items: Item[], activeItemRecord: null | ItemRecord<Item>, isActivatable?: (item: Item) => boolean, wrap?: boolean): Item | null;
105
109
  /**
106
110
  * Activates the previous item and focuses it. If nothing is currently
107
111
  * activated, activates the last item.
108
112
  */
109
- export declare function activatePreviousItem<Item extends ListItem>(items: Item[], activeItemRecord: null | ItemRecord<Item>, isActivatable?: (item: Item) => boolean): Item | null;
113
+ export declare function activatePreviousItem<Item extends ListItem>(items: Item[], activeItemRecord: null | ItemRecord<Item>, isActivatable?: (item: Item) => boolean, wrap?: boolean): Item | null;
110
114
  /**
111
115
  * Creates an event that requests the parent md-list to deactivate all other
112
116
  * items.
@@ -122,11 +122,17 @@ export function getLastActivatableItem(items, isActivatable = (isItemNotDisabled
122
122
  * @param index {{index: number}} The index to search from.
123
123
  * @param isActivatable Function to determine if an item can be activated.
124
124
  * Defaults to non-disabled items.
125
+ * @param wrap If true, then the next item at the end of the list is the first
126
+ * item. Defaults to true.
125
127
  * @return The next activatable item or `null` if none are activatable.
126
128
  */
127
- export function getNextItem(items, index, isActivatable = (isItemNotDisabled)) {
129
+ export function getNextItem(items, index, isActivatable = (isItemNotDisabled), wrap = true) {
128
130
  for (let i = 1; i < items.length; i++) {
129
131
  const nextIndex = (i + index) % items.length;
132
+ if (nextIndex < index && !wrap) {
133
+ // Return if the index loops back to the beginning and not wrapping.
134
+ return null;
135
+ }
130
136
  const item = items[nextIndex];
131
137
  if (isActivatable(item)) {
132
138
  return item;
@@ -141,11 +147,17 @@ export function getNextItem(items, index, isActivatable = (isItemNotDisabled)) {
141
147
  * @param index {{index: number}} The index to search from.
142
148
  * @param isActivatable Function to determine if an item can be activated.
143
149
  * Defaults to non-disabled items.
150
+ * @param wrap If true, then the previous item at the beginning of the list is
151
+ * the last item. Defaults to true.
144
152
  * @return The previous activatable item or `null` if none are activatable.
145
153
  */
146
- export function getPrevItem(items, index, isActivatable = (isItemNotDisabled)) {
154
+ export function getPrevItem(items, index, isActivatable = (isItemNotDisabled), wrap = true) {
147
155
  for (let i = 1; i < items.length; i++) {
148
156
  const prevIndex = (index - i + items.length) % items.length;
157
+ if (prevIndex > index && !wrap) {
158
+ // Return if the index loops back to the end and not wrapping.
159
+ return null;
160
+ }
149
161
  const item = items[prevIndex];
150
162
  if (isActivatable(item)) {
151
163
  return item;
@@ -157,9 +169,9 @@ export function getPrevItem(items, index, isActivatable = (isItemNotDisabled)) {
157
169
  * Activates the next item and focuses it. If nothing is currently activated,
158
170
  * activates the first item.
159
171
  */
160
- export function activateNextItem(items, activeItemRecord, isActivatable = (isItemNotDisabled)) {
172
+ export function activateNextItem(items, activeItemRecord, isActivatable = (isItemNotDisabled), wrap = true) {
161
173
  if (activeItemRecord) {
162
- const next = getNextItem(items, activeItemRecord.index, isActivatable);
174
+ const next = getNextItem(items, activeItemRecord.index, isActivatable, wrap);
163
175
  if (next) {
164
176
  next.tabIndex = 0;
165
177
  next.focus();
@@ -174,9 +186,9 @@ export function activateNextItem(items, activeItemRecord, isActivatable = (isIte
174
186
  * Activates the previous item and focuses it. If nothing is currently
175
187
  * activated, activates the last item.
176
188
  */
177
- export function activatePreviousItem(items, activeItemRecord, isActivatable = (isItemNotDisabled)) {
189
+ export function activatePreviousItem(items, activeItemRecord, isActivatable = (isItemNotDisabled), wrap = true) {
178
190
  if (activeItemRecord) {
179
- const prev = getPrevItem(items, activeItemRecord.index, isActivatable);
191
+ const prev = getPrevItem(items, activeItemRecord.index, isActivatable, wrap);
180
192
  if (prev) {
181
193
  prev.tabIndex = 0;
182
194
  prev.focus();
@@ -1 +1 @@
1
- {"version":3,"file":"list-navigation-helpers.js","sourceRoot":"","sources":["list-navigation-helpers.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAeH;;;;;;;GAOG;AACH,MAAM,UAAU,iBAAiB,CAC/B,KAAa,EACb,gBAAgB,CAAA,iBAAuB,CAAA;IAEvC,yEAAyE;IACzE,yEAAyE;IACzE,UAAU;IACV,MAAM,SAAS,GAAG,uBAAuB,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;IAChE,IAAI,SAAS,EAAE;QACb,SAAS,CAAC,QAAQ,GAAG,CAAC,CAAC;QACvB,SAAS,CAAC,KAAK,EAAE,CAAC;KACnB;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,gBAAgB,CAC9B,KAAa,EACb,gBAAgB,CAAA,iBAAuB,CAAA;IAEvC,MAAM,QAAQ,GAAG,sBAAsB,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;IAC9D,IAAI,QAAQ,EAAE;QACZ,QAAQ,CAAC,QAAQ,GAAG,CAAC,CAAC;QACtB,QAAQ,CAAC,KAAK,EAAE,CAAC;KAClB;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,oBAAoB,CAClC,KAAa,EACb,gBAAgB,CAAA,iBAAuB,CAAA;IAEvC,MAAM,UAAU,GAAG,aAAa,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;IACvD,IAAI,UAAU,EAAE;QACd,UAAU,CAAC,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC;KAC/B;IACD,OAAO,UAAU,CAAC;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QAED,OAAO,IAAI,CAAC;KACb;SAAM;QACL,OAAO,iBAAiB,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;KAChD;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAClC,KAAa,EACb,gBAAyC,EACzC,gBAAgB,CAAA,iBAAuB,CAAA;IAEvC,IAAI,gBAAgB,EAAE;QACpB,MAAM,IAAI,GAAG,WAAW,CAAC,KAAK,EAAE,gBAAgB,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;QACvE,IAAI,IAAI,EAAE;YACR,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC;YAClB,IAAI,CAAC,KAAK,EAAE,CAAC;SACd;QACD,OAAO,IAAI,CAAC;KACb;SAAM;QACL,OAAO,gBAAgB,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;KAC/C;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,0BAA0B;IACxC,OAAO,IAAI,KAAK,CAAC,kBAAkB,EAAE,EAAC,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAC,CAAC,CAAC;AACxE,CAAC;AAUD;;;;;;;GAOG;AACH,MAAM,UAAU,4BAA4B;IAC1C,OAAO,IAAI,KAAK,CAAC,oBAAoB,EAAE,EAAC,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAC,CAAC,CAAC;AAC1E,CAAC;AASD;;;;;;GAMG;AACH,SAAS,iBAAiB,CAAwB,IAAU;IAC1D,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC;AACxB,CAAC","sourcesContent":["/**\n * @license\n * Copyright 2023 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nexport interface ListItem extends HTMLElement {\n disabled: boolean;\n}\n\n/**\n * A record that describes a list item in a list with metadata such a reference\n * to the item and its index in the list.\n */\nexport interface ItemRecord<Item extends ListItem> {\n item: Item;\n index: number;\n}\n\n/**\n * Activates the first non-disabled item of a given array of items.\n *\n * @param items {Array<ListItem>} The items from which to activate the\n * first item.\n * @param isActivatable Function to determine if an item can be activated.\n * Defaults to non-disabled items.\n */\nexport function activateFirstItem<Item extends ListItem>(\n items: Item[],\n isActivatable = isItemNotDisabled<Item>,\n) {\n // NOTE: These selector functions are static and not on the instance such\n // that multiple operations can be chained and we do not have to re-query\n // the DOM\n const firstItem = getFirstActivatableItem(items, isActivatable);\n if (firstItem) {\n firstItem.tabIndex = 0;\n firstItem.focus();\n }\n return firstItem;\n}\n\n/**\n * Activates the last non-disabled item of a given array of items.\n *\n * @param items {Array<ListItem>} The items from which to activate the\n * last item.\n * @param isActivatable Function to determine if an item can be activated.\n * Defaults to non-disabled items.\n * @nocollapse\n */\nexport function activateLastItem<Item extends ListItem>(\n items: Item[],\n isActivatable = isItemNotDisabled<Item>,\n) {\n const lastItem = getLastActivatableItem(items, isActivatable);\n if (lastItem) {\n lastItem.tabIndex = 0;\n lastItem.focus();\n }\n return lastItem;\n}\n\n/**\n * Deactivates the currently active item of a given array of items.\n *\n * @param items {Array<ListItem>} The items from which to deactivate the\n * active item.\n * @param isActivatable Function to determine if an item can be activated.\n * Defaults to non-disabled items.\n * @return A record of the deleselcted activated item including the item and\n * the index of the item or `null` if none are deactivated.\n * @nocollapse\n */\nexport function deactivateActiveItem<Item extends ListItem>(\n items: Item[],\n isActivatable = isItemNotDisabled<Item>,\n) {\n const activeItem = getActiveItem(items, isActivatable);\n if (activeItem) {\n activeItem.item.tabIndex = -1;\n }\n return activeItem;\n}\n\n/**\n * Retrieves the first activated item of a given array of items.\n *\n * @param items {Array<ListItem>} The items to search.\n * @param isActivatable Function to determine if an item can be activated.\n * Defaults to non-disabled items.\n * @return A record of the first activated item including the item and the\n * index of the item or `null` if none are activated.\n * @nocollapse\n */\nexport function getActiveItem<Item extends ListItem>(\n items: Item[],\n isActivatable = isItemNotDisabled<Item>,\n) {\n for (let i = 0; i < items.length; i++) {\n const item = items[i];\n if (item.tabIndex === 0 && isActivatable(item)) {\n return {\n item,\n index: i,\n } as ItemRecord<Item>;\n }\n }\n return null;\n}\n\n/**\n * Retrieves the first non-disabled item of a given array of items. This\n * the first item that is not disabled.\n *\n * @param items {Array<ListItem>} The items to search.\n * @param isActivatable Function to determine if an item can be activated.\n * Defaults to non-disabled items.\n * @return The first activatable item or `null` if none are activatable.\n * @nocollapse\n */\nexport function getFirstActivatableItem<Item extends ListItem>(\n items: Item[],\n isActivatable = isItemNotDisabled<Item>,\n) {\n for (const item of items) {\n if (isActivatable(item)) {\n return item;\n }\n }\n\n return null;\n}\n\n/**\n * Retrieves the last non-disabled item of a given array of items.\n *\n * @param items {Array<ListItem>} The items to search.\n * @param isActivatable Function to determine if an item can be activated.\n * Defaults to non-disabled items.\n * @return The last activatable item or `null` if none are activatable.\n * @nocollapse\n */\nexport function getLastActivatableItem<Item extends ListItem>(\n items: Item[],\n isActivatable = isItemNotDisabled<Item>,\n) {\n for (let i = items.length - 1; i >= 0; i--) {\n const item = items[i];\n if (isActivatable(item)) {\n return item;\n }\n }\n\n return null;\n}\n\n/**\n * Retrieves the next non-disabled item of a given array of items.\n *\n * @param items {Array<ListItem>} The items to search.\n * @param index {{index: number}} The index to search from.\n * @param isActivatable Function to determine if an item can be activated.\n * Defaults to non-disabled items.\n * @return The next activatable item or `null` if none are activatable.\n */\nexport function getNextItem<Item extends ListItem>(\n items: Item[],\n index: number,\n isActivatable = isItemNotDisabled<Item>,\n) {\n for (let i = 1; i < items.length; i++) {\n const nextIndex = (i + index) % items.length;\n const item = items[nextIndex];\n if (isActivatable(item)) {\n return item;\n }\n }\n\n return items[index] ? items[index] : null;\n}\n\n/**\n * Retrieves the previous non-disabled item of a given array of items.\n *\n * @param items {Array<ListItem>} The items to search.\n * @param index {{index: number}} The index to search from.\n * @param isActivatable Function to determine if an item can be activated.\n * Defaults to non-disabled items.\n * @return The previous activatable item or `null` if none are activatable.\n */\nexport function getPrevItem<Item extends ListItem>(\n items: Item[],\n index: number,\n isActivatable = isItemNotDisabled<Item>,\n) {\n for (let i = 1; i < items.length; i++) {\n const prevIndex = (index - i + items.length) % items.length;\n const item = items[prevIndex];\n\n if (isActivatable(item)) {\n return item;\n }\n }\n\n return items[index] ? items[index] : null;\n}\n\n/**\n * Activates the next item and focuses it. If nothing is currently activated,\n * activates the first item.\n */\nexport function activateNextItem<Item extends ListItem>(\n items: Item[],\n activeItemRecord: null | ItemRecord<Item>,\n isActivatable = isItemNotDisabled<Item>,\n): Item | null {\n if (activeItemRecord) {\n const next = getNextItem(items, activeItemRecord.index, isActivatable);\n\n if (next) {\n next.tabIndex = 0;\n next.focus();\n }\n\n return next;\n } else {\n return activateFirstItem(items, isActivatable);\n }\n}\n\n/**\n * Activates the previous item and focuses it. If nothing is currently\n * activated, activates the last item.\n */\nexport function activatePreviousItem<Item extends ListItem>(\n items: Item[],\n activeItemRecord: null | ItemRecord<Item>,\n isActivatable = isItemNotDisabled<Item>,\n): Item | null {\n if (activeItemRecord) {\n const prev = getPrevItem(items, activeItemRecord.index, isActivatable);\n if (prev) {\n prev.tabIndex = 0;\n prev.focus();\n }\n return prev;\n } else {\n return activateLastItem(items, isActivatable);\n }\n}\n\n/**\n * Creates an event that requests the parent md-list to deactivate all other\n * items.\n */\nexport function createDeactivateItemsEvent() {\n return new Event('deactivate-items', {bubbles: true, composed: true});\n}\n\n/**\n * The type of the event that requests the parent md-list to deactivate all\n * other items.\n */\nexport type DeactivateItemsEvent = ReturnType<\n typeof createDeactivateItemsEvent\n>;\n\n/**\n * Creates an event that requests the menu to set `tabindex=0` on the item and\n * focus it. We use this pattern because List keeps track of what element is\n * active in the List by maintaining tabindex. We do not want list items\n * to set tabindex on themselves or focus themselves so that we can organize all\n * that logic in the parent List and Menus, and list item stays as dumb as\n * possible.\n */\nexport function createRequestActivationEvent() {\n return new Event('request-activation', {bubbles: true, composed: true});\n}\n\n/**\n * The type of the event that requests the list activates and focuses the item.\n */\nexport type RequestActivationEvent = ReturnType<\n typeof createRequestActivationEvent\n>;\n\n/**\n * The default `isActivatable` function, which checks if an item is not\n * disabled.\n *\n * @param item The item to check.\n * @return true if `item.disabled` is `false.\n */\nfunction isItemNotDisabled<Item extends ListItem>(item: Item) {\n return !item.disabled;\n}\n"]}
1
+ {"version":3,"file":"list-navigation-helpers.js","sourceRoot":"","sources":["list-navigation-helpers.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAeH;;;;;;;GAOG;AACH,MAAM,UAAU,iBAAiB,CAC/B,KAAa,EACb,gBAAgB,CAAA,iBAAuB,CAAA;IAEvC,yEAAyE;IACzE,yEAAyE;IACzE,UAAU;IACV,MAAM,SAAS,GAAG,uBAAuB,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;IAChE,IAAI,SAAS,EAAE;QACb,SAAS,CAAC,QAAQ,GAAG,CAAC,CAAC;QACvB,SAAS,CAAC,KAAK,EAAE,CAAC;KACnB;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,gBAAgB,CAC9B,KAAa,EACb,gBAAgB,CAAA,iBAAuB,CAAA;IAEvC,MAAM,QAAQ,GAAG,sBAAsB,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;IAC9D,IAAI,QAAQ,EAAE;QACZ,QAAQ,CAAC,QAAQ,GAAG,CAAC,CAAC;QACtB,QAAQ,CAAC,KAAK,EAAE,CAAC;KAClB;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,oBAAoB,CAClC,KAAa,EACb,gBAAgB,CAAA,iBAAuB,CAAA;IAEvC,MAAM,UAAU,GAAG,aAAa,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;IACvD,IAAI,UAAU,EAAE;QACd,UAAU,CAAC,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC;KAC/B;IACD,OAAO,UAAU,CAAC;AACpB,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,aAAa,CAC3B,KAAa,EACb,gBAAgB,CAAA,i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LC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nexport interface ListItem extends HTMLElement {\n disabled: boolean;\n}\n\n/**\n * A record that describes a list item in a list with metadata such a reference\n * to the item and its index in the list.\n */\nexport interface ItemRecord<Item extends ListItem> {\n item: Item;\n index: number;\n}\n\n/**\n * Activates the first non-disabled item of a given array of items.\n *\n * @param items {Array<ListItem>} The items from which to activate the\n * first item.\n * @param isActivatable Function to determine if an item can be activated.\n * Defaults to non-disabled items.\n */\nexport function activateFirstItem<Item extends ListItem>(\n items: Item[],\n isActivatable = isItemNotDisabled<Item>,\n) {\n // NOTE: These selector functions are static and not on the instance such\n // that multiple operations can be chained and we do not have to re-query\n // the DOM\n const firstItem = getFirstActivatableItem(items, isActivatable);\n if (firstItem) {\n firstItem.tabIndex = 0;\n firstItem.focus();\n }\n return firstItem;\n}\n\n/**\n * Activates the last non-disabled item of a given array of items.\n *\n * @param items {Array<ListItem>} The items from which to activate the\n * last item.\n * @param isActivatable Function to determine if an item can be activated.\n * Defaults to non-disabled items.\n * @nocollapse\n */\nexport function activateLastItem<Item extends ListItem>(\n items: Item[],\n isActivatable = isItemNotDisabled<Item>,\n) {\n const lastItem = getLastActivatableItem(items, isActivatable);\n if (lastItem) {\n lastItem.tabIndex = 0;\n lastItem.focus();\n }\n return lastItem;\n}\n\n/**\n * Deactivates the currently active item of a given array of items.\n *\n * @param items {Array<ListItem>} The items from which to deactivate the\n * active item.\n * @param isActivatable Function to determine if an item can be activated.\n * Defaults to non-disabled items.\n * @return A record of the deleselcted activated item including the item and\n * the index of the item or `null` if none are deactivated.\n * @nocollapse\n */\nexport function deactivateActiveItem<Item extends ListItem>(\n items: Item[],\n isActivatable = isItemNotDisabled<Item>,\n) {\n const activeItem = getActiveItem(items, isActivatable);\n if (activeItem) {\n activeItem.item.tabIndex = -1;\n }\n return activeItem;\n}\n\n/**\n * Retrieves the first activated item of a given array of items.\n *\n * @param items {Array<ListItem>} The items to search.\n * @param isActivatable Function to determine if an item can be activated.\n * Defaults to non-disabled items.\n * @return A record of the first activated item including the item and the\n * index of the item or `null` if none are activated.\n * @nocollapse\n */\nexport function getActiveItem<Item extends ListItem>(\n items: Item[],\n isActivatable = isItemNotDisabled<Item>,\n) {\n for (let i = 0; i < items.length; i++) {\n const item = items[i];\n if (item.tabIndex === 0 && isActivatable(item)) {\n return {\n item,\n index: i,\n } as ItemRecord<Item>;\n }\n }\n return null;\n}\n\n/**\n * Retrieves the first non-disabled item of a given array of items. This\n * the first item that is not disabled.\n *\n * @param items {Array<ListItem>} The items to search.\n * @param isActivatable Function to determine if an item can be activated.\n * Defaults to non-disabled items.\n * @return The first activatable item or `null` if none are activatable.\n * @nocollapse\n */\nexport function getFirstActivatableItem<Item extends ListItem>(\n items: Item[],\n isActivatable = isItemNotDisabled<Item>,\n) {\n for (const item of items) {\n if (isActivatable(item)) {\n return item;\n }\n }\n\n return null;\n}\n\n/**\n * Retrieves the last non-disabled item of a given array of items.\n *\n * @param items {Array<ListItem>} The items to search.\n * @param isActivatable Function to determine if an item can be activated.\n * Defaults to non-disabled items.\n * @return The last activatable item or `null` if none are activatable.\n * @nocollapse\n */\nexport function getLastActivatableItem<Item extends ListItem>(\n items: Item[],\n isActivatable = isItemNotDisabled<Item>,\n) {\n for (let i = items.length - 1; i >= 0; i--) {\n const item = items[i];\n if (isActivatable(item)) {\n return item;\n }\n }\n\n return null;\n}\n\n/**\n * Retrieves the next non-disabled item of a given array of items.\n *\n * @param items {Array<ListItem>} The items to search.\n * @param index {{index: number}} The index to search from.\n * @param isActivatable Function to determine if an item can be activated.\n * Defaults to non-disabled items.\n * @param wrap If true, then the next item at the end of the list is the first\n * item. Defaults to true.\n * @return The next activatable item or `null` if none are activatable.\n */\nexport function getNextItem<Item extends ListItem>(\n items: Item[],\n index: number,\n isActivatable = isItemNotDisabled<Item>,\n wrap = true,\n) {\n for (let i = 1; i < items.length; i++) {\n const nextIndex = (i + index) % items.length;\n if (nextIndex < index && !wrap) {\n // Return if the index loops back to the beginning and not wrapping.\n return null;\n }\n\n const item = items[nextIndex];\n if (isActivatable(item)) {\n return item;\n }\n }\n\n return items[index] ? items[index] : null;\n}\n\n/**\n * Retrieves the previous non-disabled item of a given array of items.\n *\n * @param items {Array<ListItem>} The items to search.\n * @param index {{index: number}} The index to search from.\n * @param isActivatable Function to determine if an item can be activated.\n * Defaults to non-disabled items.\n * @param wrap If true, then the previous item at the beginning of the list is\n * the last item. Defaults to true.\n * @return The previous activatable item or `null` if none are activatable.\n */\nexport function getPrevItem<Item extends ListItem>(\n items: Item[],\n index: number,\n isActivatable = isItemNotDisabled<Item>,\n wrap = true,\n) {\n for (let i = 1; i < items.length; i++) {\n const prevIndex = (index - i + items.length) % items.length;\n if (prevIndex > index && !wrap) {\n // Return if the index loops back to the end and not wrapping.\n return null;\n }\n\n const item = items[prevIndex];\n\n if (isActivatable(item)) {\n return item;\n }\n }\n\n return items[index] ? items[index] : null;\n}\n\n/**\n * Activates the next item and focuses it. If nothing is currently activated,\n * activates the first item.\n */\nexport function activateNextItem<Item extends ListItem>(\n items: Item[],\n activeItemRecord: null | ItemRecord<Item>,\n isActivatable = isItemNotDisabled<Item>,\n wrap = true,\n): Item | null {\n if (activeItemRecord) {\n const next = getNextItem(\n items,\n activeItemRecord.index,\n isActivatable,\n wrap,\n );\n\n if (next) {\n next.tabIndex = 0;\n next.focus();\n }\n\n return next;\n } else {\n return activateFirstItem(items, isActivatable);\n }\n}\n\n/**\n * Activates the previous item and focuses it. If nothing is currently\n * activated, activates the last item.\n */\nexport function activatePreviousItem<Item extends ListItem>(\n items: Item[],\n activeItemRecord: null | ItemRecord<Item>,\n isActivatable = isItemNotDisabled<Item>,\n wrap = true,\n): Item | null {\n if (activeItemRecord) {\n const prev = getPrevItem(\n items,\n activeItemRecord.index,\n isActivatable,\n wrap,\n );\n if (prev) {\n prev.tabIndex = 0;\n prev.focus();\n }\n return prev;\n } else {\n return activateLastItem(items, isActivatable);\n }\n}\n\n/**\n * Creates an event that requests the parent md-list to deactivate all other\n * items.\n */\nexport function createDeactivateItemsEvent() {\n return new Event('deactivate-items', {bubbles: true, composed: true});\n}\n\n/**\n * The type of the event that requests the parent md-list to deactivate all\n * other items.\n */\nexport type DeactivateItemsEvent = ReturnType<\n typeof createDeactivateItemsEvent\n>;\n\n/**\n * Creates an event that requests the menu to set `tabindex=0` on the item and\n * focus it. We use this pattern because List keeps track of what element is\n * active in the List by maintaining tabindex. We do not want list items\n * to set tabindex on themselves or focus themselves so that we can organize all\n * that logic in the parent List and Menus, and list item stays as dumb as\n * possible.\n */\nexport function createRequestActivationEvent() {\n return new Event('request-activation', {bubbles: true, composed: true});\n}\n\n/**\n * The type of the event that requests the list activates and focuses the item.\n */\nexport type RequestActivationEvent = ReturnType<\n typeof createRequestActivationEvent\n>;\n\n/**\n * The default `isActivatable` function, which checks if an item is not\n * disabled.\n *\n * @param item The item to check.\n * @return true if `item.disabled` is `false.\n */\nfunction isItemNotDisabled<Item extends ListItem>(item: Item) {\n return !item.disabled;\n}\n"]}
@@ -3,6 +3,7 @@
3
3
  * Copyright 2022 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
+ import { CSSResultOrNative } from 'lit';
6
7
  import { ListItemEl as ListItem } from './internal/listitem/list-item.js';
7
8
  export { type ListItemType } from './internal/listitem/list-item.js';
8
9
  declare global {
@@ -49,5 +50,5 @@ declare global {
49
50
  * @suppress {visibility}
50
51
  */
51
52
  export declare class MdListItem extends ListItem {
52
- static styles: import("lit").CSSResult[];
53
+ static styles: CSSResultOrNative[];
53
54
  }
@@ -1 +1 @@
1
- {"version":3,"file":"list-item.js","sourceRoot":"","sources":["list-item.ts"],"names":[],"mappings":"AAAA;;;;GAIG;;AAEH,OAAO,EAAC,aAAa,EAAC,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAC,UAAU,IAAI,QAAQ,EAAC,MAAM,kCAAkC,CAAC;AACxE,OAAO,EAAC,MAAM,EAAC,MAAM,6CAA6C,CAAC;AAUnE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEI,WAAM,UAAU,GAAhB,MAAM,UAAW,SAAQ,QAAQ;;AACtB,iBAAM,GAAG,CAAC,MAAM,CAAC,AAAX,CAAY;AADvB,UAAU;IADtB,aAAa,CAAC,cAAc,CAAC;GACjB,UAAU,CAEtB","sourcesContent":["/**\n * @license\n * Copyright 2022 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {customElement} from 'lit/decorators.js';\n\nimport {ListItemEl as ListItem} from './internal/listitem/list-item.js';\nimport {styles} from './internal/listitem/list-item-styles.css.js';\n\nexport {type ListItemType} from './internal/listitem/list-item.js';\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'md-list-item': MdListItem;\n }\n}\n\n/**\n * @summary\n * Lists are continuous, vertical indexes of text or images. Items are placed\n * inside the list.\n *\n * @description\n * Lists consist of one or more list items, and can contain actions represented\n * by icons and text. List items come in three sizes: one-line, two-line, and\n * three-line.\n *\n * __Takeaways:__\n *\n * - Lists should be sorted in logical ways that make content easy to scan, such\n * as alphabetical, numerical, chronological, or by user preference.\n * - Lists present content in a way that makes it easy to identify a specific\n * item in a collection and act on it.\n * - Lists should present icons, text, and actions in a consistent format.\n *\n * Acceptable slot child variants are:\n *\n * - `img[slot=end]`\n * - `img[slot=start]`\n *\n * @example\n * ```html\n * <md-list-item\n * headline=\"User Name\"\n * supportingText=\"user@name.com\">\n * <md-icon slot=\"start\">account_circle</md-icon>\n * <md-icon slot=\"end\">check</md-icon>\n * </md-list-item>\n * ```\n *\n * @example\n *\n * @final\n * @suppress {visibility}\n */\n@customElement('md-list-item')\nexport class MdListItem extends ListItem {\n static override styles = [styles];\n}\n"]}
1
+ {"version":3,"file":"list-item.js","sourceRoot":"","sources":["list-item.ts"],"names":[],"mappings":"AAAA;;;;GAIG;;AAGH,OAAO,EAAC,aAAa,EAAC,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAC,UAAU,IAAI,QAAQ,EAAC,MAAM,kCAAkC,CAAC;AACxE,OAAO,EAAC,MAAM,EAAC,MAAM,6CAA6C,CAAC;AAUnE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEI,WAAM,UAAU,GAAhB,MAAM,UAAW,SAAQ,QAAQ;;AACtB,iBAAM,GAAwB,CAAC,MAAM,CAAC,AAAhC,CAAiC;AAD5C,UAAU;IADtB,aAAa,CAAC,cAAc,CAAC;GACjB,UAAU,CAEtB","sourcesContent":["/**\n * @license\n * Copyright 2022 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {CSSResultOrNative} from 'lit';\nimport {customElement} from 'lit/decorators.js';\n\nimport {ListItemEl as ListItem} from './internal/listitem/list-item.js';\nimport {styles} from './internal/listitem/list-item-styles.css.js';\n\nexport {type ListItemType} from './internal/listitem/list-item.js';\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'md-list-item': MdListItem;\n }\n}\n\n/**\n * @summary\n * Lists are continuous, vertical indexes of text or images. Items are placed\n * inside the list.\n *\n * @description\n * Lists consist of one or more list items, and can contain actions represented\n * by icons and text. List items come in three sizes: one-line, two-line, and\n * three-line.\n *\n * __Takeaways:__\n *\n * - Lists should be sorted in logical ways that make content easy to scan, such\n * as alphabetical, numerical, chronological, or by user preference.\n * - Lists present content in a way that makes it easy to identify a specific\n * item in a collection and act on it.\n * - Lists should present icons, text, and actions in a consistent format.\n *\n * Acceptable slot child variants are:\n *\n * - `img[slot=end]`\n * - `img[slot=start]`\n *\n * @example\n * ```html\n * <md-list-item\n * headline=\"User Name\"\n * supportingText=\"user@name.com\">\n * <md-icon slot=\"start\">account_circle</md-icon>\n * <md-icon slot=\"end\">check</md-icon>\n * </md-list-item>\n * ```\n *\n * @example\n *\n * @final\n * @suppress {visibility}\n */\n@customElement('md-list-item')\nexport class MdListItem extends ListItem {\n static override styles: CSSResultOrNative[] = [styles];\n}\n"]}
package/list/list.d.ts CHANGED
@@ -3,6 +3,7 @@
3
3
  * Copyright 2021 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
+ import { CSSResultOrNative } from 'lit';
6
7
  import { List } from './internal/list.js';
7
8
  declare global {
8
9
  interface HTMLElementTagNameMap {
@@ -29,5 +30,5 @@ declare global {
29
30
  * @suppress {visibility}
30
31
  */
31
32
  export declare class MdList extends List {
32
- static styles: import("lit").CSSResult[];
33
+ static styles: CSSResultOrNative[];
33
34
  }
package/list/list.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"list.js","sourceRoot":"","sources":["list.ts"],"names":[],"mappings":"AAAA;;;;GAIG;;AAEH,OAAO,EAAC,aAAa,EAAC,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAC,IAAI,EAAC,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAC,MAAM,EAAC,MAAM,+BAA+B,CAAC;AAQrD;;;;;;;;;;;;;;;;;;GAkBG;AAEI,WAAM,MAAM,GAAZ,MAAM,MAAO,SAAQ,IAAI;;AACd,aAAM,GAAG,CAAC,MAAM,CAAC,AAAX,CAAY;AADvB,MAAM;IADlB,aAAa,CAAC,SAAS,CAAC;GACZ,MAAM,CAElB","sourcesContent":["/**\n * @license\n * Copyright 2021 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {customElement} from 'lit/decorators.js';\n\nimport {List} from './internal/list.js';\nimport {styles} from './internal/list-styles.css.js';\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'md-list': MdList;\n }\n}\n\n/**\n * @summary Lists are continuous, vertical indexes of text or images.\n *\n * @description\n * Lists consist of one or more list items, and can contain actions represented\n * by icons and text. List items come in three sizes: one-line, two-line, and\n * three-line.\n *\n * __Takeaways:__\n *\n * - Lists should be sorted in logical ways that make content easy to scan, such\n * as alphabetical, numerical, chronological, or by user preference.\n * - Lists present content in a way that makes it easy to identify a specific\n * item in a collection and act on it.\n * - Lists should present icons, text, and actions in a consistent format.\n *\n * @final\n * @suppress {visibility}\n */\n@customElement('md-list')\nexport class MdList extends List {\n static override styles = [styles];\n}\n"]}
1
+ {"version":3,"file":"list.js","sourceRoot":"","sources":["list.ts"],"names":[],"mappings":"AAAA;;;;GAIG;;AAGH,OAAO,EAAC,aAAa,EAAC,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAC,IAAI,EAAC,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAC,MAAM,EAAC,MAAM,+BAA+B,CAAC;AAQrD;;;;;;;;;;;;;;;;;;GAkBG;AAEI,WAAM,MAAM,GAAZ,MAAM,MAAO,SAAQ,IAAI;;AACd,aAAM,GAAwB,CAAC,MAAM,CAAC,AAAhC,CAAiC;AAD5C,MAAM;IADlB,aAAa,CAAC,SAAS,CAAC;GACZ,MAAM,CAElB","sourcesContent":["/**\n * @license\n * Copyright 2021 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {CSSResultOrNative} from 'lit';\nimport {customElement} from 'lit/decorators.js';\n\nimport {List} from './internal/list.js';\nimport {styles} from './internal/list-styles.css.js';\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'md-list': MdList;\n }\n}\n\n/**\n * @summary Lists are continuous, vertical indexes of text or images.\n *\n * @description\n * Lists consist of one or more list items, and can contain actions represented\n * by icons and text. List items come in three sizes: one-line, two-line, and\n * three-line.\n *\n * __Takeaways:__\n *\n * - Lists should be sorted in logical ways that make content easy to scan, such\n * as alphabetical, numerical, chronological, or by user preference.\n * - Lists present content in a way that makes it easy to identify a specific\n * item in a collection and act on it.\n * - Lists should present icons, text, and actions in a consistent format.\n *\n * @final\n * @suppress {visibility}\n */\n@customElement('md-list')\nexport class MdList extends List {\n static override styles: CSSResultOrNative[] = [styles];\n}\n"]}
@@ -153,6 +153,12 @@ export declare abstract class Menu extends LitElement {
153
153
  * `display: contents` when necessary.
154
154
  */
155
155
  defaultFocus: FocusState;
156
+ /**
157
+ * Turns off navigation wrapping. By default, navigating past the end of the
158
+ * menu items will wrap focus back to the beginning and vice versa. Use this
159
+ * for ARIA patterns that do not wrap focus, like combobox.
160
+ */
161
+ noNavigationWrap: boolean;
156
162
  protected slotItems: HTMLElement[];
157
163
  private typeaheadActive;
158
164
  /**
@@ -209,6 +209,12 @@ export class Menu extends LitElement {
209
209
  * `display: contents` when necessary.
210
210
  */
211
211
  this.defaultFocus = FocusState.FIRST_ITEM;
212
+ /**
213
+ * Turns off navigation wrapping. By default, navigating past the end of the
214
+ * menu items will wrap focus back to the beginning and vice versa. Use this
215
+ * for ARIA patterns that do not wrap focus, like combobox.
216
+ */
217
+ this.noNavigationWrap = false;
212
218
  this.typeaheadActive = true;
213
219
  /**
214
220
  * Whether or not the current menu is a submenu and should not handle specific
@@ -257,6 +263,7 @@ export class Menu extends LitElement {
257
263
  }
258
264
  return submenuNavKeys.has(key);
259
265
  },
266
+ wrapNavigation: () => !this.noNavigationWrap,
260
267
  });
261
268
  /**
262
269
  * The element that was focused before the menu opened.
@@ -865,6 +872,9 @@ __decorate([
865
872
  __decorate([
866
873
  property({ attribute: 'default-focus' })
867
874
  ], Menu.prototype, "defaultFocus", void 0);
875
+ __decorate([
876
+ property({ type: Boolean, attribute: 'no-navigation-wrap' })
877
+ ], Menu.prototype, "noNavigationWrap", void 0);
868
878
  __decorate([
869
879
  queryAssignedElements({ flatten: true })
870
880
  ], Menu.prototype, "slotItems", void 0);