@cloudscape-design/components 3.0.1411 → 3.0.1413

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 (238) hide show
  1. package/action-card/internal.d.ts +10 -2
  2. package/action-card/internal.d.ts.map +1 -1
  3. package/action-card/internal.js +5 -5
  4. package/action-card/internal.js.map +1 -1
  5. package/action-card/styles.css.js +18 -17
  6. package/action-card/styles.scoped.css +274 -202
  7. package/action-card/styles.selectors.js +18 -17
  8. package/app-layout/visual-refresh-toolbar/skeleton/toolbar-container.d.ts.map +1 -1
  9. package/app-layout/visual-refresh-toolbar/skeleton/toolbar-container.js +3 -1
  10. package/app-layout/visual-refresh-toolbar/skeleton/toolbar-container.js.map +1 -1
  11. package/button-dropdown/filter.d.ts +1 -1
  12. package/expandable-section/expandable-section-header.js +1 -1
  13. package/expandable-section/expandable-section-header.js.map +1 -1
  14. package/header/interfaces.d.ts +4 -0
  15. package/header/interfaces.d.ts.map +1 -1
  16. package/header/interfaces.js.map +1 -1
  17. package/header/internal.d.ts +1 -6
  18. package/header/internal.d.ts.map +1 -1
  19. package/header/internal.js +2 -2
  20. package/header/internal.js.map +1 -1
  21. package/header/styles.css.js +36 -36
  22. package/header/styles.scoped.css +55 -55
  23. package/header/styles.selectors.js +36 -36
  24. package/i18n/messages/all.all.js +1 -1
  25. package/i18n/messages/all.all.json +1 -1
  26. package/i18n/messages/all.de.js +1 -1
  27. package/i18n/messages/all.de.json +1 -1
  28. package/i18n/messages/all.en-GB.js +1 -1
  29. package/i18n/messages/all.en-GB.json +1 -1
  30. package/i18n/messages/all.en.js +1 -1
  31. package/i18n/messages/all.en.json +1 -1
  32. package/i18n/messages/all.es.js +1 -1
  33. package/i18n/messages/all.es.json +1 -1
  34. package/i18n/messages/all.fr.js +1 -1
  35. package/i18n/messages/all.fr.json +1 -1
  36. package/i18n/messages/all.id.js +1 -1
  37. package/i18n/messages/all.id.json +1 -1
  38. package/i18n/messages/all.it.js +1 -1
  39. package/i18n/messages/all.it.json +1 -1
  40. package/i18n/messages/all.ja.js +1 -1
  41. package/i18n/messages/all.ja.json +1 -1
  42. package/i18n/messages/all.ko.js +1 -1
  43. package/i18n/messages/all.ko.json +1 -1
  44. package/i18n/messages/all.pt-BR.js +1 -1
  45. package/i18n/messages/all.pt-BR.json +1 -1
  46. package/i18n/messages/all.tr.js +1 -1
  47. package/i18n/messages/all.tr.json +1 -1
  48. package/i18n/messages/all.zh-CN.js +1 -1
  49. package/i18n/messages/all.zh-CN.json +1 -1
  50. package/i18n/messages/all.zh-TW.js +1 -1
  51. package/i18n/messages/all.zh-TW.json +1 -1
  52. package/i18n/messages-types.d.ts +3 -0
  53. package/i18n/messages-types.d.ts.map +1 -1
  54. package/i18n/messages-types.js.map +1 -1
  55. package/index.d.ts +1 -0
  56. package/index.d.ts.map +1 -1
  57. package/index.js +1 -0
  58. package/index.js.map +1 -1
  59. package/internal/base-component/styles.scoped.css +1 -1
  60. package/internal/components/focus-lock/utils.d.ts +2 -0
  61. package/internal/components/focus-lock/utils.d.ts.map +1 -1
  62. package/internal/components/focus-lock/utils.js +5 -1
  63. package/internal/components/focus-lock/utils.js.map +1 -1
  64. package/internal/components/listbox/interfaces.d.ts +12 -0
  65. package/internal/components/listbox/interfaces.d.ts.map +1 -0
  66. package/internal/components/listbox/interfaces.js +2 -0
  67. package/internal/components/listbox/interfaces.js.map +1 -0
  68. package/internal/components/listbox/parts/get-item-props.d.ts +1 -3
  69. package/internal/components/listbox/parts/get-item-props.d.ts.map +1 -1
  70. package/internal/components/listbox/parts/get-item-props.js +1 -2
  71. package/internal/components/listbox/parts/get-item-props.js.map +1 -1
  72. package/internal/components/listbox/parts/item.d.ts +45 -0
  73. package/internal/components/listbox/parts/item.d.ts.map +1 -0
  74. package/internal/components/listbox/parts/item.js +184 -0
  75. package/internal/components/listbox/parts/item.js.map +1 -0
  76. package/internal/components/listbox/parts/plain-list.d.ts +29 -0
  77. package/internal/components/listbox/parts/plain-list.d.ts.map +1 -0
  78. package/{select → internal/components/listbox}/parts/plain-list.js +12 -12
  79. package/internal/components/listbox/parts/plain-list.js.map +1 -0
  80. package/internal/components/listbox/parts/render-options.d.ts +3 -4
  81. package/internal/components/listbox/parts/render-options.d.ts.map +1 -1
  82. package/internal/components/listbox/parts/render-options.js +3 -6
  83. package/internal/components/listbox/parts/render-options.js.map +1 -1
  84. package/internal/components/listbox/parts/scroll-to-index.d.ts +11 -0
  85. package/internal/components/listbox/parts/scroll-to-index.d.ts.map +1 -1
  86. package/internal/components/listbox/parts/scroll-to-index.js +16 -0
  87. package/internal/components/listbox/parts/scroll-to-index.js.map +1 -1
  88. package/internal/components/listbox/use-listbox.d.ts +95 -0
  89. package/internal/components/listbox/use-listbox.d.ts.map +1 -0
  90. package/internal/components/listbox/use-listbox.js +117 -0
  91. package/internal/components/listbox/use-listbox.js.map +1 -0
  92. package/internal/components/listbox/use-type-ahead.d.ts +18 -0
  93. package/internal/components/listbox/use-type-ahead.d.ts.map +1 -0
  94. package/{select/utils/use-native-search.js → internal/components/listbox/use-type-ahead.js} +8 -8
  95. package/internal/components/listbox/use-type-ahead.js.map +1 -0
  96. package/internal/components/listbox/utils/navigation.d.ts +27 -0
  97. package/internal/components/listbox/utils/navigation.d.ts.map +1 -0
  98. package/internal/components/listbox/utils/navigation.js +22 -0
  99. package/internal/components/listbox/utils/navigation.js.map +1 -0
  100. package/internal/components/listbox/utils/option-props.d.ts +35 -0
  101. package/internal/components/listbox/utils/option-props.d.ts.map +1 -0
  102. package/internal/components/listbox/utils/option-props.js +51 -0
  103. package/internal/components/listbox/utils/option-props.js.map +1 -0
  104. package/internal/components/options-list/index.d.ts +4 -1
  105. package/internal/components/options-list/index.d.ts.map +1 -1
  106. package/internal/components/options-list/index.js +1 -1
  107. package/internal/components/options-list/index.js.map +1 -1
  108. package/internal/components/options-list/utils/use-keyboard.d.ts +2 -1
  109. package/internal/components/options-list/utils/use-keyboard.d.ts.map +1 -1
  110. package/internal/components/options-list/utils/use-keyboard.js +5 -3
  111. package/internal/components/options-list/utils/use-keyboard.js.map +1 -1
  112. package/internal/components/selectable-item/index.d.ts +1 -0
  113. package/internal/components/selectable-item/index.d.ts.map +1 -1
  114. package/internal/components/selectable-item/index.js +2 -1
  115. package/internal/components/selectable-item/index.js.map +1 -1
  116. package/internal/components/selectable-item/interfaces.d.ts +1 -0
  117. package/internal/components/selectable-item/interfaces.d.ts.map +1 -1
  118. package/internal/components/selectable-item/interfaces.js.map +1 -1
  119. package/internal/components/selectable-item/styles.css.js +23 -22
  120. package/internal/components/selectable-item/styles.scoped.css +52 -49
  121. package/internal/components/selectable-item/styles.selectors.js +23 -22
  122. package/internal/components/sticky-header/use-untabbable-descendants.d.ts +2 -0
  123. package/internal/components/sticky-header/use-untabbable-descendants.d.ts.map +1 -0
  124. package/internal/components/sticky-header/use-untabbable-descendants.js +16 -0
  125. package/internal/components/sticky-header/use-untabbable-descendants.js.map +1 -0
  126. package/internal/environment.js +2 -2
  127. package/internal/environment.json +2 -2
  128. package/internal/manifest.json +1 -1
  129. package/item-card/internal.d.ts +11 -1
  130. package/item-card/internal.d.ts.map +1 -1
  131. package/item-card/internal.js +4 -4
  132. package/item-card/internal.js.map +1 -1
  133. package/item-card/style.d.ts.map +1 -1
  134. package/item-card/style.js +6 -1
  135. package/item-card/style.js.map +1 -1
  136. package/item-card/styles.css.js +14 -14
  137. package/item-card/styles.scoped.css +125 -63
  138. package/item-card/styles.selectors.js +14 -14
  139. package/manifest.json +2 -2
  140. package/multiselect/embedded.d.ts.map +1 -1
  141. package/multiselect/embedded.js +2 -2
  142. package/multiselect/embedded.js.map +1 -1
  143. package/multiselect/internal.d.ts.map +1 -1
  144. package/multiselect/internal.js +2 -2
  145. package/multiselect/internal.js.map +1 -1
  146. package/multiselect/use-multiselect.d.ts +3 -4
  147. package/multiselect/use-multiselect.d.ts.map +1 -1
  148. package/multiselect/use-multiselect.js +7 -18
  149. package/multiselect/use-multiselect.js.map +1 -1
  150. package/option-list/index.d.ts +5 -0
  151. package/option-list/index.d.ts.map +1 -0
  152. package/option-list/index.js +21 -0
  153. package/option-list/index.js.map +1 -0
  154. package/option-list/interfaces.d.ts +131 -0
  155. package/option-list/interfaces.d.ts.map +1 -0
  156. package/option-list/interfaces.js +2 -0
  157. package/option-list/interfaces.js.map +1 -0
  158. package/option-list/internal.d.ts +5 -0
  159. package/option-list/internal.d.ts.map +1 -0
  160. package/option-list/internal.js +138 -0
  161. package/option-list/internal.js.map +1 -0
  162. package/option-list/styles.css.js +6 -0
  163. package/option-list/styles.scoped.css +40 -0
  164. package/option-list/styles.selectors.js +7 -0
  165. package/option-list/test-classes/styles.css.js +8 -0
  166. package/option-list/test-classes/styles.scoped.css +9 -0
  167. package/option-list/test-classes/styles.selectors.js +9 -0
  168. package/option-list/use-option-list.d.ts +36 -0
  169. package/option-list/use-option-list.d.ts.map +1 -0
  170. package/option-list/use-option-list.js +69 -0
  171. package/option-list/use-option-list.js.map +1 -0
  172. package/package.json +4 -1
  173. package/select/internal.d.ts.map +1 -1
  174. package/select/internal.js +9 -19
  175. package/select/internal.js.map +1 -1
  176. package/select/parts/filter.d.ts +1 -1
  177. package/select/parts/virtual-list.d.ts +3 -2
  178. package/select/parts/virtual-list.d.ts.map +1 -1
  179. package/select/parts/virtual-list.js +7 -8
  180. package/select/parts/virtual-list.js.map +1 -1
  181. package/select/utils/use-select.d.ts +18 -11
  182. package/select/utils/use-select.d.ts.map +1 -1
  183. package/select/utils/use-select.js +41 -117
  184. package/select/utils/use-select.js.map +1 -1
  185. package/styling/action-card.scss +56 -0
  186. package/styling/item-card.scss +81 -0
  187. package/table-root/index.js +1 -1
  188. package/table-root/index.js.map +1 -1
  189. package/table-root/interfaces.d.ts +15 -1
  190. package/table-root/interfaces.d.ts.map +1 -1
  191. package/table-root/interfaces.js.map +1 -1
  192. package/table-root/internal.d.ts +2 -0
  193. package/table-root/internal.d.ts.map +1 -1
  194. package/table-root/internal.js +23 -11
  195. package/table-root/internal.js.map +1 -1
  196. package/table-root/sticky-header-slot.d.ts +24 -0
  197. package/table-root/sticky-header-slot.d.ts.map +1 -0
  198. package/table-root/sticky-header-slot.js +13 -0
  199. package/table-root/sticky-header-slot.js.map +1 -0
  200. package/table-root/styles.css.js +10 -5
  201. package/table-root/styles.scoped.css +52 -7
  202. package/table-root/styles.selectors.js +10 -5
  203. package/table-root/use-sticky-header.d.ts +33 -0
  204. package/table-root/use-sticky-header.d.ts.map +1 -0
  205. package/table-root/use-sticky-header.js +141 -0
  206. package/table-root/use-sticky-header.js.map +1 -0
  207. package/test-utils/dom/header/index.d.ts +1 -0
  208. package/test-utils/dom/header/index.js +3 -0
  209. package/test-utils/dom/header/index.js.map +1 -1
  210. package/test-utils/dom/index.d.ts +28 -0
  211. package/test-utils/dom/index.js +21 -2
  212. package/test-utils/dom/index.js.map +1 -1
  213. package/test-utils/dom/option-list/index.d.ts +69 -0
  214. package/test-utils/dom/option-list/index.js +132 -0
  215. package/test-utils/dom/option-list/index.js.map +1 -0
  216. package/test-utils/selectors/header/index.d.ts +1 -0
  217. package/test-utils/selectors/header/index.js +3 -0
  218. package/test-utils/selectors/header/index.js.map +1 -1
  219. package/test-utils/selectors/index.d.ts +18 -0
  220. package/test-utils/selectors/index.js +16 -2
  221. package/test-utils/selectors/index.js.map +1 -1
  222. package/test-utils/selectors/option-list/index.d.ts +66 -0
  223. package/test-utils/selectors/option-list/index.js +108 -0
  224. package/test-utils/selectors/option-list/index.js.map +1 -0
  225. package/select/parts/item.d.ts +0 -33
  226. package/select/parts/item.d.ts.map +0 -1
  227. package/select/parts/item.js +0 -94
  228. package/select/parts/item.js.map +0 -1
  229. package/select/parts/multiselect-item.d.ts +0 -14
  230. package/select/parts/multiselect-item.d.ts.map +0 -1
  231. package/select/parts/multiselect-item.js +0 -112
  232. package/select/parts/multiselect-item.js.map +0 -1
  233. package/select/parts/plain-list.d.ts +0 -26
  234. package/select/parts/plain-list.d.ts.map +0 -1
  235. package/select/parts/plain-list.js.map +0 -1
  236. package/select/utils/use-native-search.d.ts +0 -18
  237. package/select/utils/use-native-search.d.ts.map +0 -1
  238. package/select/utils/use-native-search.js.map +0 -1
@@ -0,0 +1,117 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { useEffect, useRef } from 'react';
4
+ import { useUniqueId } from '@cloudscape-design/component-toolkit/internal';
5
+ import { isGroupInteractive, isInteractive } from '../option/utils/filter-options';
6
+ import { useHighlightedOption, } from '../options-list/utils/use-highlight-option';
7
+ import { getOptionId } from '../options-list/utils/use-ids';
8
+ import { useMenuKeyboard } from '../options-list/utils/use-keyboard';
9
+ import { useAnnouncement } from './use-announcement';
10
+ import { connectOptionsByValue } from './utils/connect-options';
11
+ import { getListboxNavigation } from './utils/navigation';
12
+ import { getListboxOptionProps, getListMouseHandlers, getSelectableOption, isAnnouncedSelected, isHighlightable, } from './utils/option-props';
13
+ /**
14
+ * List state shared by all list components: highlight, keyboard navigation, the choose guard, mouse handlers,
15
+ * row props, scrolling the highlighted row into view, the active descendant and the live region announcement.
16
+ * Focus handling of an embedded list is shared through `getListProps({ embedded })`. Open state, filter,
17
+ * type-ahead and the highlight on open stay with the callers, because they differ per component.
18
+ */
19
+ export function useListbox({ options, selectedOptions: selectedOptionsProp, selection, interactiveGroups, onSelect, spaceSelects, onEscape, getParent, selectedAriaLabel, renderHighlightedAriaLive, }) {
20
+ const listId = useUniqueId('option-list');
21
+ const selectedOptions = connectOptionsByValue(options, selectedOptionsProp);
22
+ const selectedSet = new Set(selectedOptions);
23
+ const [{ highlightType, highlightedOption, highlightedIndex }, highlight] = useHighlightedOption({
24
+ options,
25
+ isHighlightable: (option) => isHighlightable(option, interactiveGroups),
26
+ });
27
+ const interactivityCheck = interactiveGroups ? isGroupInteractive : isInteractive;
28
+ const selectOption = (option) => {
29
+ const optionToSelect = getSelectableOption(option, highlightedOption, interactivityCheck);
30
+ if (optionToSelect) {
31
+ onSelect(optionToSelect);
32
+ }
33
+ };
34
+ const onKeyDown = useMenuKeyboard({
35
+ ...getListboxNavigation({
36
+ options,
37
+ highlightedIndex,
38
+ highlightedOption,
39
+ interactiveGroups,
40
+ moveHighlight: highlight.moveHighlightWithKeyboard,
41
+ goHome: highlight.goHomeWithKeyboard,
42
+ goEnd: highlight.goEndWithKeyboard,
43
+ }),
44
+ selectOption,
45
+ goHome: highlight.goHomeWithKeyboard,
46
+ goEnd: highlight.goEndWithKeyboard,
47
+ onEscape,
48
+ // With 'keyboard-highlight', Space chooses only while an option has a keyboard highlight, and types otherwise.
49
+ preventNativeSpace: spaceSelects === 'always' || (!!highlightedOption && highlightType.type === 'keyboard'),
50
+ });
51
+ const mouseHandlers = getListMouseHandlers({
52
+ options,
53
+ selectOption,
54
+ setHighlightedIndexWithMouse: highlight.setHighlightedIndexWithMouse,
55
+ });
56
+ const getOptionProps = (option, index) => getListboxOptionProps(option, index, {
57
+ options,
58
+ selectedSet,
59
+ selection,
60
+ highlightedOption,
61
+ interactiveGroups,
62
+ listId,
63
+ });
64
+ const announceSelected = isAnnouncedSelected(highlightedOption, selectedSet, selection);
65
+ const announcement = useAnnouncement({
66
+ announceSelected,
67
+ highlightedOption,
68
+ getParent,
69
+ selectedAriaLabel,
70
+ renderHighlightedAriaLive,
71
+ });
72
+ const activeDescendantId = getOptionId(listId, highlightedIndex);
73
+ // Keeps the highlighted option scrolled into view in the list passed `ref={scrollToIndex}`.
74
+ const scrollToIndex = useRef(null);
75
+ useEffect(() => {
76
+ var _a;
77
+ (_a = scrollToIndex.current) === null || _a === void 0 ? void 0 : _a.call(scrollToIndex, highlightedIndex);
78
+ }, [highlightedIndex]);
79
+ const listRef = useRef(null);
80
+ const getListProps = ({ withKeyboard, embedded }) => {
81
+ const listProps = { id: listId, ref: listRef, ...mouseHandlers };
82
+ if (withKeyboard) {
83
+ listProps.onKeyDown = onKeyDown;
84
+ listProps.nativeAttributes = { 'aria-activedescendant': activeDescendantId };
85
+ }
86
+ if (embedded) {
87
+ listProps.onFocus = () => {
88
+ if (!highlightedOption) {
89
+ highlight.goHomeWithKeyboard();
90
+ }
91
+ };
92
+ listProps.onBlur = () => {
93
+ highlight.resetHighlightWithKeyboard();
94
+ };
95
+ }
96
+ return listProps;
97
+ };
98
+ return {
99
+ listId,
100
+ highlightedIndex,
101
+ highlightType,
102
+ highlightedOption,
103
+ activeDescendantId,
104
+ scrollToIndex,
105
+ selectedOptions,
106
+ highlight,
107
+ selectOption,
108
+ onKeyDown,
109
+ mouseHandlers,
110
+ listRef,
111
+ getListProps,
112
+ getOptionProps,
113
+ announceSelected,
114
+ announcement,
115
+ };
116
+ }
117
+ //# sourceMappingURL=use-listbox.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-listbox.js","sourceRoot":"","sources":["../../../../../src/internal/components/listbox/use-listbox.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,EAAa,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAErD,OAAO,EAAE,WAAW,EAAE,MAAM,+CAA+C,CAAC;AAM5E,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AACnF,OAAO,EAGL,oBAAoB,GACrB,MAAM,4CAA4C,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AAGrE,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EACL,qBAAqB,EACrB,oBAAoB,EACpB,mBAAmB,EACnB,mBAAmB,EACnB,eAAe,GAChB,MAAM,sBAAsB,CAAC;AAwE9B;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CAAC,EACzB,OAAO,EACP,eA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,CAAC;YAChC,SAAS,CAAC,gBAAgB,GAAG,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,CAAC;QAC/E,CAAC;QACD,IAAI,QAAQ,EAAE,CAAC;YACb,SAAS,CAAC,OAAO,GAAG,GAAG,EAAE;gBACvB,IAAI,CAAC,iBAAiB,EAAE,CAAC;oBACvB,SAAS,CAAC,kBAAkB,EAAE,CAAC;gBACjC,CAAC;YACH,CAAC,CAAC;YACF,SAAS,CAAC,MAAM,GAAG,GAAG,EAAE;gBACtB,SAAS,CAAC,0BAA0B,EAAE,CAAC;YACzC,CAAC,CAAC;QACJ,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC,CAAC;IAEF,OAAO;QACL,MAAM;QACN,gBAAgB;QAChB,aAAa;QACb,iBAAiB;QACjB,kBAAkB;QAClB,aAAa;QACb,eAAe;QACf,SAAS;QACT,YAAY;QACZ,SAAS;QACT,aAAa;QACb,OAAO;QACP,YAAY;QACZ,cAAc;QACd,gBAAgB;QAChB,YAAY;KACb,CAAC;AACJ,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { RefObject, useEffect, useRef } from 'react';\n\nimport { useUniqueId } from '@cloudscape-design/component-toolkit/internal';\n\nimport { SelectProps } from '../../../select/interfaces';\nimport { BaseKeyDetail, CancelableEventHandler } from '../../../types/events';\nimport { OptionDefinition, OptionGroup } from '../../../types/option';\nimport { DropdownOption } from '../option/interfaces';\nimport { isGroupInteractive, isInteractive } from '../option/utils/filter-options';\nimport {\n HighlightedOptionHandlers,\n HighlightType,\n useHighlightedOption,\n} from '../options-list/utils/use-highlight-option';\nimport { getOptionId } from '../options-list/utils/use-ids';\nimport { useMenuKeyboard } from '../options-list/utils/use-keyboard';\nimport { ListElementProps, ScrollToIndexRef } from './interfaces';\nimport { SelectionModel } from './selection/interfaces';\nimport { useAnnouncement } from './use-announcement';\nimport { connectOptionsByValue } from './utils/connect-options';\nimport { getListboxNavigation } from './utils/navigation';\nimport {\n getListboxOptionProps,\n getListMouseHandlers,\n getSelectableOption,\n isAnnouncedSelected,\n isHighlightable,\n} from './utils/option-props';\n\nexport interface UseListboxProps {\n /** Rendered options in list order (flattened, filtered, including select-all). */\n options: ReadonlyArray<DropdownOption>;\n /** Selected options, matched to the rendered rows by value. */\n selectedOptions: ReadonlyArray<OptionDefinition>;\n /** Group and select-all state. */\n selection: SelectionModel;\n /** Whether group headers (and select-all) can be highlighted and chosen. */\n interactiveGroups: boolean;\n /** Called with the interactive option the user chose (Enter, Space, mouse up, or `selectOption`). */\n onSelect: (option: DropdownOption) => void;\n /**\n * 'always': Space always chooses the highlighted option.\n * 'keyboard-highlight': Space chooses only while an option has a keyboard highlight, so it still types into a\n * filter input.\n */\n spaceSelects: 'always' | 'keyboard-highlight';\n /** Called when Escape is pressed. When omitted, Escape is not handled and keeps propagating. */\n onEscape?: () => void;\n /** Group of the option, announced with the highlighted option. */\n getParent: (option: DropdownOption) => undefined | OptionGroup;\n /** Added to the announcement when the highlighted option is selected. */\n selectedAriaLabel?: string;\n /** Custom announcement for the highlighted option. */\n renderHighlightedAriaLive?: SelectProps.ContainingOptionAndGroupString;\n}\n\nexport type BaseListProps = Pick<\n ListElementProps,\n 'id' | 'ref' | 'onMouseUp' | 'onMouseMove' | 'onKeyDown' | 'onFocus' | 'onBlur' | 'nativeAttributes'\n>;\nexport interface UseListboxApi {\n /** Id of the list element; row ids are `getOptionId(listId, index)`. */\n listId: string;\n highlightedIndex: number;\n highlightType: HighlightType;\n highlightedOption: DropdownOption | undefined;\n /** Id of the highlighted row, for `aria-activedescendant`; undefined when `highlightedIndex` is -1. */\n activeDescendantId: string | undefined;\n /** Pass as `ref` to the list; it is called with `highlightedIndex` whenever the highlighted index changes. */\n scrollToIndex: RefObject<ScrollToIndexRef>;\n /** `selectedOptions` connected to rendered rows, in selection order. */\n selectedOptions: ReadonlyArray<DropdownOption>;\n /** Raw highlight setters from `useHighlightedOption`. */\n highlight: HighlightedOptionHandlers<DropdownOption>;\n /** Chooses `option`, or the highlighted option when omitted. Ignores non-interactive options. */\n selectOption(option?: DropdownOption): void;\n /** Keydown handler for the element that has focus (list or filter input). */\n onKeyDown: CancelableEventHandler<BaseKeyDetail>;\n /** `onMouseUp` / `onMouseMove` for the list element. */\n mouseHandlers: ReturnType<typeof getListMouseHandlers>;\n /** Ref of the list element, also set by `getListProps`. */\n listRef: RefObject<HTMLDivElement>;\n /**\n * Base props for the list element: id, ref and mouse handlers. With `withKeyboard`, also `onKeyDown` and\n * `aria-activedescendant`, for a list that has focus itself (not through a filter input). With `embedded`, also\n * `onFocus` and `onBlur`, for an embedded list: an always visible list that is a tab stop. Focus highlights the\n * first option if nothing is highlighted, and blur clears the highlight. A hover highlight is kept on focus, so a\n * click selects the hovered option. Moving focus to the selected option is a follow-up.\n * Callers that add native attributes spread `nativeAttributes`.\n */\n getListProps(options: { withKeyboard: boolean; embedded?: boolean }): BaseListProps;\n /** Props for the row at `index`. */\n getOptionProps(option: DropdownOption, index: number): ReturnType<typeof getListboxOptionProps>;\n /** Whether the live region announces the highlighted option as selected. */\n announceSelected: boolean;\n /** Live region text for the highlighted option. */\n announcement: string;\n}\n\n/**\n * List state shared by all list components: highlight, keyboard navigation, the choose guard, mouse handlers,\n * row props, scrolling the highlighted row into view, the active descendant and the live region announcement.\n * Focus handling of an embedded list is shared through `getListProps({ embedded })`. Open state, filter,\n * type-ahead and the highlight on open stay with the callers, because they differ per component.\n */\nexport function useListbox({\n options,\n selectedOptions: selectedOptionsProp,\n selection,\n interactiveGroups,\n onSelect,\n spaceSelects,\n onEscape,\n getParent,\n selectedAriaLabel,\n renderHighlightedAriaLive,\n}: UseListboxProps): UseListboxApi {\n const listId = useUniqueId('option-list');\n const selectedOptions = connectOptionsByValue(options, selectedOptionsProp);\n const selectedSet = new Set(selectedOptions);\n const [{ highlightType, highlightedOption, highlightedIndex }, highlight] = useHighlightedOption({\n options,\n isHighlightable: (option?: DropdownOption) => isHighlightable(option, interactiveGroups),\n });\n\n const interactivityCheck = interactiveGroups ? isGroupInteractive : isInteractive;\n const selectOption = (option?: DropdownOption) => {\n const optionToSelect = getSelectableOption(option, highlightedOption, interactivityCheck);\n if (optionToSelect) {\n onSelect(optionToSelect);\n }\n };\n\n const onKeyDown = useMenuKeyboard({\n ...getListboxNavigation({\n options,\n highlightedIndex,\n highlightedOption,\n interactiveGroups,\n moveHighlight: highlight.moveHighlightWithKeyboard,\n goHome: highlight.goHomeWithKeyboard,\n goEnd: highlight.goEndWithKeyboard,\n }),\n selectOption,\n goHome: highlight.goHomeWithKeyboard,\n goEnd: highlight.goEndWithKeyboard,\n onEscape,\n // With 'keyboard-highlight', Space chooses only while an option has a keyboard highlight, and types otherwise.\n preventNativeSpace: spaceSelects === 'always' || (!!highlightedOption && highlightType.type === 'keyboard'),\n });\n\n const mouseHandlers = getListMouseHandlers({\n options,\n selectOption,\n setHighlightedIndexWithMouse: highlight.setHighlightedIndexWithMouse,\n });\n\n const getOptionProps = (option: DropdownOption, index: number) =>\n getListboxOptionProps(option, index, {\n options,\n selectedSet,\n selection,\n highlightedOption,\n interactiveGroups,\n listId,\n });\n\n const announceSelected = isAnnouncedSelected(highlightedOption, selectedSet, selection);\n const announcement = useAnnouncement({\n announceSelected,\n highlightedOption,\n getParent,\n selectedAriaLabel,\n renderHighlightedAriaLive,\n });\n\n const activeDescendantId = getOptionId(listId, highlightedIndex);\n\n // Keeps the highlighted option scrolled into view in the list passed `ref={scrollToIndex}`.\n const scrollToIndex = useRef<ScrollToIndexRef>(null);\n useEffect(() => {\n scrollToIndex.current?.(highlightedIndex);\n }, [highlightedIndex]);\n\n const listRef = useRef<HTMLDivElement>(null);\n const getListProps = ({ withKeyboard, embedded }: { withKeyboard: boolean; embedded?: boolean }) => {\n const listProps: BaseListProps = { id: listId, ref: listRef, ...mouseHandlers };\n if (withKeyboard) {\n listProps.onKeyDown = onKeyDown;\n listProps.nativeAttributes = { 'aria-activedescendant': activeDescendantId };\n }\n if (embedded) {\n listProps.onFocus = () => {\n if (!highlightedOption) {\n highlight.goHomeWithKeyboard();\n }\n };\n listProps.onBlur = () => {\n highlight.resetHighlightWithKeyboard();\n };\n }\n return listProps;\n };\n\n return {\n listId,\n highlightedIndex,\n highlightType,\n highlightedOption,\n activeDescendantId,\n scrollToIndex,\n selectedOptions,\n highlight,\n selectOption,\n onKeyDown,\n mouseHandlers,\n listRef,\n getListProps,\n getOptionProps,\n announceSelected,\n announcement,\n };\n}\n"]}
@@ -0,0 +1,18 @@
1
+ import React from 'react';
2
+ import type { OptionDefinition } from '../../../types/option';
3
+ import type { DropdownOption } from '../option/interfaces';
4
+ interface UseTypeAheadProps {
5
+ isEnabled: boolean;
6
+ options: ReadonlyArray<DropdownOption>;
7
+ highlightOption: (option: DropdownOption) => void;
8
+ highlightedOption: OptionDefinition | undefined | null;
9
+ interactiveGroups?: boolean;
10
+ }
11
+ export declare function useTypeAhead({
12
+ isEnabled,
13
+ options,
14
+ highlightOption,
15
+ highlightedOption,
16
+ interactiveGroups
17
+ }: UseTypeAheadProps): (event: React.KeyboardEvent) => void;
18
+ export {};
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-type-ahead.d.ts","sourceRoot":"","sources":["../../../../../src/internal/components/listbox/use-type-ahead.ts"],"names":[],"mappings":"AAEA,OAAO,KAAiB,MAAM,OAAO,CAAC;AAEtC,OAAO,KAAK,EAAE,gBAAgB,EAAe,MAAM,uBAAuB,CAAC;AAE3E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAK3D,UAAU,iBAAiB;IACzB,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,EAAE,aAAa,CAAC,cAAc,CAAC,CAAC;IACvC,eAAe,EAAE,CAAC,MAAM,EAAE,cAAc,KAAK,IAAI,CAAC;IAClD,iBAAiB,EAAE,gBAAgB,GAAG,SAAS,GAAG,IAAI,CAAC;IACvD,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AA6CD,wBAAgB,YAAY,CAAC,EAC3B,SAAS,EACT,OAAO,EACP,eAAe,EACf,iBAAiB,EACjB,iBAAiB,GAClB,EAAE,iBAAiB,IAKV,OAAO,KAAK,CAAC,aAAa,UAoBnC"}
@@ -1,11 +1,11 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  import { useRef } from 'react';
4
- import { filterOptions, isGroup, isGroupInteractive, isInteractive, } from '../../internal/components/option/utils/filter-options';
5
- import { useDebounceCallback } from '../../internal/hooks/use-debounce-callback';
4
+ import { useDebounceCallback } from '../../hooks/use-debounce-callback';
5
+ import { filterOptions, isGroup, isGroupInteractive, isInteractive } from '../option/utils/filter-options';
6
6
  const isRepeatedChar = (str) => str.split('').every(c => c === str[0]);
7
- function findMatchingOption(options, searchText, currentHighlight, useInteractiveGroups) {
8
- const interactivityCheck = useInteractiveGroups ? isGroupInteractive : isInteractive;
7
+ function findMatchingOption(options, searchText, currentHighlight, interactiveGroups) {
8
+ const interactivityCheck = interactiveGroups ? isGroupInteractive : isInteractive;
9
9
  const filter = (searchText) => filterOptions(options, searchText, true).filter(option => interactivityCheck(option));
10
10
  const matchingOptions = filter(searchText);
11
11
  if (matchingOptions.length === 1) {
@@ -15,7 +15,7 @@ function findMatchingOption(options, searchText, currentHighlight, useInteractiv
15
15
  if (currentHighlight && searchText.length > 1 && isRepeatedChar(searchText)) {
16
16
  const matchingOptions = filter(searchText[0]);
17
17
  if (matchingOptions.length > 0) {
18
- //handling OptionGroups when useInteractiveGroups is set
18
+ //handling OptionGroups when interactiveGroups is set
19
19
  let active = isGroup(currentHighlight)
20
20
  ? matchingOptions.map(({ option }) => option).indexOf(currentHighlight)
21
21
  : matchingOptions
@@ -35,7 +35,7 @@ function findMatchingOption(options, searchText, currentHighlight, useInteractiv
35
35
  }
36
36
  return null;
37
37
  }
38
- export function useNativeSearch({ isEnabled, options, highlightOption, highlightedOption, useInteractiveGroups, }) {
38
+ export function useTypeAhead({ isEnabled, options, highlightOption, highlightedOption, interactiveGroups, }) {
39
39
  const value = useRef('');
40
40
  const delayedResetValue = useDebounceCallback(() => (value.current = ''), 500);
41
41
  return (event) => {
@@ -49,10 +49,10 @@ export function useNativeSearch({ isEnabled, options, highlightOption, highlight
49
49
  delayedResetValue();
50
50
  const newValue = value.current + key;
51
51
  value.current = newValue;
52
- const nextHighlight = findMatchingOption(options, newValue, highlightedOption, useInteractiveGroups);
52
+ const nextHighlight = findMatchingOption(options, newValue, highlightedOption, interactiveGroups);
53
53
  if (nextHighlight) {
54
54
  highlightOption(nextHighlight);
55
55
  }
56
56
  };
57
57
  }
58
- //# sourceMappingURL=use-native-search.js.map
58
+ //# sourceMappingURL=use-type-ahead.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-type-ahead.js","sourceRoot":"","sources":["../../../../../src/internal/components/listbox/use-type-ahead.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAc,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAGtC,OAAO,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AAExE,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAE3G,MAAM,cAAc,GAAG,CAAC,GAAW,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;AAU/E,SAAS,kBAAkB,CACzB,OAAsC,EACtC,UAAkB,EAClB,gBAAmE,EACnE,iBAA2B;IAE3B,MAAM,kBAAkB,GAAG,iBAAiB,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,aAAa,CAAC;IAClF,MAAM,MAAM,GAAG,CAAC,UAAkB,EAAE,EAAE,CACpC,aAAa,CAAC,O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;AAED,MAAM,UAAU,YAAY,CAAC,EAC3B,SAAS,EACT,OAAO,EACP,eAAe,EACf,iBAAiB,EACjB,iBAAiB,GACC;IAClB,MAAM,KAAK,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC;IAEzB,MAAM,iBAAiB,GAAG,mBAAmB,CAAC,GAAG,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,GAAG,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC;IAE/E,OAAO,CAAC,KAA0B,EAAE,EAAE;QACpC,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,OAAO;QACT,CAAC;QAED,MAAM,EAAE,GAAG,EAAE,GAAG,KAAK,CAAC;QAEtB,IAAI,CAAC,GAAG,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC7B,OAAO;QACT,CAAC;QAED,iBAAiB,EAAE,CAAC;QACpB,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,GAAG,GAAG,CAAC;QACrC,KAAK,CAAC,OAAO,GAAG,QAAQ,CAAC;QAEzB,MAAM,aAAa,GAAG,kBAAkB,CAAC,OAAO,EAAE,QAAQ,EAAE,iBAAiB,EAAE,iBAAiB,CAAC,CAAC;QAClG,IAAI,aAAa,EAAE,CAAC;YAClB,eAAe,CAAC,aAAa,CAAC,CAAC;QACjC,CAAC;IACH,CAAC,CAAC;AACJ,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React, { useRef } from 'react';\n\nimport type { OptionDefinition, OptionGroup } from '../../../types/option';\nimport { useDebounceCallback } from '../../hooks/use-debounce-callback';\nimport type { DropdownOption } from '../option/interfaces';\nimport { filterOptions, isGroup, isGroupInteractive, isInteractive } from '../option/utils/filter-options';\n\nconst isRepeatedChar = (str: string) => str.split('').every(c => c === str[0]);\n\ninterface UseTypeAheadProps {\n isEnabled: boolean;\n options: ReadonlyArray<DropdownOption>;\n highlightOption: (option: DropdownOption) => void;\n highlightedOption: OptionDefinition | undefined | null;\n interactiveGroups?: boolean;\n}\n\nfunction findMatchingOption(\n options: ReadonlyArray<DropdownOption>,\n searchText: string,\n currentHighlight: OptionDefinition | OptionGroup | undefined | null,\n interactiveGroups?: boolean\n) {\n const interactivityCheck = interactiveGroups ? isGroupInteractive : isInteractive;\n const filter = (searchText: string) =>\n filterOptions(options, searchText, true).filter(option => interactivityCheck(option));\n const matchingOptions = filter(searchText);\n\n if (matchingOptions.length === 1) {\n return matchingOptions[0];\n }\n\n // Hit the same char over and over, we assume they want to cycle through\n if (currentHighlight && searchText.length > 1 && isRepeatedChar(searchText)) {\n const matchingOptions = filter(searchText[0]);\n\n if (matchingOptions.length > 0) {\n //handling OptionGroups when interactiveGroups is set\n let active: number = isGroup(currentHighlight)\n ? matchingOptions.map(({ option }) => option).indexOf(currentHighlight)\n : matchingOptions\n .map(({ option }) => (option as OptionDefinition).value)\n .indexOf((currentHighlight as OptionDefinition).value);\n\n // Pick the next thing (if something with this prefix wasn't selected\n // we'll end up with the first option)\n active += 1;\n active = active % matchingOptions.length;\n return matchingOptions[active];\n }\n }\n\n // We have multiple things that start with this prefix. Based on the\n // behavior of native select, this is considered after the repeated case\n if (matchingOptions.length > 0) {\n return matchingOptions[0];\n }\n return null;\n}\n\nexport function useTypeAhead({\n isEnabled,\n options,\n highlightOption,\n highlightedOption,\n interactiveGroups,\n}: UseTypeAheadProps) {\n const value = useRef('');\n\n const delayedResetValue = useDebounceCallback(() => (value.current = ''), 500);\n\n return (event: React.KeyboardEvent) => {\n if (!isEnabled) {\n return;\n }\n\n const { key } = event;\n\n if (!key || key.length !== 1) {\n return;\n }\n\n delayedResetValue();\n const newValue = value.current + key;\n value.current = newValue;\n\n const nextHighlight = findMatchingOption(options, newValue, highlightedOption, interactiveGroups);\n if (nextHighlight) {\n highlightOption(nextHighlight);\n }\n };\n}\n"]}
@@ -0,0 +1,27 @@
1
+ import { DropdownOption } from '../../option/interfaces';
2
+ interface ListboxNavigationProps {
3
+ options: ReadonlyArray<DropdownOption>;
4
+ highlightedIndex: number;
5
+ highlightedOption: DropdownOption | undefined;
6
+ interactiveGroups: boolean;
7
+ moveHighlight: (direction: -1 | 1) => void;
8
+ goHome: () => void;
9
+ goEnd: () => void;
10
+ }
11
+ /**
12
+ * Arrow key handlers that wrap around the list: up from the first option goes to the end, down from the last row
13
+ * goes to the start. Without interactive groups, the first child of a leading group counts as the first option.
14
+ */
15
+ export declare const getListboxNavigation: ({
16
+ options,
17
+ highlightedIndex,
18
+ highlightedOption,
19
+ interactiveGroups,
20
+ moveHighlight,
21
+ goHome,
22
+ goEnd
23
+ }: ListboxNavigationProps) => {
24
+ goUp: () => void;
25
+ goDown: () => void;
26
+ };
27
+ export {};
@@ -0,0 +1 @@
1
+ {"version":3,"file":"navigation.d.ts","sourceRoot":"","sources":["../../../../../../src/internal/components/listbox/utils/navigation.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAEzD,UAAU,sBAAsB;IAC9B,OAAO,EAAE,aAAa,CAAC,cAAc,CAAC,CAAC;IACvC,gBAAgB,EAAE,MAAM,CAAC;IACzB,iBAAiB,EAAE,cAAc,GAAG,SAAS,CAAC;IAC9C,iBAAiB,EAAE,OAAO,CAAC;IAC3B,aAAa,EAAE,CAAC,SAAS,EAAE,CAAC,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC;IAC3C,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAED;;;GAGG;AACH,eAAO,MAAM,oBAAoB,GAAI,oGAQlC,sBAAsB;;;CAkBvB,CAAC"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Arrow key handlers that wrap around the list: up from the first option goes to the end, down from the last row
3
+ * goes to the start. Without interactive groups, the first child of a leading group counts as the first option.
4
+ */
5
+ export const getListboxNavigation = ({ options, highlightedIndex, highlightedOption, interactiveGroups, moveHighlight, goHome, goEnd, }) => ({
6
+ goUp: () => {
7
+ if ((!interactiveGroups && (highlightedOption === null || highlightedOption === void 0 ? void 0 : highlightedOption.type) === 'child' && highlightedIndex === 1) ||
8
+ highlightedIndex === 0) {
9
+ goEnd();
10
+ return;
11
+ }
12
+ moveHighlight(-1);
13
+ },
14
+ goDown: () => {
15
+ if (highlightedIndex === options.length - 1) {
16
+ goHome();
17
+ return;
18
+ }
19
+ moveHighlight(1);
20
+ },
21
+ });
22
+ //# sourceMappingURL=navigation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"navigation.js","sourceRoot":"","sources":["../../../../../../src/internal/components/listbox/utils/navigation.ts"],"names":[],"mappings":"AAcA;;;GAGG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,EACnC,OAAO,EACP,gBAAgB,EAChB,iBAAiB,EACjB,iBAAiB,EACjB,aAAa,EACb,MAAM,EACN,KAAK,GACkB,EAAE,EAAE,CAAC,CAAC;IAC7B,IAAI,EAAE,GAAG,EAAE;QACT,IACE,CAAC,CAAC,iBAAiB,IAAI,CAAA,iBAAiB,aAAjB,iBAAiB,uBAAjB,iBAAiB,CAAE,IAAI,MAAK,OAAO,IAAI,gBAAgB,KAAK,CAAC,CAAC;YACrF,gBAAgB,KAAK,CAAC,EACtB,CAAC;YACD,KAAK,EAAE,CAAC;YACR,OAAO;QACT,CAAC;QACD,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;IACD,MAAM,EAAE,GAAG,EAAE;QACX,IAAI,gBAAgB,KAAK,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC5C,MAAM,EAAE,CAAC;YACT,OAAO;QACT,CAAC;QACD,aAAa,CAAC,CAAC,CAAC,CAAC;IACnB,CAAC;CACF,CAAC,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { DropdownOption } from '../../option/interfaces';\n\ninterface ListboxNavigationProps {\n options: ReadonlyArray<DropdownOption>;\n highlightedIndex: number;\n highlightedOption: DropdownOption | undefined;\n interactiveGroups: boolean;\n moveHighlight: (direction: -1 | 1) => void;\n goHome: () => void;\n goEnd: () => void;\n}\n\n/**\n * Arrow key handlers that wrap around the list: up from the first option goes to the end, down from the last row\n * goes to the start. Without interactive groups, the first child of a leading group counts as the first option.\n */\nexport const getListboxNavigation = ({\n options,\n highlightedIndex,\n highlightedOption,\n interactiveGroups,\n moveHighlight,\n goHome,\n goEnd,\n}: ListboxNavigationProps) => ({\n goUp: () => {\n if (\n (!interactiveGroups && highlightedOption?.type === 'child' && highlightedIndex === 1) ||\n highlightedIndex === 0\n ) {\n goEnd();\n return;\n }\n moveHighlight(-1);\n },\n goDown: () => {\n if (highlightedIndex === options.length - 1) {\n goHome();\n return;\n }\n moveHighlight(1);\n },\n});\n"]}
@@ -0,0 +1,35 @@
1
+ import { DropdownOption } from '../../option/interfaces';
2
+ import { SelectionModel } from '../selection/interfaces';
3
+ /** Group headers can be highlighted only when groups are interactive. */
4
+ export declare const isHighlightable: (option: DropdownOption | undefined, interactiveGroups: boolean) => boolean;
5
+ interface OptionPropsContext {
6
+ /** Rendered options, in list order. */
7
+ options: ReadonlyArray<DropdownOption>;
8
+ /** Selected options, connected to the rendered options by `connectOptionsByValue`. */
9
+ selectedSet: ReadonlySet<DropdownOption>;
10
+ selection: SelectionModel;
11
+ highlightedOption: DropdownOption | undefined;
12
+ interactiveGroups: boolean;
13
+ listId: string;
14
+ }
15
+ /** Props for one listbox row. */
16
+ export declare function getListboxOptionProps(option: DropdownOption, index: number, context: OptionPropsContext): any;
17
+ /** The option to choose: `option`, or the highlighted option when omitted. Undefined when it isn't interactive. */
18
+ export declare const getSelectableOption: (option: DropdownOption | undefined, highlightedOption: DropdownOption | undefined, interactivityCheck: (option: DropdownOption) => boolean) => DropdownOption | undefined;
19
+ interface ListMouseHandlersProps {
20
+ options: ReadonlyArray<DropdownOption>;
21
+ selectOption: (option: DropdownOption) => void;
22
+ setHighlightedIndexWithMouse: (index: number) => void;
23
+ }
24
+ /** Mouse handlers for the list. An item index of -1 means the pointer isn't over a highlightable option. */
25
+ export declare const getListMouseHandlers: ({
26
+ options,
27
+ selectOption,
28
+ setHighlightedIndexWithMouse
29
+ }: ListMouseHandlersProps) => {
30
+ onMouseUp: (itemIndex: number) => void;
31
+ onMouseMove: (itemIndex: number) => void;
32
+ };
33
+ /** Whether the live region announces the highlighted option as selected. */
34
+ export declare const isAnnouncedSelected: (highlightedOption: DropdownOption | undefined, selectedSet: ReadonlySet<DropdownOption>, selection: SelectionModel) => boolean;
35
+ export {};
@@ -0,0 +1 @@
1
+ {"version":3,"file":"option-props.d.ts","sourceRoot":"","sources":["../../../../../../src/internal/components/listbox/utils/option-props.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAGzD,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAEzD,yEAAyE;AACzE,eAAO,MAAM,eAAe,GAAI,QAAQ,cAAc,GAAG,SAAS,EAAE,mBAAmB,OAAO,YACjC,CAAC;AAE9D,UAAU,kBAAkB;IAC1B,uCAAuC;IACvC,OAAO,EAAE,aAAa,CAAC,cAAc,CAAC,CAAC;IACvC,sFAAsF;IACtF,WAAW,EAAE,WAAW,CAAC,cAAc,CAAC,CAAC;IACzC,SAAS,EAAE,cAAc,CAAC;IAC1B,iBAAiB,EAAE,cAAc,GAAG,SAAS,CAAC;IAC9C,iBAAiB,EAAE,OAAO,CAAC;IAC3B,MAAM,EAAE,MAAM,CAAC;CAChB;AAYD,iCAAiC;AACjC,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,kBAAkB,OAiBvG;AAED,mHAAmH;AACnH,eAAO,MAAM,mBAAmB,GAC9B,QAAQ,cAAc,GAAG,SAAS,EAClC,mBAAmB,cAAc,GAAG,SAAS,EAC7C,oBAAoB,CAAC,MAAM,EAAE,cAAc,KAAK,OAAO,+BAIxD,CAAC;AAEF,UAAU,sBAAsB;IAC9B,OAAO,EAAE,aAAa,CAAC,cAAc,CAAC,CAAC;IACvC,YAAY,EAAE,CAAC,MAAM,EAAE,cAAc,KAAK,IAAI,CAAC;IAC/C,4BAA4B,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACvD;AAED,4GAA4G;AAC5G,eAAO,MAAM,oBAAoB,GAAI,0DAIlC,sBAAsB;2BACA,MAAM;6BAKJ,MAAM;CAK/B,CAAC;AAEH,4EAA4E;AAC5E,eAAO,MAAM,mBAAmB,GAC9B,mBAAmB,cAAc,GAAG,SAAS,EAC7C,aAAa,WAAW,CAAC,cAAc,CAAC,EACxC,WAAW,cAAc,YAIoE,CAAC"}
@@ -0,0 +1,51 @@
1
+ import { isGroup } from '../../option/utils/filter-options';
2
+ import { getOptionId } from '../../options-list/utils/use-ids';
3
+ /** Group headers can be highlighted only when groups are interactive. */
4
+ export const isHighlightable = (option, interactiveGroups) => !!option && (interactiveGroups || option.type !== 'parent');
5
+ // Only group neighbours use group state. Select-all never counts as a selected neighbour, so the row
6
+ // below it doesn't get the previous-item-selected style.
7
+ const isSelectedNeighbour = (option, { selectedSet, selection }) => !!option && isGroup(option.option)
8
+ ? selection.getGroupState(option).selected
9
+ : selectedSet.has(option);
10
+ /** Props for one listbox row. */
11
+ export function getListboxOptionProps(option, index, context) {
12
+ const { options, selectedSet, selection, highlightedOption, interactiveGroups, listId } = context;
13
+ const isSelectAll = option.type === 'select-all';
14
+ const groupState = isSelectAll || isGroup(option.option) ? selection.getGroupState(option) : undefined;
15
+ const selected = isSelectAll ? !!(groupState === null || groupState === void 0 ? void 0 : groupState.selected) : selectedSet.has(option) || !!(groupState === null || groupState === void 0 ? void 0 : groupState.selected);
16
+ const optionProps = {
17
+ key: index,
18
+ option,
19
+ highlighted: option === highlightedOption,
20
+ selected,
21
+ isNextSelected: isSelectedNeighbour(options[index + 1], context),
22
+ isPreviousSelected: isSelectedNeighbour(options[index - 1], context),
23
+ indeterminate: !!(groupState === null || groupState === void 0 ? void 0 : groupState.indeterminate),
24
+ ['data-mouse-target']: isHighlightable(option, interactiveGroups) ? index : -1,
25
+ id: getOptionId(listId, index),
26
+ };
27
+ return optionProps;
28
+ }
29
+ /** The option to choose: `option`, or the highlighted option when omitted. Undefined when it isn't interactive. */
30
+ export const getSelectableOption = (option, highlightedOption, interactivityCheck) => {
31
+ const optionToSelect = option || highlightedOption;
32
+ return optionToSelect && interactivityCheck(optionToSelect) ? optionToSelect : undefined;
33
+ };
34
+ /** Mouse handlers for the list. An item index of -1 means the pointer isn't over a highlightable option. */
35
+ export const getListMouseHandlers = ({ options, selectOption, setHighlightedIndexWithMouse, }) => ({
36
+ onMouseUp: (itemIndex) => {
37
+ if (itemIndex > -1) {
38
+ selectOption(options[itemIndex]);
39
+ }
40
+ },
41
+ onMouseMove: (itemIndex) => {
42
+ if (itemIndex > -1) {
43
+ setHighlightedIndexWithMouse(itemIndex);
44
+ }
45
+ },
46
+ });
47
+ /** Whether the live region announces the highlighted option as selected. */
48
+ export const isAnnouncedSelected = (highlightedOption, selectedSet, selection) => !!highlightedOption &&
49
+ (selectedSet.has(highlightedOption) ||
50
+ (isGroup(highlightedOption.option) && selection.getGroupState(highlightedOption).selected));
51
+ //# sourceMappingURL=option-props.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"option-props.js","sourceRoot":"","sources":["../../../../../../src/internal/components/listbox/utils/option-props.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAC;AAG/D,yEAAyE;AACzE,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,MAAkC,EAAE,iBAA0B,EAAE,EAAE,CAChG,CAAC,CAAC,MAAM,IAAI,CAAC,iBAAiB,IAAI,MAAM,CAAC,IAAI,KAAK,QAAQ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C,iBAAiB;IACnB,CAAC,WAAW,CAAC,GAAG,CAAC,iBAAiB,CAAC;QACjC,CAAC,OAAO,CAAC,iBAAiB,CAAC,MAAM,CAAC,IAAI,SAAS,CAAC,aAAa,CAAC,iBAAiB,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { DropdownOption } from '../../option/interfaces';\nimport { isGroup } from '../../option/utils/filter-options';\nimport { getOptionId } from '../../options-list/utils/use-ids';\nimport { SelectionModel } from '../selection/interfaces';\n\n/** Group headers can be highlighted only when groups are interactive. */\nexport const isHighlightable = (option: DropdownOption | undefined, interactiveGroups: boolean) =>\n !!option && (interactiveGroups || option.type !== 'parent');\n\ninterface OptionPropsContext {\n /** Rendered options, in list order. */\n options: ReadonlyArray<DropdownOption>;\n /** Selected options, connected to the rendered options by `connectOptionsByValue`. */\n selectedSet: ReadonlySet<DropdownOption>;\n selection: SelectionModel;\n highlightedOption: DropdownOption | undefined;\n interactiveGroups: boolean;\n listId: string;\n}\n\n// Only group neighbours use group state. Select-all never counts as a selected neighbour, so the row\n// below it doesn't get the previous-item-selected style.\nconst isSelectedNeighbour = (\n option: DropdownOption | undefined,\n { selectedSet, selection }: Pick<OptionPropsContext, 'selectedSet' | 'selection'>\n) =>\n !!option && isGroup(option.option)\n ? selection.getGroupState(option).selected\n : selectedSet.has(option as DropdownOption);\n\n/** Props for one listbox row. */\nexport function getListboxOptionProps(option: DropdownOption, index: number, context: OptionPropsContext) {\n const { options, selectedSet, selection, highlightedOption, interactiveGroups, listId } = context;\n const isSelectAll = option.type === 'select-all';\n const groupState = isSelectAll || isGroup(option.option) ? selection.getGroupState(option) : undefined;\n const selected = isSelectAll ? !!groupState?.selected : selectedSet.has(option) || !!groupState?.selected;\n const optionProps: any = {\n key: index,\n option,\n highlighted: option === highlightedOption,\n selected,\n isNextSelected: isSelectedNeighbour(options[index + 1], context),\n isPreviousSelected: isSelectedNeighbour(options[index - 1], context),\n indeterminate: !!groupState?.indeterminate,\n ['data-mouse-target']: isHighlightable(option, interactiveGroups) ? index : -1,\n id: getOptionId(listId, index),\n };\n return optionProps;\n}\n\n/** The option to choose: `option`, or the highlighted option when omitted. Undefined when it isn't interactive. */\nexport const getSelectableOption = (\n option: DropdownOption | undefined,\n highlightedOption: DropdownOption | undefined,\n interactivityCheck: (option: DropdownOption) => boolean\n) => {\n const optionToSelect = option || highlightedOption;\n return optionToSelect && interactivityCheck(optionToSelect) ? optionToSelect : undefined;\n};\n\ninterface ListMouseHandlersProps {\n options: ReadonlyArray<DropdownOption>;\n selectOption: (option: DropdownOption) => void;\n setHighlightedIndexWithMouse: (index: number) => void;\n}\n\n/** Mouse handlers for the list. An item index of -1 means the pointer isn't over a highlightable option. */\nexport const getListMouseHandlers = ({\n options,\n selectOption,\n setHighlightedIndexWithMouse,\n}: ListMouseHandlersProps) => ({\n onMouseUp: (itemIndex: number) => {\n if (itemIndex > -1) {\n selectOption(options[itemIndex]);\n }\n },\n onMouseMove: (itemIndex: number) => {\n if (itemIndex > -1) {\n setHighlightedIndexWithMouse(itemIndex);\n }\n },\n});\n\n/** Whether the live region announces the highlighted option as selected. */\nexport const isAnnouncedSelected = (\n highlightedOption: DropdownOption | undefined,\n selectedSet: ReadonlySet<DropdownOption>,\n selection: SelectionModel\n) =>\n !!highlightedOption &&\n (selectedSet.has(highlightedOption) ||\n (isGroup(highlightedOption.option) && selection.getGroupState(highlightedOption).selected));\n"]}
@@ -4,7 +4,10 @@ import { DropdownStatusProps } from '../../../types/dropdown-status';
4
4
  import { BaseKeyDetail, CancelableEventHandler, NonCancelableEventHandler } from '../../../types/events';
5
5
  export interface OptionsListProps extends BaseComponentProps {
6
6
  open?: boolean;
7
- statusType: DropdownStatusProps.StatusType;
7
+ /**
8
+ * When the list opens with `pending` status, `onLoadMore` fires right away. Defaults to `finished`.
9
+ */
10
+ statusType?: DropdownStatusProps.StatusType;
8
11
  /**
9
12
  * Options list
10
13
  */
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/internal/components/options-list/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAA4B,MAAM,OAAO,CAAC;AAMjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,sBAAsB,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AAMzG,MAAM,WAAW,gBAAiB,SAAQ,kBAAkB;IAC1D,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,UAAU,EAAE,mBAAmB,CAAC,UAAU,CAAC;IAC3C;;OAEG;IACH,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACvC;;OAEG;IACH,UAAU,CAAC,EAAE,yBAAyB,CAAC;IACvC,SAAS,CAAC,EAAE,sBAAsB,CAAC,aAAa,CAAC,CAAC;IAClD,MAAM,CAAC,EAAE,yBAAyB,CAAC;QAAE,aAAa,EAAE,IAAI,GAAG,IAAI,CAAA;KAAE,CAAC,CAAC;IACnE,OAAO,CAAC,EAAE,yBAAyB,CAAC;IACpC,SAAS,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;IACxC,WAAW,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;IAC1C,QAAQ,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;IAC3C,WAAW,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC;IAC3B,IAAI,CAAC,EAAE,SAAS,GAAG,MAAM,GAAG,MAAM,CAAC;IACnC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,e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C,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;IAC1C,QAAQ,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;IAC3C,WAAW,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC;IAC3B,IAAI,CAAC,EAAE,SAAS,GAAG,MAAM,GAAG,MAAM,CAAC;IACnC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,mBAAmB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,0FAA0F;IAC1F,gBAAgB,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;CACxC;;AA8FD,wBAA6C"}
@@ -13,7 +13,7 @@ const getItemIndex = (containerRef, event) => {
13
13
  const mouseTarget = target === null || target === void 0 ? void 0 : target.dataset.mouseTarget;
14
14
  return mouseTarget ? parseInt(mouseTarget) : -1;
15
15
  };
16
- const OptionsList = ({ open, statusType, children, nativeAttributes = {}, onKeyDown, onBlur, onFocus, onLoadMore, onMouseUp, onMouseMove, position = 'relative', role = 'listbox', tagOverride: Tag = 'div', decreaseBlockMargin = false, ariaLabel, ariaLabelledby, ariaDescribedby, ariaRequired, embedded, stickyItemBlockSize, isMultiSelect, customProperties, ...restProps }, ref) => {
16
+ const OptionsList = ({ open, statusType = 'finished', children, nativeAttributes = {}, onKeyDown, onBlur, onFocus, onLoadMore, onMouseUp, onMouseMove, position = 'relative', role = 'listbox', tagOverride: Tag = 'div', decreaseBlockMargin = false, ariaLabel, ariaLabelledby, ariaDescribedby, ariaRequired, embedded, stickyItemBlockSize, isMultiSelect, customProperties, ...restProps }, ref) => {
17
17
  const baseProps = getBaseProps(restProps);
18
18
  const menuRef = useRef(null);
19
19
  const handleScroll = useStableCallback(() => {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/internal/components/options-list/index.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AACjD,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,WAAW,EAAE,MAAM,0CAA0C,CAAC;AACvE,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,+CAA+C,CAAC;AAKhG,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAEzE,OAAO,MAAM,MAAM,iBAAiB,CAAC;AAkCrC,MAAM,qBAAqB,GAAG,EAAE,CAAC;AAEjC,MAAM,YAAY,GAAG,CAAC,YAA0C,EAAE,KAAuB,EAAE,EAAE;IAC3F,MAAM,MAAM,GAAG,WAAW,CACxB,KAAK,CAAC,MAAqB,EAC3B,OAAO,CAAC,EAAE,CAAC,OAAO,KAAK,YAAY,CAAC,OAAO,IAAI,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,WAAW,CAC7E,CAAC;IACF,MAAM,WAAW,GAAG,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,OAAO,CAAC,WAAW,CAAC;IAChD,OAAO,WAAW,CAAC,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAClD,CAAC,CAAC;AAEF,MAAM,WAAW,GAAG,CAClB,EACE,IAAI,EACJ,UAAU,EACV,QAAQ,EACR,gBAAgB,GAAG,EAAE,EACrB,SAAS,EACT,MAAM,EACN,OAAO,EACP,UAAU,EACV,SAAS,EACT,WAAW,EACX,QAAQ,GAAG,UAAU,EACrB,IAAI,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ACL,oBAAC,GAAG,OACE,SAAS,KACT,gBAAgB,EACpB,SAAS,EAAE,SAAS,EACpB,GAAG,EAAE,SAAS,EACd,KAAK,EAAE,EAAE,GAAG,gBAAgB,EAAE,QAAQ,EAAE,uBAAuB,EAAE,mBAAmB,aAAnB,mBAAmB,cAAnB,mBAAmB,GAAI,SAAS,EAAE,EACnG,IAAI,EAAE,IAAI,EACV,QAAQ,EAAE,YAAY,EACtB,SAAS,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CAAC,SAAS,EAAE,KAAK,CAAC,EACvD,WAAW,EAAE,KAAK,CAAC,EAAE,CAAC,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAG,YAAY,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,EACjE,SAAS,EAAE,KAAK,CAAC,EAAE,CAAC,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAG,YAAY,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,EAC7D,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC,sBAAsB,CAAC,MAAM,EAAE,EAAE,aAAa,EAAE,KAAK,CAAC,aAAa,EAAE,CAAC,EACvF,OAAO,EAAE,GAAG,EAAE,CAAC,sBAAsB,CAAC,OAAO,CAAC,EAC9C,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,gBACf,SAAS,qBACJ,cAAc,sBACb,eAAe,0BACX,IAAI,KAAK,SAAS,IAAI,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,mBAC7D,YAAY,IAE1B,IAAI,IAAI,QAAQ,CACb,CACP,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,KAAK,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React, { useEffect, useRef } from 'react';\nimport clsx from 'clsx';\n\nimport { findUpUntil } from '@cloudscape-design/component-toolkit/dom';\nimport { useMergeRefs, useStableCallback } from '@cloudscape-design/component-toolkit/internal';\n\nimport { BaseComponentProps } from '../../../types/base-component';\nimport { DropdownStatusProps } from '../../../types/dropdown-status';\nimport { BaseKeyDetail, CancelableEventHandler, NonCancelableEventHandler } from '../../../types/events';\nimport { getBaseProps } from '../../base-component';\nimport { fireKeyboardEvent, fireNonCancelableEvent } from '../../events';\n\nimport styles from './styles.css.js';\n\nexport interface OptionsListProps extends BaseComponentProps {\n open?: boolean;\n statusType: DropdownStatusProps.StatusType;\n /**\n * Options list\n */\n children: React.ReactNode;\n nativeAttributes?: Record<string, any>;\n /**\n * Called when more items need to be loaded.\n */\n onLoadMore?: NonCancelableEventHandler;\n onKeyDown?: CancelableEventHandler<BaseKeyDetail>;\n onBlur?: NonCancelableEventHandler<{ relatedTarget: Node | null }>;\n onFocus?: NonCancelableEventHandler;\n onMouseUp?: (itemIndex: number) => void;\n onMouseMove?: (itemIndex: number) => void;\n position?: React.CSSProperties['position'];\n tagOverride?: 'div' | 'ul';\n role?: 'listbox' | 'list' | 'menu';\n ariaLabel?: string;\n ariaLabelledby?: string;\n ariaDescribedby?: string;\n ariaRequired?: boolean;\n decreaseBlockMargin?: boolean;\n embedded?: boolean;\n stickyItemBlockSize?: number | null;\n isMultiSelect?: boolean;\n /** Internal: custom CSS properties set on the list root; inherited by the option rows. */\n customProperties?: React.CSSProperties;\n}\n\nconst BOTTOM_TRIGGER_OFFSET = 80;\n\nconst getItemIndex = (containerRef: React.RefObject<HTMLElement>, event: React.MouseEvent) => {\n const target = findUpUntil(\n event.target as HTMLElement,\n element => element === containerRef.current || !!element.dataset.mouseTarget\n );\n const mouseTarget = target?.dataset.mouseTarget;\n return mouseTarget ? parseInt(mouseTarget) : -1;\n};\n\nconst OptionsList = (\n {\n open,\n statusType,\n children,\n nativeAttributes = {},\n onKeyDown,\n onBlur,\n onFocus,\n onLoadMore,\n onMouseUp,\n onMouseMove,\n position = 'relative',\n role = 'listbox',\n tagOverride: Tag = 'div',\n decreaseBlockMargin = false,\n ariaLabel,\n ariaLabelledby,\n ariaDescribedby,\n ariaRequired,\n embedded,\n stickyItemBlockSize,\n isMultiSelect,\n customProperties,\n ...restProps\n }: OptionsListProps,\n ref: React.Ref<HTMLDivElement>\n) => {\n const baseProps = getBaseProps(restProps);\n const menuRef = useRef<HTMLElement>(null);\n\n const handleScroll = useStableCallback(() => {\n const scrollContainer = menuRef?.current;\n if (scrollContainer) {\n const bottomEdgePosition = scrollContainer.scrollTop + scrollContainer.clientHeight;\n const remainingScrollHeight = scrollContainer.scrollHeight - bottomEdgePosition;\n if (remainingScrollHeight < BOTTOM_TRIGGER_OFFSET) {\n fireNonCancelableEvent(onLoadMore);\n }\n }\n });\n\n useEffect(() => {\n if (open && statusType === 'pending') {\n handleScroll();\n }\n }, [open, statusType, handleScroll]);\n\n const className = clsx(styles['options-list'], {\n [styles['decrease-block-margin']]: decreaseBlockMargin,\n [styles['options-list-embedded']]: embedded,\n });\n\n const mergedRef = useMergeRefs(ref, menuRef);\n\n return (\n <Tag\n {...baseProps}\n {...nativeAttributes}\n className={className}\n ref={mergedRef}\n style={{ ...customProperties, position, scrollPaddingBlockStart: stickyItemBlockSize ?? undefined }}\n role={role}\n onScroll={handleScroll}\n onKeyDown={event => fireKeyboardEvent(onKeyDown, event)}\n onMouseMove={event => onMouseMove?.(getItemIndex(menuRef, event))}\n onMouseUp={event => onMouseUp?.(getItemIndex(menuRef, event))}\n onBlur={event => fireNonCancelableEvent(onBlur, { relatedTarget: event.relatedTarget })}\n onFocus={() => fireNonCancelableEvent(onFocus)}\n tabIndex={embedded ? 0 : -1}\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledby}\n aria-describedby={ariaDescribedby}\n aria-multiselectable={role === 'listbox' && isMultiSelect ? true : undefined}\n aria-required={ariaRequired}\n >\n {open && children}\n </Tag>\n );\n};\n\nexport default React.forwardRef(OptionsList);\n"]}
1
+ {"version":3,"file":"index.js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,EAAE,SAAS,EACd,KAAK,EAAE,EAAE,GAAG,gBAAgB,EAAE,QAAQ,EAAE,uBAAuB,EAAE,mBAAmB,aAAnB,mBAAmB,cAAnB,mBAAmB,GAAI,SAAS,EAAE,EACnG,IAAI,EAAE,IAAI,EACV,QAAQ,EAAE,YAAY,EACtB,SAAS,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CAAC,SAAS,EAAE,KAAK,CAAC,EACvD,WAAW,EAAE,KAAK,CAAC,EAAE,CAAC,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAG,YAAY,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,EACjE,SAAS,EAAE,KAAK,CAAC,EAAE,CAAC,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAG,YAAY,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,EAC7D,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC,sBAAsB,CAAC,MAAM,EAAE,EAAE,aAAa,EAAE,KAAK,CAAC,aAAa,EAAE,CAAC,EACvF,OAAO,EAAE,GAAG,EAAE,CAAC,sBAAsB,CAAC,OAAO,CAAC,EAC9C,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,gBACf,SAAS,qBACJ,cAAc,sBACb,eAAe,0BACX,IAAI,KAAK,SAAS,IAAI,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,mBAC7D,YAAY,IAE1B,IAAI,IAAI,QAAQ,CACb,CACP,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,KAAK,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React, { useEffect, useRef } from 'react';\nimport clsx from 'clsx';\n\nimport { findUpUntil } from '@cloudscape-design/component-toolkit/dom';\nimport { useMergeRefs, useStableCallback } from '@cloudscape-design/component-toolkit/internal';\n\nimport { BaseComponentProps } from '../../../types/base-component';\nimport { DropdownStatusProps } from '../../../types/dropdown-status';\nimport { BaseKeyDetail, CancelableEventHandler, NonCancelableEventHandler } from '../../../types/events';\nimport { getBaseProps } from '../../base-component';\nimport { fireKeyboardEvent, fireNonCancelableEvent } from '../../events';\n\nimport styles from './styles.css.js';\n\nexport interface OptionsListProps extends BaseComponentProps {\n open?: boolean;\n /**\n * When the list opens with `pending` status, `onLoadMore` fires right away. Defaults to `finished`.\n */\n statusType?: DropdownStatusProps.StatusType;\n /**\n * Options list\n */\n children: React.ReactNode;\n nativeAttributes?: Record<string, any>;\n /**\n * Called when more items need to be loaded.\n */\n onLoadMore?: NonCancelableEventHandler;\n onKeyDown?: CancelableEventHandler<BaseKeyDetail>;\n onBlur?: NonCancelableEventHandler<{ relatedTarget: Node | null }>;\n onFocus?: NonCancelableEventHandler;\n onMouseUp?: (itemIndex: number) => void;\n onMouseMove?: (itemIndex: number) => void;\n position?: React.CSSProperties['position'];\n tagOverride?: 'div' | 'ul';\n role?: 'listbox' | 'list' | 'menu';\n ariaLabel?: string;\n ariaLabelledby?: string;\n ariaDescribedby?: string;\n ariaRequired?: boolean;\n decreaseBlockMargin?: boolean;\n embedded?: boolean;\n stickyItemBlockSize?: number | null;\n isMultiSelect?: boolean;\n /** Internal: custom CSS properties set on the list root; inherited by the option rows. */\n customProperties?: React.CSSProperties;\n}\n\nconst BOTTOM_TRIGGER_OFFSET = 80;\n\nconst getItemIndex = (containerRef: React.RefObject<HTMLElement>, event: React.MouseEvent) => {\n const target = findUpUntil(\n event.target as HTMLElement,\n element => element === containerRef.current || !!element.dataset.mouseTarget\n );\n const mouseTarget = target?.dataset.mouseTarget;\n return mouseTarget ? parseInt(mouseTarget) : -1;\n};\n\nconst OptionsList = (\n {\n open,\n statusType = 'finished',\n children,\n nativeAttributes = {},\n onKeyDown,\n onBlur,\n onFocus,\n onLoadMore,\n onMouseUp,\n onMouseMove,\n position = 'relative',\n role = 'listbox',\n tagOverride: Tag = 'div',\n decreaseBlockMargin = false,\n ariaLabel,\n ariaLabelledby,\n ariaDescribedby,\n ariaRequired,\n embedded,\n stickyItemBlockSize,\n isMultiSelect,\n customProperties,\n ...restProps\n }: OptionsListProps,\n ref: React.Ref<HTMLDivElement>\n) => {\n const baseProps = getBaseProps(restProps);\n const menuRef = useRef<HTMLElement>(null);\n\n const handleScroll = useStableCallback(() => {\n const scrollContainer = menuRef?.current;\n if (scrollContainer) {\n const bottomEdgePosition = scrollContainer.scrollTop + scrollContainer.clientHeight;\n const remainingScrollHeight = scrollContainer.scrollHeight - bottomEdgePosition;\n if (remainingScrollHeight < BOTTOM_TRIGGER_OFFSET) {\n fireNonCancelableEvent(onLoadMore);\n }\n }\n });\n\n useEffect(() => {\n if (open && statusType === 'pending') {\n handleScroll();\n }\n }, [open, statusType, handleScroll]);\n\n const className = clsx(styles['options-list'], {\n [styles['decrease-block-margin']]: decreaseBlockMargin,\n [styles['options-list-embedded']]: embedded,\n });\n\n const mergedRef = useMergeRefs(ref, menuRef);\n\n return (\n <Tag\n {...baseProps}\n {...nativeAttributes}\n className={className}\n ref={mergedRef}\n style={{ ...customProperties, position, scrollPaddingBlockStart: stickyItemBlockSize ?? undefined }}\n role={role}\n onScroll={handleScroll}\n onKeyDown={event => fireKeyboardEvent(onKeyDown, event)}\n onMouseMove={event => onMouseMove?.(getItemIndex(menuRef, event))}\n onMouseUp={event => onMouseUp?.(getItemIndex(menuRef, event))}\n onBlur={event => fireNonCancelableEvent(onBlur, { relatedTarget: event.relatedTarget })}\n onFocus={() => fireNonCancelableEvent(onFocus)}\n tabIndex={embedded ? 0 : -1}\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledby}\n aria-describedby={ariaDescribedby}\n aria-multiselectable={role === 'listbox' && isMultiSelect ? true : undefined}\n aria-required={ariaRequired}\n >\n {open && children}\n </Tag>\n );\n};\n\nexport default React.forwardRef(OptionsList);\n"]}
@@ -6,7 +6,8 @@ interface UseMenuKeyboard {
6
6
  selectOption: () => void;
7
7
  goHome: () => void;
8
8
  goEnd: () => void;
9
- closeDropdown: () => void;
9
+ /** Escape handler. When omitted, Escape is not handled and keeps propagating. */
10
+ onEscape?: () => void;
10
11
  preventNativeSpace?: boolean;
11
12
  }): CancelableEventHandler<BaseKeyDetail>;
12
13
  }
@@ -1 +1 @@
1
- {"version":3,"file":"use-keyboard.d.ts","sourceRoot":"","sources":["../../../../../../src/internal/components/options-list/utils/use-keyboard.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAMjF,UAAU,eAAe;IACvB,CAAC,UAAU,EAAE;QACX,IAAI,EAAE,MAAM,IAAI,CAAC;QACjB,MAAM,EAAE,MAAM,IAAI,CAAC;QACnB,YAAY,EAAE,MAAM,IAAI,CAAC;QACzB,MAAM,EAAE,MAAM,IAAI,CAAC;QACnB,KAAK,EAAE,MAAM,IAAI,CAAC;QAClB,aAAa,EAAE,MAAM,IAAI,CAAC;QAC1B,kBAAkB,CAAC,EAAE,OAAO,CAAC;KAC9B,GAAG,sBAAsB,CAAC,aAAa,CAAC,CAAC;CAC3C;AAED,eAAO,MAAM,eAAe,EAAE,eAwC7B,CAAC;AAEF,UAAU,kBAAkB;IAC1B,CAAC,UAAU,EAAE;QAAE,YAAY,EAAE,MAAM,IAAI,CAAC;QAAC,MAAM,EAAE,MAAM,IAAI,CAAA;KAAE,GAAG,sBAAsB,CAAC,aAAa,CAAC,CAAC;CACvG;AAED,eAAO,MAAM,kBAAkB,EAAE,kBAgBhC,CAAC"}
1
+ {"version":3,"file":"use-keyboard.d.ts","sourceRoot":"","sources":["../../../../../../src/internal/components/options-list/utils/use-keyboard.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAMjF,UAAU,eAAe;IACvB,CAAC,UAAU,EAAE;QACX,IAAI,EAAE,MAAM,IAAI,CAAC;QACjB,MAAM,EAAE,MAAM,IAAI,CAAC;QACnB,YAAY,EAAE,MAAM,IAAI,CAAC;QACzB,MAAM,EAAE,MAAM,IAAI,CAAC;QACnB,KAAK,EAAE,MAAM,IAAI,CAAC;QAClB,iFAAiF;QACjF,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;QACtB,kBAAkB,CAAC,EAAE,OAAO,CAAC;KAC9B,GAAG,sBAAsB,CAAC,aAAa,CAAC,CAAC;CAC3C;AAED,eAAO,MAAM,eAAe,EAAE,eA0C7B,CAAC;AAEF,UAAU,kBAAkB;IAC1B,CAAC,UAAU,EAAE;QAAE,YAAY,EAAE,MAAM,IAAI,CAAC;QAAC,MAAM,EAAE,MAAM,IAAI,CAAA;KAAE,GAAG,sBAAsB,CAAC,aAAa,CAAC,CAAC;CACvG;AAED,eAAO,MAAM,kBAAkB,EAAE,kBAgBhC,CAAC"}
@@ -1,7 +1,7 @@
1
1
  import { KeyCode } from '../../../keycode';
2
2
  const HOME = 36;
3
3
  const END = 35;
4
- export const useMenuKeyboard = ({ goUp, goDown, selectOption, goHome, goEnd, closeDropdown, preventNativeSpace = false, }) => {
4
+ export const useMenuKeyboard = ({ goUp, goDown, selectOption, goHome, goEnd, onEscape, preventNativeSpace = false, }) => {
5
5
  return (event) => {
6
6
  switch (event.detail.keyCode) {
7
7
  case KeyCode.up:
@@ -19,8 +19,10 @@ export const useMenuKeyboard = ({ goUp, goDown, selectOption, goHome, goEnd, clo
19
19
  goEnd();
20
20
  break;
21
21
  case KeyCode.escape:
22
- event.stopPropagation();
23
- closeDropdown();
22
+ if (onEscape) {
23
+ event.stopPropagation();
24
+ onEscape();
25
+ }
24
26
  break;
25
27
  case KeyCode.enter:
26
28
  event.preventDefault();
@@ -1 +1 @@
1
- {"version":3,"file":"use-keyboard.js","sourceRoot":"","sources":["../../../../../../src/internal/components/options-list/utils/use-keyboard.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE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EAAE,CAAC;YAChB,KAAK,OAAO,CAAC,IAAI;gBACf,KAAK,CAAC,cAAc,EAAE,CAAC;gBACvB,MAAM,EAAE,CAAC;gBACT,YAAY,EAAE,CAAC;gBACf,MAAM;YACR,KAAK,OAAO,CAAC,KAAK,CAAC;YACnB,KAAK,OAAO,CAAC,KAAK;gBAChB,KAAK,CAAC,cAAc,EAAE,CAAC;gBACvB,YAAY,EAAE,CAAC;gBACf,MAAM;QACV,CAAC;IACH,CAAC,CAAC;AACJ,CAAC,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { BaseKeyDetail, CancelableEventHandler } from '../../../../types/events';\nimport { KeyCode } from '../../../keycode';\n\nconst HOME = 36;\nconst END = 35;\n\ninterface UseMenuKeyboard {\n (inputProps: {\n goUp: () => void;\n goDown: () => void;\n selectOption: () => void;\n goHome: () => void;\n goEnd: () => void;\n closeDropdown: () => void;\n preventNativeSpace?: boolean;\n }): CancelableEventHandler<BaseKeyDetail>;\n}\n\nexport const useMenuKeyboard: UseMenuKeyboard = ({\n goUp,\n goDown,\n selectOption,\n goHome,\n goEnd,\n closeDropdown,\n preventNativeSpace = false,\n}) => {\n return (event: CustomEvent<BaseKeyDetail>) => {\n switch (event.detail.keyCode) {\n case KeyCode.up:\n event.preventDefault();\n goUp();\n break;\n case KeyCode.down:\n event.preventDefault();\n goDown();\n break;\n case HOME:\n goHome();\n break;\n case END:\n goEnd();\n break;\n case KeyCode.escape:\n event.stopPropagation();\n closeDropdown();\n break;\n case KeyCode.enter:\n event.preventDefault();\n selectOption();\n break;\n case KeyCode.space:\n if (preventNativeSpace) {\n event.preventDefault();\n selectOption();\n }\n }\n };\n};\n\ninterface UseTriggerKeyboard {\n (inputProps: { openDropdown: () => void; goHome: () => void }): CancelableEventHandler<BaseKeyDetail>;\n}\n\nexport const useTriggerKeyboard: UseTriggerKeyboard = ({ openDropdown, goHome }) => {\n return (event: CustomEvent<BaseKeyDetail>) => {\n switch (event.detail.keyCode) {\n case KeyCode.up:\n case KeyCode.down:\n event.preventDefault();\n goHome();\n openDropdown();\n break;\n case KeyCode.space:\n case KeyCode.enter:\n event.preventDefault();\n openDropdown();\n break;\n }\n };\n};\n"]}
1
+ {"version":3,"file":"use-keyboard.js","sourceRoot":"","sources":["../../../../../../src/internal/components/options-list/utils/use-keyboard.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE3C,MAAM,IAAI,GAAG,EAAE,CAAC;AAChB,MAAM,GAAG,GAAG,EAAE,CAAC;AAef,MAAM,CAAC,MAAM,eAAe,GAAoB,CAAC,EAC/C,IAAI,EACJ,MAAM,EACN,YAAY,EACZ,MAAM,EACN,KAAK,EACL,QAAQ,EACR,kBAAkB,GAAG,KAAK,GAC3B,EAAE,EAAE;IACH,OAAO,CAAC,KAAiC,EAAE,EAAE;QAC3C,QAAQ,KAAK,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YAC7B,KAAK,OAAO,CAAC,EAAE;gBACb,KAAK,CAAC,cAAc,EAAE,CAAC;gBACvB,IAAI,EAAE,CAAC;gBACP,MAAM;YACR,KAAK,OAAO,CAAC,IAAI;gBACf,KAAK,CAAC,cAAc,EAAE,CAAC;gBACvB,MAAM,EAAE,CAAC;gBACT,MAAM;YACR,KAAK,IAAI;gBACP,MAAM,EAAE,CAAC;gBACT,MAAM;YACR,KAAK,GAAG;gBACN,KAAK,EAAE,CAAC;gBACR,MAAM;YACR,KAAK,OAAO,CAAC,MAAM;gBACjB,IAAI,QAAQ,EAAE,CAAC;oBACb,KAAK,CAAC,eAAe,EAAE,CAAC;oBACxB,QAAQ,EAAE,CAAC;gBACb,CAAC;gBACD,MAAM;YACR,KAAK,OAAO,CAAC,KAAK;gBAChB,KAAK,CAAC,cAAc,EAAE,CAAC;gBACvB,YAAY,EAAE,CAAC;gBACf,MAAM;YACR,KAAK,OAAO,CAAC,KAAK;gBAChB,IAAI,kBAAkB,EAAE,CAAC;oBACvB,KAAK,CAAC,cAAc,EAAE,CAAC;oBACvB,YAAY,EAAE,CAAC;gBACjB,CAAC;QACL,CAAC;IACH,CAAC,CAAC;AACJ,CAAC,CAAC;AAMF,MAAM,CAAC,MAAM,kBAAkB,GAAuB,CAAC,EAAE,YAAY,EAAE,MAAM,EAAE,EAAE,EAAE;IACjF,OAAO,CAAC,KAAiC,EAAE,EAAE;QAC3C,QAAQ,KAAK,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YAC7B,KAAK,OAAO,CAAC,EAAE,CAAC;YAChB,KAAK,OAAO,CAAC,IAAI;gBACf,KAAK,CAAC,cAAc,EAAE,CAAC;gBACvB,MAAM,EAAE,CAAC;gBACT,YAAY,EAAE,CAAC;gBACf,MAAM;YACR,KAAK,OAAO,CAAC,KAAK,CAAC;YACnB,KAAK,OAAO,CAAC,KAAK;gBAChB,KAAK,CAAC,cAAc,EAAE,CAAC;gBACvB,YAAY,EAAE,CAAC;gBACf,MAAM;QACV,CAAC;IACH,CAAC,CAAC;AACJ,CAAC,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { BaseKeyDetail, CancelableEventHandler } from '../../../../types/events';\nimport { KeyCode } from '../../../keycode';\n\nconst HOME = 36;\nconst END = 35;\n\ninterface UseMenuKeyboard {\n (inputProps: {\n goUp: () => void;\n goDown: () => void;\n selectOption: () => void;\n goHome: () => void;\n goEnd: () => void;\n /** Escape handler. When omitted, Escape is not handled and keeps propagating. */\n onEscape?: () => void;\n preventNativeSpace?: boolean;\n }): CancelableEventHandler<BaseKeyDetail>;\n}\n\nexport const useMenuKeyboard: UseMenuKeyboard = ({\n goUp,\n goDown,\n selectOption,\n goHome,\n goEnd,\n onEscape,\n preventNativeSpace = false,\n}) => {\n return (event: CustomEvent<BaseKeyDetail>) => {\n switch (event.detail.keyCode) {\n case KeyCode.up:\n event.preventDefault();\n goUp();\n break;\n case KeyCode.down:\n event.preventDefault();\n goDown();\n break;\n case HOME:\n goHome();\n break;\n case END:\n goEnd();\n break;\n case KeyCode.escape:\n if (onEscape) {\n event.stopPropagation();\n onEscape();\n }\n break;\n case KeyCode.enter:\n event.preventDefault();\n selectOption();\n break;\n case KeyCode.space:\n if (preventNativeSpace) {\n event.preventDefault();\n selectOption();\n }\n }\n };\n};\n\ninterface UseTriggerKeyboard {\n (inputProps: { openDropdown: () => void; goHome: () => void }): CancelableEventHandler<BaseKeyDetail>;\n}\n\nexport const useTriggerKeyboard: UseTriggerKeyboard = ({ openDropdown, goHome }) => {\n return (event: CustomEvent<BaseKeyDetail>) => {\n switch (event.detail.keyCode) {\n case KeyCode.up:\n case KeyCode.down:\n event.preventDefault();\n goHome();\n openDropdown();\n break;\n case KeyCode.space:\n case KeyCode.enter:\n event.preventDefault();\n openDropdown();\n break;\n }\n };\n};\n"]}
@@ -25,6 +25,7 @@ declare const _default: React.ForwardRefExoticComponent<import("../../base-compo
25
25
  sticky?: boolean;
26
26
  afterHeader?: boolean;
27
27
  withScrollbar?: boolean;
28
+ hideTopDivider?: boolean;
28
29
  ariaSelected?: boolean | never;
29
30
  ariaChecked?: boolean | "mixed" | never;
30
31
  } & React.RefAttributes<HTMLDivElement>>;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/internal/components/selectable-item/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAkC,MAAM,OAAO,CAAC;AAQvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAKnD,OAAO,EAAE,mBAAmB,EAAE,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmI/B,wBAAgD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/internal/components/selectable-item/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAkC,MAAM,OAAO,CAAC;AAQvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAKnD,OAAO,EAAE,mBAAmB,EAAE,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqI/B,wBAAgD"}
@@ -8,7 +8,7 @@ import { getBaseProps } from '../../base-component';
8
8
  import { getAnalyticsSelectActionMetadata } from './analytics-metadata/utils';
9
9
  import analyticsSelectors from './analytics-metadata/styles.css.js';
10
10
  import styles from './styles.css.js';
11
- const SelectableItem = ({ children: content, ariaSelected, ariaChecked, selected, highlighted, disabled, hasBackground, isParent, isChild, isSelectAll, virtualPosition, padBottom, disableContentStyling, isNextSelected, isPreviousSelected, useInteractiveGroups, screenReaderContent, ariaPosinset, ariaSetsize, highlightType, value, sticky, afterHeader, withScrollbar, ...restProps }, ref) => {
11
+ const SelectableItem = ({ children: content, ariaSelected, ariaChecked, selected, highlighted, disabled, hasBackground, isParent, isChild, isSelectAll, virtualPosition, padBottom, disableContentStyling, isNextSelected, isPreviousSelected, useInteractiveGroups, screenReaderContent, ariaPosinset, ariaSetsize, highlightType, value, sticky, afterHeader, withScrollbar, hideTopDivider, ...restProps }, ref) => {
12
12
  const isVisualRefresh = useVisualRefresh();
13
13
  const { className, ...rest } = getBaseProps(restProps);
14
14
  const classNames = clsx(className, styles['selectable-item'], {
@@ -29,6 +29,7 @@ const SelectableItem = ({ children: content, ariaSelected, ariaChecked, selected
29
29
  [styles.sticky]: sticky,
30
30
  [styles['after-header']]: !!afterHeader,
31
31
  [styles['with-scrollbar']]: withScrollbar,
32
+ [styles['hide-top-divider']]: hideTopDivider,
32
33
  [styles['visual-refresh']]: isVisualRefresh,
33
34
  });
34
35
  const contentClassNames = clsx(styles['option-content'], analyticsSelectors['option-content'], {