@fluentui/react-combobox 9.0.0-beta.9 → 9.0.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 (302) hide show
  1. package/CHANGELOG.json +848 -1
  2. package/CHANGELOG.md +248 -2
  3. package/README.md +1 -3
  4. package/dist/index.d.ts +62 -11
  5. package/lib/Combobox.js.map +1 -1
  6. package/lib/ComboboxField.js +2 -0
  7. package/lib/ComboboxField.js.map +1 -0
  8. package/lib/Dropdown.js.map +1 -1
  9. package/lib/Listbox.js.map +1 -1
  10. package/lib/Option.js.map +1 -1
  11. package/lib/OptionGroup.js.map +1 -1
  12. package/lib/components/Combobox/Combobox.js +0 -1
  13. package/lib/components/Combobox/Combobox.js.map +1 -1
  14. package/lib/components/Combobox/Combobox.types.js.map +1 -1
  15. package/lib/components/Combobox/index.js.map +1 -1
  16. package/lib/components/Combobox/renderCombobox.js +10 -6
  17. package/lib/components/Combobox/renderCombobox.js.map +1 -1
  18. package/lib/components/Combobox/useCombobox.js +107 -70
  19. package/lib/components/Combobox/useCombobox.js.map +1 -1
  20. package/lib/components/Combobox/useComboboxStyles.js +246 -185
  21. package/lib/components/Combobox/useComboboxStyles.js.map +1 -1
  22. package/lib/components/ComboboxField/ComboboxField.js +8 -0
  23. package/lib/components/ComboboxField/ComboboxField.js.map +1 -0
  24. package/lib/components/ComboboxField/index.js +2 -0
  25. package/lib/components/ComboboxField/index.js.map +1 -0
  26. package/lib/components/Dropdown/Dropdown.js +0 -1
  27. package/lib/components/Dropdown/Dropdown.js.map +1 -1
  28. package/lib/components/Dropdown/Dropdown.types.js.map +1 -1
  29. package/lib/components/Dropdown/index.js.map +1 -1
  30. package/lib/components/Dropdown/renderDropdown.js +10 -6
  31. package/lib/components/Dropdown/renderDropdown.js.map +1 -1
  32. package/lib/components/Dropdown/useDropdown.js +25 -36
  33. package/lib/components/Dropdown/useDropdown.js.map +1 -1
  34. package/lib/components/Dropdown/useDropdownStyles.js +236 -176
  35. package/lib/components/Dropdown/useDropdownStyles.js.map +1 -1
  36. package/lib/components/Listbox/Listbox.js +0 -1
  37. package/lib/components/Listbox/Listbox.js.map +1 -1
  38. package/lib/components/Listbox/Listbox.types.js.map +1 -1
  39. package/lib/components/Listbox/index.js.map +1 -1
  40. package/lib/components/Listbox/renderListbox.js +2 -2
  41. package/lib/components/Listbox/renderListbox.js.map +1 -1
  42. package/lib/components/Listbox/useListbox.js +15 -17
  43. package/lib/components/Listbox/useListbox.js.map +1 -1
  44. package/lib/components/Listbox/useListboxStyles.js +16 -20
  45. package/lib/components/Listbox/useListboxStyles.js.map +1 -1
  46. package/lib/components/Option/Option.js +0 -1
  47. package/lib/components/Option/Option.js.map +1 -1
  48. package/lib/components/Option/Option.types.js.map +1 -1
  49. package/lib/components/Option/index.js.map +1 -1
  50. package/lib/components/Option/renderOption.js +4 -3
  51. package/lib/components/Option/renderOption.js.map +1 -1
  52. package/lib/components/Option/useOption.js +46 -39
  53. package/lib/components/Option/useOption.js.map +1 -1
  54. package/lib/components/Option/useOptionStyles.js +101 -79
  55. package/lib/components/Option/useOptionStyles.js.map +1 -1
  56. package/lib/components/OptionGroup/OptionGroup.js +0 -1
  57. package/lib/components/OptionGroup/OptionGroup.js.map +1 -1
  58. package/lib/components/OptionGroup/OptionGroup.types.js.map +1 -1
  59. package/lib/components/OptionGroup/index.js.map +1 -1
  60. package/lib/components/OptionGroup/renderOptionGroup.js +4 -3
  61. package/lib/components/OptionGroup/renderOptionGroup.js.map +1 -1
  62. package/lib/components/OptionGroup/useOptionGroup.js +0 -1
  63. package/lib/components/OptionGroup/useOptionGroup.js.map +1 -1
  64. package/lib/components/OptionGroup/useOptionGroupStyles.js +29 -34
  65. package/lib/components/OptionGroup/useOptionGroupStyles.js.map +1 -1
  66. package/lib/contexts/ComboboxContext.js +9 -11
  67. package/lib/contexts/ComboboxContext.js.map +1 -1
  68. package/lib/contexts/ListboxContext.js +7 -9
  69. package/lib/contexts/ListboxContext.js.map +1 -1
  70. package/lib/contexts/useComboboxContextValues.js.map +1 -1
  71. package/lib/contexts/useListboxContextValues.js +2 -2
  72. package/lib/contexts/useListboxContextValues.js.map +1 -1
  73. package/lib/index.js +6 -0
  74. package/lib/index.js.map +1 -1
  75. package/lib/utils/ComboboxBase.types.js.map +1 -1
  76. package/lib/utils/OptionCollection.types.js.map +1 -1
  77. package/lib/utils/Selection.types.js.map +1 -1
  78. package/lib/utils/dropdownKeyActions.js +12 -33
  79. package/lib/utils/dropdownKeyActions.js.map +1 -1
  80. package/lib/utils/internalTokens.js.map +1 -1
  81. package/lib/utils/useComboboxBaseState.js +29 -30
  82. package/lib/utils/useComboboxBaseState.js.map +1 -1
  83. package/lib/utils/useComboboxPopup.js +6 -4
  84. package/lib/utils/useComboboxPopup.js.map +1 -1
  85. package/lib/utils/useOptionCollection.js +13 -23
  86. package/lib/utils/useOptionCollection.js.map +1 -1
  87. package/lib/utils/useScrollOptionsIntoView.js +36 -0
  88. package/lib/utils/useScrollOptionsIntoView.js.map +1 -0
  89. package/lib/utils/useSelection.js +9 -12
  90. package/lib/utils/useSelection.js.map +1 -1
  91. package/lib/utils/useTriggerListboxSlots.js +34 -40
  92. package/lib/utils/useTriggerListboxSlots.js.map +1 -1
  93. package/lib-amd/Combobox.js +6 -0
  94. package/lib-amd/Combobox.js.map +1 -0
  95. package/lib-amd/ComboboxField.js +6 -0
  96. package/lib-amd/ComboboxField.js.map +1 -0
  97. package/lib-amd/Dropdown.js +6 -0
  98. package/lib-amd/Dropdown.js.map +1 -0
  99. package/lib-amd/Listbox.js +6 -0
  100. package/lib-amd/Listbox.js.map +1 -0
  101. package/lib-amd/Option.js +6 -0
  102. package/lib-amd/Option.js.map +1 -0
  103. package/lib-amd/OptionGroup.js +6 -0
  104. package/lib-amd/OptionGroup.js.map +1 -0
  105. package/lib-amd/components/Combobox/Combobox.js +16 -0
  106. package/lib-amd/components/Combobox/Combobox.js.map +1 -0
  107. package/lib-amd/components/Combobox/Combobox.types.js +5 -0
  108. package/lib-amd/components/Combobox/Combobox.types.js.map +1 -0
  109. package/lib-amd/components/Combobox/index.js +10 -0
  110. package/lib-amd/components/Combobox/index.js.map +1 -0
  111. package/lib-amd/components/Combobox/renderCombobox.js +20 -0
  112. package/lib-amd/components/Combobox/renderCombobox.js.map +1 -0
  113. package/lib-amd/components/Combobox/useCombobox.js +206 -0
  114. package/lib-amd/components/Combobox/useCombobox.js.map +1 -0
  115. package/lib-amd/components/Combobox/useComboboxStyles.js +152 -0
  116. package/lib-amd/components/Combobox/useComboboxStyles.js.map +1 -0
  117. package/lib-amd/components/ComboboxField/ComboboxField.js +10 -0
  118. package/lib-amd/components/ComboboxField/ComboboxField.js.map +1 -0
  119. package/lib-amd/components/ComboboxField/index.js +6 -0
  120. package/lib-amd/components/ComboboxField/index.js.map +1 -0
  121. package/lib-amd/components/Dropdown/Dropdown.js +16 -0
  122. package/lib-amd/components/Dropdown/Dropdown.js.map +1 -0
  123. package/lib-amd/components/Dropdown/Dropdown.types.js +5 -0
  124. package/lib-amd/components/Dropdown/Dropdown.types.js.map +1 -0
  125. package/lib-amd/components/Dropdown/index.js +10 -0
  126. package/lib-amd/components/Dropdown/index.js.map +1 -0
  127. package/lib-amd/components/Dropdown/renderDropdown.js +21 -0
  128. package/lib-amd/components/Dropdown/renderDropdown.js.map +1 -0
  129. package/lib-amd/components/Dropdown/useDropdown.js +121 -0
  130. package/lib-amd/components/Dropdown/useDropdown.js.map +1 -0
  131. package/lib-amd/components/Dropdown/useDropdownStyles.js +127 -0
  132. package/lib-amd/components/Dropdown/useDropdownStyles.js.map +1 -0
  133. package/lib-amd/components/Listbox/Listbox.js +16 -0
  134. package/lib-amd/components/Listbox/Listbox.js.map +1 -0
  135. package/lib-amd/components/Listbox/Listbox.types.js +5 -0
  136. package/lib-amd/components/Listbox/Listbox.types.js.map +1 -0
  137. package/lib-amd/components/Listbox/index.js +10 -0
  138. package/lib-amd/components/Listbox/index.js.map +1 -0
  139. package/lib-amd/components/Listbox/renderListbox.js +15 -0
  140. package/lib-amd/components/Listbox/renderListbox.js.map +1 -0
  141. package/lib-amd/components/Listbox/useListbox.js +80 -0
  142. package/lib-amd/components/Listbox/useListbox.js.map +1 -0
  143. package/lib-amd/components/Listbox/useListboxStyles.js +24 -0
  144. package/lib-amd/components/Listbox/useListboxStyles.js.map +1 -0
  145. package/lib-amd/components/Option/Option.js +15 -0
  146. package/lib-amd/components/Option/Option.js.map +1 -0
  147. package/lib-amd/components/Option/Option.types.js +5 -0
  148. package/lib-amd/components/Option/Option.types.js.map +1 -0
  149. package/lib-amd/components/Option/index.js +10 -0
  150. package/lib-amd/components/Option/index.js.map +1 -0
  151. package/lib-amd/components/Option/renderOption.js +16 -0
  152. package/lib-amd/components/Option/renderOption.js.map +1 -0
  153. package/lib-amd/components/Option/useOption.js +117 -0
  154. package/lib-amd/components/Option/useOption.js.map +1 -0
  155. package/lib-amd/components/Option/useOptionStyles.js +73 -0
  156. package/lib-amd/components/Option/useOptionStyles.js.map +1 -0
  157. package/lib-amd/components/OptionGroup/OptionGroup.js +15 -0
  158. package/lib-amd/components/OptionGroup/OptionGroup.js.map +1 -0
  159. package/lib-amd/components/OptionGroup/OptionGroup.types.js +5 -0
  160. package/lib-amd/components/OptionGroup/OptionGroup.types.js.map +1 -0
  161. package/lib-amd/components/OptionGroup/index.js +10 -0
  162. package/lib-amd/components/OptionGroup/index.js.map +1 -0
  163. package/lib-amd/components/OptionGroup/renderOptionGroup.js +16 -0
  164. package/lib-amd/components/OptionGroup/renderOptionGroup.js.map +1 -0
  165. package/lib-amd/components/OptionGroup/useOptionGroup.js +33 -0
  166. package/lib-amd/components/OptionGroup/useOptionGroup.js.map +1 -0
  167. package/lib-amd/components/OptionGroup/useOptionGroupStyles.js +34 -0
  168. package/lib-amd/components/OptionGroup/useOptionGroupStyles.js.map +1 -0
  169. package/lib-amd/contexts/ComboboxContext.js +28 -0
  170. package/lib-amd/contexts/ComboboxContext.js.map +1 -0
  171. package/lib-amd/contexts/ListboxContext.js +23 -0
  172. package/lib-amd/contexts/ListboxContext.js.map +1 -0
  173. package/lib-amd/contexts/useComboboxContextValues.js +23 -0
  174. package/lib-amd/contexts/useComboboxContextValues.js.map +1 -0
  175. package/lib-amd/contexts/useListboxContextValues.js +24 -0
  176. package/lib-amd/contexts/useListboxContextValues.js.map +1 -0
  177. package/lib-amd/index.js +37 -0
  178. package/lib-amd/index.js.map +1 -0
  179. package/lib-amd/utils/ComboboxBase.types.js +5 -0
  180. package/lib-amd/utils/ComboboxBase.types.js.map +1 -0
  181. package/lib-amd/utils/OptionCollection.types.js +5 -0
  182. package/lib-amd/utils/OptionCollection.types.js.map +1 -0
  183. package/lib-amd/utils/Selection.types.js +5 -0
  184. package/lib-amd/utils/Selection.types.js.map +1 -0
  185. package/lib-amd/utils/dropdownKeyActions.js +85 -0
  186. package/lib-amd/utils/dropdownKeyActions.js.map +1 -0
  187. package/lib-amd/utils/internalTokens.js +11 -0
  188. package/lib-amd/utils/internalTokens.js.map +1 -0
  189. package/lib-amd/utils/useComboboxBaseState.js +76 -0
  190. package/lib-amd/utils/useComboboxBaseState.js.map +1 -0
  191. package/lib-amd/utils/useComboboxPopup.js +16 -0
  192. package/lib-amd/utils/useComboboxPopup.js.map +1 -0
  193. package/lib-amd/utils/useOptionCollection.js +65 -0
  194. package/lib-amd/utils/useOptionCollection.js.map +1 -0
  195. package/lib-amd/utils/useScrollOptionsIntoView.js +33 -0
  196. package/lib-amd/utils/useScrollOptionsIntoView.js.map +1 -0
  197. package/lib-amd/utils/useSelection.js +42 -0
  198. package/lib-amd/utils/useSelection.js.map +1 -0
  199. package/lib-amd/utils/useTriggerListboxSlots.js +104 -0
  200. package/lib-amd/utils/useTriggerListboxSlots.js.map +1 -0
  201. package/lib-commonjs/Combobox.js +0 -2
  202. package/lib-commonjs/Combobox.js.map +1 -1
  203. package/lib-commonjs/ComboboxField.js +8 -0
  204. package/lib-commonjs/ComboboxField.js.map +1 -0
  205. package/lib-commonjs/Dropdown.js +0 -2
  206. package/lib-commonjs/Dropdown.js.map +1 -1
  207. package/lib-commonjs/Listbox.js +0 -2
  208. package/lib-commonjs/Listbox.js.map +1 -1
  209. package/lib-commonjs/Option.js +0 -2
  210. package/lib-commonjs/Option.js.map +1 -1
  211. package/lib-commonjs/OptionGroup.js +0 -2
  212. package/lib-commonjs/OptionGroup.js.map +1 -1
  213. package/lib-commonjs/components/Combobox/Combobox.js +0 -7
  214. package/lib-commonjs/components/Combobox/Combobox.js.map +1 -1
  215. package/lib-commonjs/components/Combobox/Combobox.types.js.map +1 -1
  216. package/lib-commonjs/components/Combobox/index.js +0 -6
  217. package/lib-commonjs/components/Combobox/index.js.map +1 -1
  218. package/lib-commonjs/components/Combobox/renderCombobox.js +10 -12
  219. package/lib-commonjs/components/Combobox/renderCombobox.js.map +1 -1
  220. package/lib-commonjs/components/Combobox/useCombobox.js +106 -78
  221. package/lib-commonjs/components/Combobox/useCombobox.js.map +1 -1
  222. package/lib-commonjs/components/Combobox/useComboboxStyles.js +245 -189
  223. package/lib-commonjs/components/Combobox/useComboboxStyles.js.map +1 -1
  224. package/lib-commonjs/components/ComboboxField/ComboboxField.js +14 -0
  225. package/lib-commonjs/components/ComboboxField/ComboboxField.js.map +1 -0
  226. package/lib-commonjs/components/ComboboxField/index.js +8 -0
  227. package/lib-commonjs/components/ComboboxField/index.js.map +1 -0
  228. package/lib-commonjs/components/Dropdown/Dropdown.js +0 -7
  229. package/lib-commonjs/components/Dropdown/Dropdown.js.map +1 -1
  230. package/lib-commonjs/components/Dropdown/Dropdown.types.js.map +1 -1
  231. package/lib-commonjs/components/Dropdown/index.js +0 -6
  232. package/lib-commonjs/components/Dropdown/index.js.map +1 -1
  233. package/lib-commonjs/components/Dropdown/renderDropdown.js +10 -12
  234. package/lib-commonjs/components/Dropdown/renderDropdown.js.map +1 -1
  235. package/lib-commonjs/components/Dropdown/useDropdown.js +25 -47
  236. package/lib-commonjs/components/Dropdown/useDropdown.js.map +1 -1
  237. package/lib-commonjs/components/Dropdown/useDropdownStyles.js +235 -180
  238. package/lib-commonjs/components/Dropdown/useDropdownStyles.js.map +1 -1
  239. package/lib-commonjs/components/Listbox/Listbox.js +0 -7
  240. package/lib-commonjs/components/Listbox/Listbox.js.map +1 -1
  241. package/lib-commonjs/components/Listbox/Listbox.types.js.map +1 -1
  242. package/lib-commonjs/components/Listbox/index.js +0 -6
  243. package/lib-commonjs/components/Listbox/index.js.map +1 -1
  244. package/lib-commonjs/components/Listbox/renderListbox.js +2 -7
  245. package/lib-commonjs/components/Listbox/renderListbox.js.map +1 -1
  246. package/lib-commonjs/components/Listbox/useListbox.js +14 -25
  247. package/lib-commonjs/components/Listbox/useListbox.js.map +1 -1
  248. package/lib-commonjs/components/Listbox/useListboxStyles.js +16 -24
  249. package/lib-commonjs/components/Listbox/useListboxStyles.js.map +1 -1
  250. package/lib-commonjs/components/Option/Option.js +0 -6
  251. package/lib-commonjs/components/Option/Option.js.map +1 -1
  252. package/lib-commonjs/components/Option/Option.types.js.map +1 -1
  253. package/lib-commonjs/components/Option/index.js +0 -6
  254. package/lib-commonjs/components/Option/index.js.map +1 -1
  255. package/lib-commonjs/components/Option/renderOption.js +4 -7
  256. package/lib-commonjs/components/Option/renderOption.js.map +1 -1
  257. package/lib-commonjs/components/Option/useOption.js +45 -45
  258. package/lib-commonjs/components/Option/useOption.js.map +1 -1
  259. package/lib-commonjs/components/Option/useOptionStyles.js +101 -83
  260. package/lib-commonjs/components/Option/useOptionStyles.js.map +1 -1
  261. package/lib-commonjs/components/OptionGroup/OptionGroup.js +0 -6
  262. package/lib-commonjs/components/OptionGroup/OptionGroup.js.map +1 -1
  263. package/lib-commonjs/components/OptionGroup/OptionGroup.types.js.map +1 -1
  264. package/lib-commonjs/components/OptionGroup/index.js +0 -6
  265. package/lib-commonjs/components/OptionGroup/index.js.map +1 -1
  266. package/lib-commonjs/components/OptionGroup/renderOptionGroup.js +4 -7
  267. package/lib-commonjs/components/OptionGroup/renderOptionGroup.js.map +1 -1
  268. package/lib-commonjs/components/OptionGroup/useOptionGroup.js +0 -4
  269. package/lib-commonjs/components/OptionGroup/useOptionGroup.js.map +1 -1
  270. package/lib-commonjs/components/OptionGroup/useOptionGroupStyles.js +29 -38
  271. package/lib-commonjs/components/OptionGroup/useOptionGroupStyles.js.map +1 -1
  272. package/lib-commonjs/contexts/ComboboxContext.js +10 -14
  273. package/lib-commonjs/contexts/ComboboxContext.js.map +1 -1
  274. package/lib-commonjs/contexts/ListboxContext.js +8 -12
  275. package/lib-commonjs/contexts/ListboxContext.js.map +1 -1
  276. package/lib-commonjs/contexts/useComboboxContextValues.js +0 -2
  277. package/lib-commonjs/contexts/useComboboxContextValues.js.map +1 -1
  278. package/lib-commonjs/contexts/useListboxContextValues.js +2 -6
  279. package/lib-commonjs/contexts/useListboxContextValues.js.map +1 -1
  280. package/lib-commonjs/index.js +43 -11
  281. package/lib-commonjs/index.js.map +1 -1
  282. package/lib-commonjs/utils/ComboboxBase.types.js.map +1 -1
  283. package/lib-commonjs/utils/OptionCollection.types.js.map +1 -1
  284. package/lib-commonjs/utils/Selection.types.js.map +1 -1
  285. package/lib-commonjs/utils/dropdownKeyActions.js +12 -37
  286. package/lib-commonjs/utils/dropdownKeyActions.js.map +1 -1
  287. package/lib-commonjs/utils/internalTokens.js.map +1 -1
  288. package/lib-commonjs/utils/useComboboxBaseState.js +29 -36
  289. package/lib-commonjs/utils/useComboboxBaseState.js.map +1 -1
  290. package/lib-commonjs/utils/useComboboxPopup.js +6 -8
  291. package/lib-commonjs/utils/useComboboxPopup.js.map +1 -1
  292. package/lib-commonjs/utils/useOptionCollection.js +13 -26
  293. package/lib-commonjs/utils/useOptionCollection.js.map +1 -1
  294. package/lib-commonjs/utils/useScrollOptionsIntoView.js +43 -0
  295. package/lib-commonjs/utils/useScrollOptionsIntoView.js.map +1 -0
  296. package/lib-commonjs/utils/useSelection.js +9 -15
  297. package/lib-commonjs/utils/useSelection.js.map +1 -1
  298. package/lib-commonjs/utils/useTriggerListboxSlots.js +33 -44
  299. package/lib-commonjs/utils/useTriggerListboxSlots.js.map +1 -1
  300. package/package.json +23 -22
  301. package/Spec-migration.md +0 -13
  302. package/Spec.md +0 -520
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OptionCollection.types.js","sourceRoot":"","sources":["../../../../../../../../packages/react-components/react-combobox/src/utils/OptionCollection.types.ts"],"names":[],"mappings":"","sourcesContent":["export type OptionValue = {\n /** The disabled state of the option. */\n disabled?: boolean;\n\n /** The `id` attribute of the option. */\n id: string;\n\n /** The `text` string for the option. */\n text: string;\n\n /** The value string of the option. */\n value: string;\n};\n\nexport type OptionCollectionState = {\n /** The total number of options in the collection. */\n getCount: () => number;\n\n /** Returns the index of an option by key. */\n getIndexOfId(id: string): number;\n\n /** Returns the option data for the nth option. */\n getOptionAtIndex(index: number): OptionValue | undefined;\n\n /** Returns the option data by key. */\n getOptionById(id: string): OptionValue | undefined;\n\n /** Returns an array of options filtered by a value matching function against the option's text string. */\n getOptionsMatchingText(matcher: (value: string) => boolean): OptionValue[];\n\n /** The unordered option data. */\n options: OptionValue[];\n\n /* A function that child options call to register their values. Returns a function to unregister the option. */\n registerOption: (option: OptionValue, element: HTMLElement) => () => void;\n};\n"]}
@@ -0,0 +1,5 @@
1
+ define(["require", "exports"], function (require, exports) {
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ });
5
+ //# sourceMappingURL=Selection.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Selection.types.js","sourceRoot":"","sources":["../../../../../../../../packages/react-components/react-combobox/src/utils/Selection.types.ts"],"names":[],"mappings":"","sourcesContent":["import * as React from 'react';\nimport { OptionValue } from './OptionCollection.types';\n\nexport type SelectionProps = {\n /* For an uncontrolled component, sets the initial selection */\n defaultSelectedOptions?: string[];\n\n /**\n * Sets the selection type to multiselect.\n * Set this to true for multiselect, even if fully controlling selection state.\n * This enables styles and accessibility properties to be set.\n * @default false\n */\n multiselect?: boolean;\n\n /* Callback when an option is selected */\n onOptionSelect?: (event: SelectionEvents, data: OptionOnSelectData) => void;\n\n /**\n * An array of selected option keys.\n * Use this with `onOptionSelect` to directly control the selected option(s)\n */\n selectedOptions?: string[];\n};\n\n/* Values returned by the useSelection hook */\nexport type SelectionState = {\n clearSelection: (event: SelectionEvents) => void;\n selectedOptions: string[];\n selectOption: (event: SelectionEvents, option: OptionValue) => void;\n};\n\n/*\n * Data for the onOptionSelect callback.\n * `optionValue` and `optionText` will be undefined if multiple options are modified at once.\n */\nexport type OptionOnSelectData = {\n optionValue: string | undefined;\n optionText: string | undefined;\n selectedOptions: string[];\n};\n\n/* Possible event types for onOptionSelect */\nexport type SelectionEvents =\n | React.ChangeEvent<HTMLElement>\n | React.KeyboardEvent<HTMLElement>\n | React.MouseEvent<HTMLElement>;\n"]}
@@ -0,0 +1,85 @@
1
+ define(["require", "exports", "@fluentui/keyboard-keys"], function (require, exports, keys) {
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.getIndexFromAction = exports.getDropdownActionFromKey = void 0;
5
+ /**
6
+ * Converts a keyboard interaction into a defined action
7
+ */
8
+ function getDropdownActionFromKey(e, options) {
9
+ if (options === void 0) { options = {}; }
10
+ var _a = options.open, open = _a === void 0 ? true : _a, _b = options.multiselect, multiselect = _b === void 0 ? false : _b;
11
+ var code = e.key;
12
+ var altKey = e.altKey, ctrlKey = e.ctrlKey, key = e.key, metaKey = e.metaKey;
13
+ // typing action occurs whether open or closed
14
+ if (key.length === 1 && code !== keys.Space && !altKey && !ctrlKey && !metaKey) {
15
+ return 'Type';
16
+ }
17
+ // handle opening the dropdown if closed
18
+ if (!open) {
19
+ if (code === keys.ArrowDown || code === keys.ArrowUp || code === keys.Enter || code === keys.Space) {
20
+ return 'Open';
21
+ }
22
+ // if the dropdown is closed and an action did not match the above, do nothing
23
+ return 'None';
24
+ }
25
+ // select or close actions
26
+ if ((code === keys.ArrowUp && altKey) || code === keys.Enter || (!multiselect && code === keys.Space)) {
27
+ return 'CloseSelect';
28
+ }
29
+ if (multiselect && code === keys.Space) {
30
+ return 'Select';
31
+ }
32
+ if (code === keys.Escape) {
33
+ return 'Close';
34
+ }
35
+ // navigation interactions
36
+ if (code === keys.ArrowDown) {
37
+ return 'Next';
38
+ }
39
+ if (code === keys.ArrowUp) {
40
+ return 'Previous';
41
+ }
42
+ if (code === keys.Home) {
43
+ return 'First';
44
+ }
45
+ if (code === keys.End) {
46
+ return 'Last';
47
+ }
48
+ if (code === keys.PageUp) {
49
+ return 'PageUp';
50
+ }
51
+ if (code === keys.PageDown) {
52
+ return 'PageDown';
53
+ }
54
+ if (code === keys.Tab) {
55
+ return 'Tab';
56
+ }
57
+ // if nothing matched, return none
58
+ return 'None';
59
+ }
60
+ exports.getDropdownActionFromKey = getDropdownActionFromKey;
61
+ /**
62
+ * Returns the requested option index from an action
63
+ */
64
+ function getIndexFromAction(action, currentIndex, maxIndex) {
65
+ switch (action) {
66
+ case 'Next':
67
+ return Math.min(maxIndex, currentIndex + 1);
68
+ break;
69
+ case 'Previous':
70
+ return Math.max(0, currentIndex - 1);
71
+ case 'First':
72
+ return 0;
73
+ case 'Last':
74
+ return maxIndex;
75
+ case 'PageDown':
76
+ return Math.min(maxIndex, currentIndex + 10);
77
+ case 'PageUp':
78
+ return Math.max(0, currentIndex - 10);
79
+ default:
80
+ return currentIndex;
81
+ }
82
+ }
83
+ exports.getIndexFromAction = getIndexFromAction;
84
+ });
85
+ //# sourceMappingURL=dropdownKeyActions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dropdownKeyActions.js","sourceRoot":"","sources":["../../../../../../../../packages/react-components/react-combobox/src/utils/dropdownKeyActions.ts"],"names":[],"mappings":";;;;IA2BA;;OAEG;IACH,SAAgB,wBAAwB,CACtC,CAAsC,EACtC,OAAmC;QAAnC,wBAAA,EAAA,YAAmC;QAE3B,IAAA,KAAqC,OAAO,KAAjC,EAAX,IAAI,mBAAG,IAAI,KAAA,EAAE,KAA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,UAAU,CAAC;SACnB;QACD,IAAI,IAAI,KAAK,IAAI,CAAC,IAAI,EAAE;YACtB,OAAO,OAAO,CAAC;SAChB;QACD,IAAI,IAAI,KAAK,IAAI,CAAC,GAAG,EAAE;YACrB,OAAO,MAAM,CAAC;SACf;QACD,IAAI,IAAI,KAAK,IAAI,CAAC,MAAM,EAAE;YACxB,OAAO,QAAQ,CAAC;SACjB;QACD,IAAI,IAAI,KAAK,IAAI,CAAC,QAAQ,EAAE;YAC1B,OAAO,UAAU,CAAC;SACnB;QACD,IAAI,IAAI,KAAK,IAAI,CAAC,GAAG,EAAE;YACrB,OAAO,KAAK,CAAC;SACd;QAED,kCAAkC;QAClC,OAAO,MAAM,CAAC;IAChB,CAAC;IA3DD,4DA2DC;IAED;;OAEG;IACH,SAAgB,kBAAkB,CAAC,MAAuB,EAAE,YAAoB,EAAE,QAAgB;QAChG,QAAQ,MAAM,EAAE;YACd,KAAK,MAAM;gBACT,OAAO,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,YAAY,GAAG,CAAC,CAAC,CAAC;gBAC5C,MAAM;YACR,KAAK,UAAU;gBACb,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,YAAY,GAAG,CAAC,CAAC,CAAC;YACvC,KAAK,OAAO;gBACV,OAAO,CAAC,CAAC;YACX,KAAK,MAAM;gBACT,OAAO,QAAQ,CAAC;YAClB,KAAK,UAAU;gBACb,OAAO,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,YAAY,GAAG,EAAE,CAAC,CAAC;YAC/C,KAAK,QAAQ;gBACX,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,YAAY,GAAG,EAAE,CAAC,CAAC;YACxC;gBACE,OAAO,YAAY,CAAC;SACvB;IACH,CAAC;IAlBD,gDAkBC","sourcesContent":["import * as keys from '@fluentui/keyboard-keys';\nimport * as React from 'react';\n\n/**\n * enum of actions available in any type of managed dropdown control\n * e.g. combobox, select, datepicker, menu\n */\nexport type DropdownActions =\n | 'Close'\n | 'CloseSelect'\n | 'First'\n | 'Last'\n | 'Next'\n | 'None'\n | 'Open'\n | 'PageDown'\n | 'PageUp'\n | 'Previous'\n | 'Select'\n | 'Tab'\n | 'Type';\n\nexport interface DropdownActionOptions {\n open?: boolean;\n multiselect?: boolean;\n}\n\n/**\n * Converts a keyboard interaction into a defined action\n */\nexport function getDropdownActionFromKey(\n e: KeyboardEvent | React.KeyboardEvent,\n options: DropdownActionOptions = {},\n): DropdownActions {\n const { open = true, multiselect = false } = options;\n const code = e.key;\n const { altKey, ctrlKey, key, metaKey } = e;\n\n // typing action occurs whether open or closed\n if (key.length === 1 && code !== keys.Space && !altKey && !ctrlKey && !metaKey) {\n return 'Type';\n }\n\n // handle opening the dropdown if closed\n if (!open) {\n if (code === keys.ArrowDown || code === keys.ArrowUp || code === keys.Enter || code === keys.Space) {\n return 'Open';\n }\n\n // if the dropdown is closed and an action did not match the above, do nothing\n return 'None';\n }\n\n // select or close actions\n if ((code === keys.ArrowUp && altKey) || code === keys.Enter || (!multiselect && code === keys.Space)) {\n return 'CloseSelect';\n }\n if (multiselect && code === keys.Space) {\n return 'Select';\n }\n if (code === keys.Escape) {\n return 'Close';\n }\n\n // navigation interactions\n if (code === keys.ArrowDown) {\n return 'Next';\n }\n if (code === keys.ArrowUp) {\n return 'Previous';\n }\n if (code === keys.Home) {\n return 'First';\n }\n if (code === keys.End) {\n return 'Last';\n }\n if (code === keys.PageUp) {\n return 'PageUp';\n }\n if (code === keys.PageDown) {\n return 'PageDown';\n }\n if (code === keys.Tab) {\n return 'Tab';\n }\n\n // if nothing matched, return none\n return 'None';\n}\n\n/**\n * Returns the requested option index from an action\n */\nexport function getIndexFromAction(action: DropdownActions, currentIndex: number, maxIndex: number): number {\n switch (action) {\n case 'Next':\n return Math.min(maxIndex, currentIndex + 1);\n break;\n case 'Previous':\n return Math.max(0, currentIndex - 1);\n case 'First':\n return 0;\n case 'Last':\n return maxIndex;\n case 'PageDown':\n return Math.min(maxIndex, currentIndex + 10);\n case 'PageUp':\n return Math.max(0, currentIndex - 10);\n default:\n return currentIndex;\n }\n}\n"]}
@@ -0,0 +1,11 @@
1
+ define(["require", "exports"], function (require, exports) {
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.iconSizes = void 0;
5
+ exports.iconSizes = {
6
+ small: '16px',
7
+ medium: '20px',
8
+ large: '24px',
9
+ };
10
+ });
11
+ //# sourceMappingURL=internalTokens.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internalTokens.js","sourceRoot":"","sources":["../../../../../../../../packages/react-components/react-combobox/src/utils/internalTokens.ts"],"names":[],"mappings":";;;;IAAa,QAAA,SAAS,GAAG;QACvB,KAAK,EAAE,MAAM;QACb,MAAM,EAAE,MAAM;QACd,KAAK,EAAE,MAAM;KACd,CAAC","sourcesContent":["export const iconSizes = {\n small: '16px',\n medium: '20px',\n large: '24px',\n};\n"]}
@@ -0,0 +1,76 @@
1
+ define(["require", "exports", "tslib", "react", "@fluentui/react-utilities", "../utils/useOptionCollection", "../utils/useSelection"], function (require, exports, tslib_1, React, react_utilities_1, useOptionCollection_1, useSelection_1) {
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.useComboboxBaseState = void 0;
5
+ /**
6
+ * State shared between Combobox and Dropdown components
7
+ */
8
+ var useComboboxBaseState = function (props) {
9
+ var _a = props.appearance, appearance = _a === void 0 ? 'outline' : _a, children = props.children, _b = props.editable, editable = _b === void 0 ? false : _b, _c = props.inlinePopup, inlinePopup = _c === void 0 ? false : _c, multiselect = props.multiselect, onOpenChange = props.onOpenChange, _d = props.size, size = _d === void 0 ? 'medium' : _d;
10
+ var optionCollection = useOptionCollection_1.useOptionCollection();
11
+ var getOptionAtIndex = optionCollection.getOptionAtIndex, getOptionsMatchingText = optionCollection.getOptionsMatchingText;
12
+ var _e = React.useState(), activeOption = _e[0], setActiveOption = _e[1];
13
+ // track whether keyboard focus outline should be shown
14
+ // tabster/keyborg doesn't work here, since the actual keyboard focus target doesn't move
15
+ var _f = React.useState(false), focusVisible = _f[0], setFocusVisible = _f[1];
16
+ // track focused state to conditionally render collapsed listbox
17
+ var _g = React.useState(false), hasFocus = _g[0], setHasFocus = _g[1];
18
+ var ignoreNextBlur = React.useRef(false);
19
+ var selectionState = useSelection_1.useSelection(props);
20
+ var selectedOptions = selectionState.selectedOptions;
21
+ // calculate value based on props, internal value changes, and selected options
22
+ var isFirstMount = react_utilities_1.useFirstMount();
23
+ var _h = react_utilities_1.useControllableState({
24
+ state: props.value,
25
+ initialState: undefined,
26
+ }), controllableValue = _h[0], setValue = _h[1];
27
+ var value = React.useMemo(function () {
28
+ // don't compute the value if it is defined through props or setValue,
29
+ if (controllableValue !== undefined) {
30
+ return controllableValue;
31
+ }
32
+ // handle defaultValue here, so it is overridden by selection
33
+ if (isFirstMount && props.defaultValue !== undefined) {
34
+ return props.defaultValue;
35
+ }
36
+ if (multiselect) {
37
+ // editable inputs should not display multiple selected options in the input as text
38
+ return editable ? '' : selectedOptions.join(', ');
39
+ }
40
+ return selectedOptions[0];
41
+ }, [controllableValue, editable, isFirstMount, multiselect, props.defaultValue, selectedOptions]);
42
+ // Handle open state, which is shared with options in context
43
+ var _j = react_utilities_1.useControllableState({
44
+ state: props.open,
45
+ defaultState: props.defaultOpen,
46
+ initialState: false,
47
+ }), open = _j[0], setOpenState = _j[1];
48
+ var setOpen = React.useCallback(function (event, newState) {
49
+ onOpenChange === null || onOpenChange === void 0 ? void 0 : onOpenChange(event, { open: newState });
50
+ setOpenState(newState);
51
+ }, [onOpenChange, setOpenState]);
52
+ // update active option based on change in open state or children
53
+ React.useEffect(function () {
54
+ if (open && !activeOption) {
55
+ // if it is single-select and there is a selected option, start at the selected option
56
+ if (!multiselect && selectedOptions.length > 0) {
57
+ var selectedOption = getOptionsMatchingText(function (v) { return v === selectedOptions[0]; }).pop();
58
+ selectedOption && setActiveOption(selectedOption);
59
+ }
60
+ // default to starting at the first option
61
+ else {
62
+ setActiveOption(getOptionAtIndex(0));
63
+ }
64
+ }
65
+ else if (!open) {
66
+ // reset the active option when closing
67
+ setActiveOption(undefined);
68
+ }
69
+ // this should only be run in response to changes in the open state or children
70
+ // eslint-disable-next-line react-hooks/exhaustive-deps
71
+ }, [open, children]);
72
+ return tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, optionCollection), selectionState), { activeOption: activeOption, appearance: appearance, focusVisible: focusVisible, hasFocus: hasFocus, ignoreNextBlur: ignoreNextBlur, inlinePopup: inlinePopup, open: open, setActiveOption: setActiveOption, setFocusVisible: setFocusVisible, setHasFocus: setHasFocus, setOpen: setOpen, setValue: setValue, size: size, value: value });
73
+ };
74
+ exports.useComboboxBaseState = useComboboxBaseState;
75
+ });
76
+ //# sourceMappingURL=useComboboxBaseState.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useComboboxBaseState.js","sourceRoot":"","sources":["../../../../../../../../packages/react-components/react-combobox/src/utils/useComboboxBaseState.ts"],"names":[],"mappings":";;;;IAOA;;OAEG;IACI,IAAM,oBAAoB,GAAG,UAClC,KAA6E;QAG3E,IAAA,KAOE,KAAK,WAPe,EAAtB,UAAU,mBAAG,SAAS,KAAA,EACtB,QAAQ,GAMN,KAAK,SANC,EACR,KAKE,KAAK,SALS,EAAhB,QAAQ,mBAAG,KAAK,KAAA,EAChB,KAIE,KAAK,YAJY,EAAnB,WAAW,mBAAG,KAAK,KAAA,EACnB,WAAW,GAGT,KAAK,YAHI,EACX,YAAY,GAEV,KAAK,aAFK,EACZ,KACE,KAAK,KADQ,EAAf,IAAI,mBAAG,QAAQ,KAAA,CACP;QAEV,IAAM,gBAAgB,GAAG,yCAAmB,EAAE,CAAC;QACvC,IAAA,gBAAgB,GAA6B,gBAAgB,iBAA7C,EAAE,sBAAsB,GAAK,gBAAgB,uBAArB,CAAsB;QAEhE,IAAA,KAAkC,KAAK,CAAC,QAAQ,EAA2B,EAA1E,YAAY,QAAA,EAAE,eAAe,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WAAW,aAAA,EACX,IAAI,MAAA,EACJ,eAAe,iBAAA,EACf,eAAe,iBAAA,EACf,WAAW,aAAA,EACX,OAAO,SAAA,EACP,QAAQ,UAAA,EACR,IAAI,MAAA,EACJ,KAAK,OAAA,IACL;IACJ,CAAC,CAAC;IA7GW,QAAA,oBAAoB,wBA6G/B","sourcesContent":["import * as React from 'react';\nimport { useControllableState, useFirstMount } from '@fluentui/react-utilities';\nimport { useOptionCollection } from '../utils/useOptionCollection';\nimport { OptionValue } from '../utils/OptionCollection.types';\nimport { useSelection } from '../utils/useSelection';\nimport type { ComboboxBaseProps, ComboboxBaseOpenEvents, ComboboxBaseState } from './ComboboxBase.types';\n\n/**\n * State shared between Combobox and Dropdown components\n */\nexport const useComboboxBaseState = (\n props: ComboboxBaseProps & { children?: React.ReactNode; editable?: boolean },\n): ComboboxBaseState => {\n const {\n appearance = 'outline',\n children,\n editable = false,\n inlinePopup = false,\n multiselect,\n onOpenChange,\n size = 'medium',\n } = props;\n\n const optionCollection = useOptionCollection();\n const { getOptionAtIndex, getOptionsMatchingText } = optionCollection;\n\n const [activeOption, setActiveOption] = React.useState<OptionValue | undefined>();\n\n // track whether keyboard focus outline should be shown\n // tabster/keyborg doesn't work here, since the actual keyboard focus target doesn't move\n const [focusVisible, setFocusVisible] = React.useState(false);\n\n // track focused state to conditionally render collapsed listbox\n const [hasFocus, setHasFocus] = React.useState(false);\n\n const ignoreNextBlur = React.useRef(false);\n\n const selectionState = useSelection(props);\n const { selectedOptions } = selectionState;\n\n // calculate value based on props, internal value changes, and selected options\n const isFirstMount = useFirstMount();\n const [controllableValue, setValue] = useControllableState({\n state: props.value,\n initialState: undefined,\n });\n\n const value = React.useMemo(() => {\n // don't compute the value if it is defined through props or setValue,\n if (controllableValue !== undefined) {\n return controllableValue;\n }\n\n // handle defaultValue here, so it is overridden by selection\n if (isFirstMount && props.defaultValue !== undefined) {\n return props.defaultValue;\n }\n\n if (multiselect) {\n // editable inputs should not display multiple selected options in the input as text\n return editable ? '' : selectedOptions.join(', ');\n }\n\n return selectedOptions[0];\n }, [controllableValue, editable, isFirstMount, multiselect, props.defaultValue, selectedOptions]);\n\n // Handle open state, which is shared with options in context\n const [open, setOpenState] = useControllableState({\n state: props.open,\n defaultState: props.defaultOpen,\n initialState: false,\n });\n\n const setOpen = React.useCallback(\n (event: ComboboxBaseOpenEvents, newState: boolean) => {\n onOpenChange?.(event, { open: newState });\n setOpenState(newState);\n },\n [onOpenChange, setOpenState],\n );\n\n // update active option based on change in open state or children\n React.useEffect(() => {\n if (open && !activeOption) {\n // if it is single-select and there is a selected option, start at the selected option\n if (!multiselect && selectedOptions.length > 0) {\n const selectedOption = getOptionsMatchingText(v => v === selectedOptions[0]).pop();\n selectedOption && setActiveOption(selectedOption);\n }\n // default to starting at the first option\n else {\n setActiveOption(getOptionAtIndex(0));\n }\n } else if (!open) {\n // reset the active option when closing\n setActiveOption(undefined);\n }\n // this should only be run in response to changes in the open state or children\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [open, children]);\n\n return {\n ...optionCollection,\n ...selectionState,\n activeOption,\n appearance,\n focusVisible,\n hasFocus,\n ignoreNextBlur,\n inlinePopup,\n open,\n setActiveOption,\n setFocusVisible,\n setHasFocus,\n setOpen,\n setValue,\n size,\n value,\n };\n};\n"]}
@@ -0,0 +1,16 @@
1
+ define(["require", "exports", "tslib", "@fluentui/react-positioning", "@fluentui/react-utilities"], function (require, exports, tslib_1, react_positioning_1, react_utilities_1) {
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.useComboboxPopup = void 0;
5
+ function useComboboxPopup(props, triggerShorthand, listboxShorthand) {
6
+ var positioning = props.positioning;
7
+ // popper options
8
+ var popperOptions = tslib_1.__assign({ position: 'below', align: 'start', offset: { crossAxis: 0, mainAxis: 2 } }, react_positioning_1.resolvePositioningShorthand(positioning));
9
+ var _a = react_positioning_1.usePositioning(popperOptions), targetRef = _a.targetRef, containerRef = _a.containerRef;
10
+ var listboxRef = react_utilities_1.useMergedRefs(listboxShorthand === null || listboxShorthand === void 0 ? void 0 : listboxShorthand.ref, containerRef);
11
+ var listbox = listboxShorthand && tslib_1.__assign(tslib_1.__assign({}, listboxShorthand), { ref: listboxRef });
12
+ return [tslib_1.__assign(tslib_1.__assign({}, triggerShorthand), { ref: react_utilities_1.useMergedRefs(triggerShorthand === null || triggerShorthand === void 0 ? void 0 : triggerShorthand.ref, targetRef) }), listbox];
13
+ }
14
+ exports.useComboboxPopup = useComboboxPopup;
15
+ });
16
+ //# sourceMappingURL=useComboboxPopup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useComboboxPopup.js","sourceRoot":"","sources":["../../../../../../../../packages/react-components/react-combobox/src/utils/useComboboxPopup.ts"],"names":[],"mappings":";;;;IAgBA,SAAgB,gBAAgB,CAC9B,KAAwB,EACxB,gBAAqF,EACrF,gBAAyD;QAKjD,IAAA,WAAW,GAAK,KAAK,YAAV,CAAW;QAE9B,iBAAiB;QACjB,IAAM,aAAa,sBACjB,QAAQ,EAAE,OAAgB,EAC1B,KAAK,EAAE,OAAgB,EACvB,MAAM,EAAE,EAAE,SAAS,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,IAClC,+CAA2B,CAAC,WAAW,CAAC,CAC5C,CAAC;QAEI,IAAA,KAA8B,kCAAc,CAAC,aAAa,CAAC,EAAzD,SAAS,eAAA,EAAE,YAAY,kBAAkC,CAAC;QAElE,IAAM,UAAU,GAAG,+BAAa,CAAC,gBAAgB,aAAhB,gBAAgB,uBAAhB,gBAAgB,CAAE,GAAG,EAAE,YAAY,CAAC,CAAC;QACtE,IAAM,OAAO,GAAG,gBAAgB,0CAAS,gBAAgB,KAAE,GAAG,EAAE,UAAU,GAAE,CAAC;QAE7E,OAAO,uCAAM,gBAAgB,KAAE,GAAG,EAAE,+BAAa,CAAC,gBAAgB,aAAhB,gBAAgB,uBAAhB,gBAAgB,CAAE,GAAG,EAAE,SAAS,CAAC,KAAI,OAAO,CAAC,CAAC;IAClG,CAAC;IAxBD,4CAwBC","sourcesContent":["import { resolvePositioningShorthand, usePositioning } from '@fluentui/react-positioning';\nimport { ExtractSlotProps, Slot, useMergedRefs } from '@fluentui/react-utilities';\nimport type { ComboboxBaseProps } from './ComboboxBase.types';\nimport { Listbox } from '../components/Listbox/Listbox';\n\nexport function useComboboxPopup(\n props: ComboboxBaseProps,\n triggerShorthand?: ExtractSlotProps<Slot<'button'>>,\n listboxShorthand?: ExtractSlotProps<Slot<typeof Listbox>>,\n): [trigger: ExtractSlotProps<Slot<'button'>>, listbox?: ExtractSlotProps<Slot<typeof Listbox>>];\nexport function useComboboxPopup(\n props: ComboboxBaseProps,\n triggerShorthand?: ExtractSlotProps<Slot<'input'>>,\n listboxShorthand?: ExtractSlotProps<Slot<typeof Listbox>>,\n): [trigger: ExtractSlotProps<Slot<'input'>>, listbox?: ExtractSlotProps<Slot<typeof Listbox>>];\n\nexport function useComboboxPopup(\n props: ComboboxBaseProps,\n triggerShorthand?: ExtractSlotProps<Slot<'input'>> | ExtractSlotProps<Slot<'button'>>,\n listboxShorthand?: ExtractSlotProps<Slot<typeof Listbox>>,\n): [\n trigger: ExtractSlotProps<Slot<'input'>> | ExtractSlotProps<Slot<'button'>>,\n listbox?: ExtractSlotProps<Slot<typeof Listbox>>,\n] {\n const { positioning } = props;\n\n // popper options\n const popperOptions = {\n position: 'below' as const,\n align: 'start' as const,\n offset: { crossAxis: 0, mainAxis: 2 },\n ...resolvePositioningShorthand(positioning),\n };\n\n const { targetRef, containerRef } = usePositioning(popperOptions);\n\n const listboxRef = useMergedRefs(listboxShorthand?.ref, containerRef);\n const listbox = listboxShorthand && { ...listboxShorthand, ref: listboxRef };\n\n return [{ ...triggerShorthand, ref: useMergedRefs(triggerShorthand?.ref, targetRef) }, listbox];\n}\n"]}
@@ -0,0 +1,65 @@
1
+ define(["require", "exports", "tslib", "react"], function (require, exports, tslib_1, React) {
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.useOptionCollection = void 0;
5
+ /**
6
+ * A hook for managing a collection of child Options
7
+ */
8
+ var useOptionCollection = function () {
9
+ var nodes = React.useRef([]);
10
+ var collectionAPI = React.useMemo(function () {
11
+ var getCount = function () { return nodes.current.length; };
12
+ var getOptionAtIndex = function (index) { var _a; return (_a = nodes.current[index]) === null || _a === void 0 ? void 0 : _a.option; };
13
+ var getIndexOfId = function (id) { return nodes.current.findIndex(function (node) { return node.option.id === id; }); };
14
+ var getOptionById = function (id) {
15
+ var item = nodes.current.find(function (node) { return node.option.id === id; });
16
+ return item === null || item === void 0 ? void 0 : item.option;
17
+ };
18
+ var getOptionsMatchingText = function (matcher) {
19
+ return nodes.current.filter(function (node) { return matcher(node.option.text); }).map(function (node) { return node.option; });
20
+ };
21
+ return {
22
+ getCount: getCount,
23
+ getOptionAtIndex: getOptionAtIndex,
24
+ getIndexOfId: getIndexOfId,
25
+ getOptionById: getOptionById,
26
+ getOptionsMatchingText: getOptionsMatchingText,
27
+ };
28
+ }, []);
29
+ var registerOption = React.useCallback(function (option, element) {
30
+ var _a;
31
+ var index = nodes.current.findIndex(function (node) {
32
+ if (!node.element || !element) {
33
+ return false;
34
+ }
35
+ if (node.option.id === option.id) {
36
+ return true;
37
+ }
38
+ // use the DOM method compareDocumentPosition to order the current node against registered nodes
39
+ // eslint-disable-next-line no-bitwise
40
+ return node.element.compareDocumentPosition(element) & Node.DOCUMENT_POSITION_PRECEDING;
41
+ });
42
+ // do not register the option if it already exists
43
+ if (((_a = nodes.current[index]) === null || _a === void 0 ? void 0 : _a.option.id) !== option.id) {
44
+ var newItem = {
45
+ element: element,
46
+ option: option,
47
+ };
48
+ // If an index is not found we will push the element to the end.
49
+ if (index === -1) {
50
+ nodes.current = tslib_1.__spreadArray(tslib_1.__spreadArray([], nodes.current), [newItem]);
51
+ }
52
+ else {
53
+ nodes.current.splice(index, 0, newItem);
54
+ }
55
+ }
56
+ // return the unregister function
57
+ return function () {
58
+ nodes.current = nodes.current.filter(function (node) { return node.option.id !== option.id; });
59
+ };
60
+ }, []);
61
+ return tslib_1.__assign(tslib_1.__assign({}, collectionAPI), { options: nodes.current.map(function (node) { return node.option; }), registerOption: registerOption });
62
+ };
63
+ exports.useOptionCollection = useOptionCollection;
64
+ });
65
+ //# sourceMappingURL=useOptionCollection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useOptionCollection.js","sourceRoot":"","sources":["../../../../../../../../packages/react-components/react-combobox/src/utils/useOptionCollection.ts"],"names":[],"mappings":";;;;IAGA;;OAEG;IACI,IAAM,mBAAmB,GAAG;QACjC,IAAM,KAAK,GAAG,KAAK,CAAC,MAAM,CAAkD,EAAE,CAAC,CAAC;QAEhF,IAAM,aAAa,GAAG,KAAK,CAAC,OAAO,CAAC;YAClC,IAAM,QAAQ,GAAG,cAAM,OAAA,KAAK,CAAC,OAAO,CAAC,MAAM,EAApB,CAAoB,CAAC;YAC5C,IAAM,gBAAgB,GAAG,UAAC,KAAa,YAAK,OAAA,MAAA,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,0CAAE,MAAM,CAAA,EAAA,CAAC;YACzE,IAAM,YAAY,GAAG,UAAC,EAAU,IAAK,OAAA,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,UAAA,IAAI,IAAI,OAAA,IAAI,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,EAArB,CAAqB,CAAC,EAAtD,CAAsD,CAAC;YAC5F,IAAM,aAAa,GAAG,UAAC,EAAU;gBAC/B,IAAM,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,UAAA,IAAI,IAAI,OAAA,IAAI,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,EAArB,CAAqB,CAAC,CAAC;gBAC/D,OAAO,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,MAAM,CAAC;YACtB,CAAC,CAAC;YACF,IAAM,sBAAsB,GAAG,UAAC,OAAmC;gBACjE,OAAO,KAAK,CAAC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oBACL,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC;iBACzC;aACF;YAED,iCAAiC;YACjC,OAAO;gBACL,KAAK,CAAC,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,UAAA,IAAI,IAAI,OAAA,IAAI,CAAC,MAAM,CAAC,EAAE,KAAK,MAAM,CAAC,EAAE,EAA5B,CAA4B,CAAC,CAAC;YAC7E,CAAC,CAAC;QACJ,CAAC,EAAE,EAAE,CAAC,CAAC;QAEP,6CACK,aAAa,KAChB,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,UAAA,IAAI,IAAI,OAAA,IAAI,CAAC,MAAM,EAAX,CAAW,CAAC,EAC/C,cAAc,gBAAA,IACd;IACJ,CAAC,CAAC;IAjEW,QAAA,mBAAmB,uBAiE9B","sourcesContent":["import * as React from 'react';\nimport type { OptionCollectionState, OptionValue } from './OptionCollection.types';\n\n/**\n * A hook for managing a collection of child Options\n */\nexport const useOptionCollection = (): OptionCollectionState => {\n const nodes = React.useRef<{ option: OptionValue; element: HTMLElement }[]>([]);\n\n const collectionAPI = React.useMemo(() => {\n const getCount = () => nodes.current.length;\n const getOptionAtIndex = (index: number) => nodes.current[index]?.option;\n const getIndexOfId = (id: string) => nodes.current.findIndex(node => node.option.id === id);\n const getOptionById = (id: string) => {\n const item = nodes.current.find(node => node.option.id === id);\n return item?.option;\n };\n const getOptionsMatchingText = (matcher: (value: string) => boolean) => {\n return nodes.current.filter(node => matcher(node.option.text)).map(node => node.option);\n };\n\n return {\n getCount,\n getOptionAtIndex,\n getIndexOfId,\n getOptionById,\n getOptionsMatchingText,\n };\n }, []);\n\n const registerOption = React.useCallback((option: OptionValue, element: HTMLElement) => {\n const index = nodes.current.findIndex(node => {\n if (!node.element || !element) {\n return false;\n }\n\n if (node.option.id === option.id) {\n return true;\n }\n\n // use the DOM method compareDocumentPosition to order the current node against registered nodes\n // eslint-disable-next-line no-bitwise\n return node.element.compareDocumentPosition(element) & Node.DOCUMENT_POSITION_PRECEDING;\n });\n\n // do not register the option if it already exists\n if (nodes.current[index]?.option.id !== option.id) {\n const newItem = {\n element,\n option,\n };\n\n // If an index is not found we will push the element to the end.\n if (index === -1) {\n nodes.current = [...nodes.current, newItem];\n } else {\n nodes.current.splice(index, 0, newItem);\n }\n }\n\n // return the unregister function\n return () => {\n nodes.current = nodes.current.filter(node => node.option.id !== option.id);\n };\n }, []);\n\n return {\n ...collectionAPI,\n options: nodes.current.map(node => node.option),\n registerOption,\n };\n};\n"]}
@@ -0,0 +1,33 @@
1
+ define(["require", "exports", "react", "@fluentui/react-utilities"], function (require, exports, React, react_utilities_1) {
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.useScrollOptionsIntoView = void 0;
5
+ function useScrollOptionsIntoView(state) {
6
+ var activeOption = state.activeOption;
7
+ var scrollContainerRef = React.useRef(null);
8
+ React.useEffect(function () {
9
+ if (scrollContainerRef.current && activeOption && react_utilities_1.canUseDOM()) {
10
+ var activeOptionElement = scrollContainerRef.current.querySelector("#" + activeOption.id);
11
+ if (!activeOptionElement) {
12
+ return;
13
+ }
14
+ var offsetHeight = activeOptionElement.offsetHeight, offsetTop = activeOptionElement.offsetTop;
15
+ var _a = scrollContainerRef.current, parentOffsetHeight = _a.offsetHeight, scrollTop = _a.scrollTop;
16
+ var isAbove = offsetTop < scrollTop;
17
+ var isBelow = offsetTop + offsetHeight > scrollTop + parentOffsetHeight;
18
+ // add a small buffer for general visual nicety
19
+ // it looks slightly better if the option has some space from the top/bottom while arrowing
20
+ var buffer = 2;
21
+ if (isAbove) {
22
+ scrollContainerRef.current.scrollTo(0, offsetTop - buffer);
23
+ }
24
+ else if (isBelow) {
25
+ scrollContainerRef.current.scrollTo(0, offsetTop - parentOffsetHeight + offsetHeight + buffer);
26
+ }
27
+ }
28
+ }, [activeOption]);
29
+ return scrollContainerRef;
30
+ }
31
+ exports.useScrollOptionsIntoView = useScrollOptionsIntoView;
32
+ });
33
+ //# sourceMappingURL=useScrollOptionsIntoView.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useScrollOptionsIntoView.js","sourceRoot":"","sources":["../../../../../../../../packages/react-components/react-combobox/src/utils/useScrollOptionsIntoView.ts"],"names":[],"mappings":";;;;IAIA,SAAgB,wBAAwB,CAAC,KAAmB;QAClD,IAAA,YAAY,GAAK,KAAK,aAAV,CAAW;QAC/B,IAAM,kBAAkB,GAAG,KAAK,CAAC,MAAM,CAAiB,IAAI,CAAC,CAAC;QAE9D,KAAK,CAAC,SAAS,CAAC;YACd,IAAI,kBAAkB,CAAC,OAAO,IAAI,YAAY,IAAI,2BAAS,EAAE,EAAE;gBAC7D,IAAM,mBAAmB,GAAG,kBAAkB,CAAC,OAAO,CAAC,aAAa,CAAC,MAAI,YAAY,CAAC,EAAI,CAAgB,CAAC;gBAE3G,IAAI,CAAC,mBAAmB,EAAE;oBACxB,OAAO;iBACR;gBAEO,IAAA,YAAY,GAAgB,mBAAmB,aAAnC,EAAE,SAAS,GAAK,mBAAmB,UAAxB,CAAyB;gBAClD,IAAA,KAAkD,kBAAkB,CAAC,OAAO,EAA5D,kBAAkB,kBAAA,EAAE,SAAS,eAA+B,CAAC;gBAEnF,IAAM,OAAO,GAAG,SAAS,GAAG,SAAS,CAAC;gBACtC,IAAM,OAAO,GAAG,SAAS,GAAG,YAAY,GAAG,SAAS,GAAG,kBAAkB,CAAC;gBAE1E,+CAA+C;gBAC/C,2FAA2F;gBAC3F,IAAM,MAAM,GAAG,CAAC,CAAC;gBAEjB,IAAI,OAAO,EAAE;oBACX,kBAAkB,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,EAAE,SAAS,GAAG,MAAM,CAAC,CAAC;iBAC5D;qBAAM,IAAI,OAAO,EAAE;oBAClB,kBAAkB,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,EAAE,SAAS,GAAG,kBAAkB,GAAG,YAAY,GAAG,MAAM,CAAC,CAAC;iBAChG;aACF;QACH,CAAC,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC;QAEnB,OAAO,kBAAkB,CAAC;IAC5B,CAAC;IA/BD,4DA+BC","sourcesContent":["import * as React from 'react';\nimport { canUseDOM } from '@fluentui/react-utilities';\nimport { ListboxState } from '../Listbox';\n\nexport function useScrollOptionsIntoView(state: ListboxState): React.Ref<HTMLDivElement> {\n const { activeOption } = state;\n const scrollContainerRef = React.useRef<HTMLDivElement>(null);\n\n React.useEffect(() => {\n if (scrollContainerRef.current && activeOption && canUseDOM()) {\n const activeOptionElement = scrollContainerRef.current.querySelector(`#${activeOption.id}`) as HTMLElement;\n\n if (!activeOptionElement) {\n return;\n }\n\n const { offsetHeight, offsetTop } = activeOptionElement;\n const { offsetHeight: parentOffsetHeight, scrollTop } = scrollContainerRef.current;\n\n const isAbove = offsetTop < scrollTop;\n const isBelow = offsetTop + offsetHeight > scrollTop + parentOffsetHeight;\n\n // add a small buffer for general visual nicety\n // it looks slightly better if the option has some space from the top/bottom while arrowing\n const buffer = 2;\n\n if (isAbove) {\n scrollContainerRef.current.scrollTo(0, offsetTop - buffer);\n } else if (isBelow) {\n scrollContainerRef.current.scrollTo(0, offsetTop - parentOffsetHeight + offsetHeight + buffer);\n }\n }\n }, [activeOption]);\n\n return scrollContainerRef;\n}\n"]}
@@ -0,0 +1,42 @@
1
+ define(["require", "exports", "tslib", "react", "@fluentui/react-utilities"], function (require, exports, tslib_1, react_1, react_utilities_1) {
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.useSelection = void 0;
5
+ var useSelection = function (props) {
6
+ var defaultSelectedOptions = props.defaultSelectedOptions, multiselect = props.multiselect, onOptionSelect = props.onOptionSelect;
7
+ var _a = react_utilities_1.useControllableState({
8
+ state: props.selectedOptions,
9
+ defaultState: defaultSelectedOptions,
10
+ initialState: [],
11
+ }), selectedOptions = _a[0], setSelectedOptions = _a[1];
12
+ var selectOption = react_1.useCallback(function (event, option) {
13
+ // if the option is disabled, do nothing
14
+ if (option.disabled) {
15
+ return;
16
+ }
17
+ // for single-select, always return the selected option
18
+ var newSelection = [option.value];
19
+ // toggle selected state of the option for multiselect
20
+ if (multiselect) {
21
+ var selectedIndex = selectedOptions.findIndex(function (o) { return o === option.value; });
22
+ if (selectedIndex > -1) {
23
+ // deselect option
24
+ newSelection = tslib_1.__spreadArray(tslib_1.__spreadArray([], selectedOptions.slice(0, selectedIndex)), selectedOptions.slice(selectedIndex + 1));
25
+ }
26
+ else {
27
+ // select option
28
+ newSelection = tslib_1.__spreadArray(tslib_1.__spreadArray([], selectedOptions), [option.value]);
29
+ }
30
+ }
31
+ setSelectedOptions(newSelection);
32
+ onOptionSelect === null || onOptionSelect === void 0 ? void 0 : onOptionSelect(event, { optionValue: option.value, optionText: option.text, selectedOptions: newSelection });
33
+ }, [onOptionSelect, multiselect, selectedOptions, setSelectedOptions]);
34
+ var clearSelection = function (event) {
35
+ setSelectedOptions([]);
36
+ onOptionSelect === null || onOptionSelect === void 0 ? void 0 : onOptionSelect(event, { optionValue: undefined, optionText: undefined, selectedOptions: [] });
37
+ };
38
+ return { clearSelection: clearSelection, selectOption: selectOption, selectedOptions: selectedOptions };
39
+ };
40
+ exports.useSelection = useSelection;
41
+ });
42
+ //# sourceMappingURL=useSelection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useSelection.js","sourceRoot":"","sources":["../../../../../../../../packages/react-components/react-combobox/src/utils/useSelection.ts"],"names":[],"mappings":";;;;IAKO,IAAM,YAAY,GAAG,UAAC,KAAqB;QACxC,IAAA,sBAAsB,GAAkC,KAAK,uBAAvC,EAAE,WAAW,GAAqB,KAAK,YAA1B,EAAE,cAAc,GAAK,KAAK,eAAV,CAAW;QAEhE,IAAA,KAAwC,sCAAoB,CAAC;YACjE,KAAK,EAAE,KAAK,CAAC,eAAe;YAC5B,YAAY,EAAE,sBAAsB;YACpC,YAAY,EAAE,EAAE;SACjB,CA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,CAAC;QAClG,CAAC,CAAC;QAEF,OAAO,EAAE,cAAc,gBAAA,EAAE,YAAY,cAAA,EAAE,eAAe,iBAAA,EAAE,CAAC;IAC3D,CAAC,CAAC;IA3CW,QAAA,YAAY,gBA2CvB","sourcesContent":["import { useCallback } from 'react';\nimport { useControllableState } from '@fluentui/react-utilities';\nimport { OptionValue } from './OptionCollection.types';\nimport { SelectionEvents, SelectionProps, SelectionState } from './Selection.types';\n\nexport const useSelection = (props: SelectionProps): SelectionState => {\n const { defaultSelectedOptions, multiselect, onOptionSelect } = props;\n\n const [selectedOptions, setSelectedOptions] = useControllableState({\n state: props.selectedOptions,\n defaultState: defaultSelectedOptions,\n initialState: [],\n });\n\n const selectOption = useCallback(\n (event: SelectionEvents, option: OptionValue) => {\n // if the option is disabled, do nothing\n if (option.disabled) {\n return;\n }\n\n // for single-select, always return the selected option\n let newSelection = [option.value];\n\n // toggle selected state of the option for multiselect\n if (multiselect) {\n const selectedIndex = selectedOptions.findIndex(o => o === option.value);\n if (selectedIndex > -1) {\n // deselect option\n newSelection = [...selectedOptions.slice(0, selectedIndex), ...selectedOptions.slice(selectedIndex + 1)];\n } else {\n // select option\n newSelection = [...selectedOptions, option.value];\n }\n }\n\n setSelectedOptions(newSelection);\n onOptionSelect?.(event, { optionValue: option.value, optionText: option.text, selectedOptions: newSelection });\n },\n [onOptionSelect, multiselect, selectedOptions, setSelectedOptions],\n );\n\n const clearSelection = (event: SelectionEvents) => {\n setSelectedOptions([]);\n onOptionSelect?.(event, { optionValue: undefined, optionText: undefined, selectedOptions: [] });\n };\n\n return { clearSelection, selectOption, selectedOptions };\n};\n"]}
@@ -0,0 +1,104 @@
1
+ define(["require", "exports", "tslib", "react", "@fluentui/react-utilities", "../utils/dropdownKeyActions"], function (require, exports, tslib_1, React, react_utilities_1, dropdownKeyActions_1) {
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.useTriggerListboxSlots = void 0;
5
+ /*
6
+ * useTriggerListboxSlots returns a tuple of trigger/listbox shorthand,
7
+ * with the semantics and event handlers needed for the Combobox and Dropdown components.
8
+ * The element type of the ref should always match the element type used in the trigger shorthand.
9
+ */
10
+ function useTriggerListboxSlots(props, state, ref, triggerSlot, listboxSlot) {
11
+ var multiselect = props.multiselect;
12
+ var activeOption = state.activeOption, getCount = state.getCount, getIndexOfId = state.getIndexOfId, getOptionAtIndex = state.getOptionAtIndex, ignoreNextBlur = state.ignoreNextBlur, open = state.open, selectOption = state.selectOption, setActiveOption = state.setActiveOption, setFocusVisible = state.setFocusVisible, setHasFocus = state.setHasFocus, setOpen = state.setOpen;
13
+ // handle trigger focus/blur
14
+ var triggerRef = React.useRef(null);
15
+ // resolve listbox shorthand props
16
+ var listboxId = react_utilities_1.useId('fluent-listbox', listboxSlot === null || listboxSlot === void 0 ? void 0 : listboxSlot.id);
17
+ var listbox = listboxSlot && tslib_1.__assign({ id: listboxId, multiselect: multiselect, tabIndex: undefined }, listboxSlot);
18
+ // resolve trigger shorthand props
19
+ var trigger = tslib_1.__assign(tslib_1.__assign({ 'aria-expanded': open, 'aria-activedescendant': open ? activeOption === null || activeOption === void 0 ? void 0 : activeOption.id : undefined, role: 'combobox' }, triggerSlot), {
20
+ // explicitly type the ref as an intersection here to prevent type errors
21
+ // since the `children` prop has mutually incompatible types between input/button
22
+ // functionally both ref and triggerRef will always be the same element type
23
+ ref: react_utilities_1.useMergedRefs(ref, triggerSlot === null || triggerSlot === void 0 ? void 0 : triggerSlot.ref, triggerRef) });
24
+ /*
25
+ * Handle focus when clicking the listbox popup:
26
+ * 1. Move focus back to the button/input when the listbox is clicked (otherwise it goes to body)
27
+ * 2. Do not close the listbox on button/input blur when clicking into the listbox
28
+ */
29
+ var listboxOnClick = react_utilities_1.useEventCallback(react_utilities_1.mergeCallbacks(function (event) {
30
+ var _a;
31
+ (_a = triggerRef.current) === null || _a === void 0 ? void 0 : _a.focus();
32
+ }, listbox === null || listbox === void 0 ? void 0 : listbox.onClick));
33
+ var listboxOnMouseOver = react_utilities_1.useEventCallback(react_utilities_1.mergeCallbacks(function (event) {
34
+ setFocusVisible(false);
35
+ }, listbox === null || listbox === void 0 ? void 0 : listbox.onMouseOver));
36
+ var listboxOnMouseDown = react_utilities_1.useEventCallback(react_utilities_1.mergeCallbacks(function (event) {
37
+ ignoreNextBlur.current = true;
38
+ }, listbox === null || listbox === void 0 ? void 0 : listbox.onMouseDown));
39
+ // listbox is nullable, only add event handlers if it exists
40
+ if (listbox) {
41
+ listbox.onClick = listboxOnClick;
42
+ listbox.onMouseOver = listboxOnMouseOver;
43
+ listbox.onMouseDown = listboxOnMouseDown;
44
+ }
45
+ // the trigger should open/close the popup on click or blur
46
+ trigger.onBlur = react_utilities_1.mergeCallbacks(function (event) {
47
+ if (!ignoreNextBlur.current) {
48
+ setOpen(event, false);
49
+ }
50
+ ignoreNextBlur.current = false;
51
+ setHasFocus(false);
52
+ }, trigger.onBlur);
53
+ trigger.onClick = react_utilities_1.mergeCallbacks(function (event) {
54
+ setOpen(event, !open);
55
+ }, trigger.onClick);
56
+ trigger.onFocus = react_utilities_1.mergeCallbacks(function (event) {
57
+ setHasFocus(true);
58
+ }, trigger.onFocus);
59
+ // handle combobox keyboard interaction
60
+ trigger.onKeyDown = react_utilities_1.mergeCallbacks(function (event) {
61
+ var action = dropdownKeyActions_1.getDropdownActionFromKey(event, { open: open, multiselect: multiselect });
62
+ var maxIndex = getCount() - 1;
63
+ var activeIndex = activeOption ? getIndexOfId(activeOption.id) : -1;
64
+ var newIndex = activeIndex;
65
+ switch (action) {
66
+ case 'Open':
67
+ event.preventDefault();
68
+ setFocusVisible(true);
69
+ setOpen(event, true);
70
+ break;
71
+ case 'Close':
72
+ // stop propagation for escape key to avoid dismissing any parent popups
73
+ event.stopPropagation();
74
+ event.preventDefault();
75
+ setOpen(event, false);
76
+ break;
77
+ case 'CloseSelect':
78
+ !multiselect && !(activeOption === null || activeOption === void 0 ? void 0 : activeOption.disabled) && setOpen(event, false);
79
+ // fallthrough
80
+ case 'Select':
81
+ activeOption && selectOption(event, activeOption);
82
+ event.preventDefault();
83
+ break;
84
+ case 'Tab':
85
+ !multiselect && activeOption && selectOption(event, activeOption);
86
+ break;
87
+ default:
88
+ newIndex = dropdownKeyActions_1.getIndexFromAction(action, activeIndex, maxIndex);
89
+ }
90
+ if (newIndex !== activeIndex) {
91
+ // prevent default page scroll/keyboard action if the index changed
92
+ event.preventDefault();
93
+ setActiveOption(getOptionAtIndex(newIndex));
94
+ setFocusVisible(true);
95
+ }
96
+ }, trigger.onKeyDown);
97
+ trigger.onMouseOver = react_utilities_1.mergeCallbacks(function (event) {
98
+ setFocusVisible(false);
99
+ }, trigger.onMouseOver);
100
+ return [trigger, listbox];
101
+ }
102
+ exports.useTriggerListboxSlots = useTriggerListboxSlots;
103
+ });
104
+ //# sourceMappingURL=useTriggerListboxSlots.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTriggerListboxSlots.js","sourceRoot":"","sources":["../../../../../../../../packages/react-components/react-combobox/src/utils/useTriggerListboxSlots.ts"],"names":[],"mappings":";;;;IAsBA;;;;OAIG;IACH,SAAgB,sBAAsB,CACpC,KAAwB,EACxB,KAAwB,EACxB,GAAoD,EACpD,WAAgF,EAChF,WAAoD;QAK5C,IAAA,WAAW,GAAK,KAAK,YAAV,CAAW;QAE5B,IAAA,YAAY,GAWV,KAAK,aAXK,EACZ,QAAQ,GAUN,KAAK,SAVC,EACR,YAAY,GASV,KAAK,aATK,EACZ,gBAAgB,GAQd,KAAK,iBARS,EAChB,cAAc,GAOZ,KAAK,eAPO,EACd,IAAI,GAMF,KAAK,KANH,EACJ,YAAY,GAKV,KAAK,aALK,EACZ,eAAe,GAIb,KAAK,gBAJQ,EACf,eAAe,GAGb,KAAK,gBAHQ,EACf,WAAW,GAET,KAAK,YAFI,EACX,OAAO,GACL,KAAK,QADA,CACC;QAEV,4BAA4B;QAC5B,IAAM,UAAU,GAAe,KAAK,CAAC,MAAM,CAAC,IAAI,CA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React from 'react';\nimport { mergeCallbacks, useId, useEventCallback, useMergedRefs } from '@fluentui/react-utilities';\nimport type { ExtractSlotProps, Slot } from '@fluentui/react-utilities';\nimport { getDropdownActionFromKey, getIndexFromAction } from '../utils/dropdownKeyActions';\nimport { Listbox } from '../components/Listbox/Listbox';\nimport type { ComboboxBaseProps, ComboboxBaseState } from './ComboboxBase.types';\n\nexport function useTriggerListboxSlots(\n props: ComboboxBaseProps,\n state: ComboboxBaseState,\n ref: React.Ref<HTMLButtonElement>,\n triggerSlot?: ExtractSlotProps<Slot<'button'>>,\n listboxSlot?: ExtractSlotProps<Slot<typeof Listbox>>,\n): [trigger: ExtractSlotProps<Slot<'button'>>, listbox?: ExtractSlotProps<Slot<typeof Listbox>>];\nexport function useTriggerListboxSlots(\n props: ComboboxBaseProps,\n state: ComboboxBaseState,\n ref: React.Ref<HTMLInputElement>,\n triggerSlot?: ExtractSlotProps<Slot<'input'>>,\n listboxSlot?: ExtractSlotProps<Slot<typeof Listbox>>,\n): [trigger: ExtractSlotProps<Slot<'input'>>, listbox?: ExtractSlotProps<Slot<typeof Listbox>>];\n\n/*\n * useTriggerListboxSlots returns a tuple of trigger/listbox shorthand,\n * with the semantics and event handlers needed for the Combobox and Dropdown components.\n * The element type of the ref should always match the element type used in the trigger shorthand.\n */\nexport function useTriggerListboxSlots(\n props: ComboboxBaseProps,\n state: ComboboxBaseState,\n ref: React.Ref<HTMLButtonElement | HTMLInputElement>,\n triggerSlot?: ExtractSlotProps<Slot<'input'>> | ExtractSlotProps<Slot<'button'>>,\n listboxSlot?: ExtractSlotProps<Slot<typeof Listbox>>,\n): [\n trigger: ExtractSlotProps<Slot<'input'>> | ExtractSlotProps<Slot<'button'>>,\n listbox?: ExtractSlotProps<Slot<typeof Listbox>>,\n] {\n const { multiselect } = props;\n const {\n activeOption,\n getCount,\n getIndexOfId,\n getOptionAtIndex,\n ignoreNextBlur,\n open,\n selectOption,\n setActiveOption,\n setFocusVisible,\n setHasFocus,\n setOpen,\n } = state;\n\n // handle trigger focus/blur\n const triggerRef: typeof ref = React.useRef(null);\n\n // resolve listbox shorthand props\n const listboxId = useId('fluent-listbox', listboxSlot?.id);\n const listbox: typeof listboxSlot = listboxSlot && {\n id: listboxId,\n multiselect,\n tabIndex: undefined,\n ...listboxSlot,\n };\n\n // resolve trigger shorthand props\n const trigger: typeof triggerSlot = {\n 'aria-expanded': open,\n 'aria-activedescendant': open ? activeOption?.id : undefined,\n role: 'combobox',\n ...triggerSlot,\n // explicitly type the ref as an intersection here to prevent type errors\n // since the `children` prop has mutually incompatible types between input/button\n // functionally both ref and triggerRef will always be the same element type\n ref: useMergedRefs(ref, triggerSlot?.ref, triggerRef) as React.Ref<HTMLButtonElement & HTMLInputElement>,\n };\n\n /*\n * Handle focus when clicking the listbox popup:\n * 1. Move focus back to the button/input when the listbox is clicked (otherwise it goes to body)\n * 2. Do not close the listbox on button/input blur when clicking into the listbox\n */\n const listboxOnClick = useEventCallback(\n mergeCallbacks((event: React.MouseEvent<HTMLDivElement>) => {\n triggerRef.current?.focus();\n }, listbox?.onClick),\n );\n\n const listboxOnMouseOver = useEventCallback(\n mergeCallbacks((event: React.MouseEvent<HTMLDivElement>) => {\n setFocusVisible(false);\n }, listbox?.onMouseOver),\n );\n\n const listboxOnMouseDown = useEventCallback(\n mergeCallbacks((event: React.MouseEvent<HTMLDivElement>) => {\n ignoreNextBlur.current = true;\n }, listbox?.onMouseDown),\n );\n\n // listbox is nullable, only add event handlers if it exists\n if (listbox) {\n listbox.onClick = listboxOnClick;\n listbox.onMouseOver = listboxOnMouseOver;\n listbox.onMouseDown = listboxOnMouseDown;\n }\n\n // the trigger should open/close the popup on click or blur\n trigger.onBlur = mergeCallbacks((event: React.FocusEvent<HTMLButtonElement> & React.FocusEvent<HTMLInputElement>) => {\n if (!ignoreNextBlur.current) {\n setOpen(event, false);\n }\n\n ignoreNextBlur.current = false;\n\n setHasFocus(false);\n }, trigger.onBlur);\n\n trigger.onClick = mergeCallbacks(\n (event: React.MouseEvent<HTMLButtonElement> & React.MouseEvent<HTMLInputElement>) => {\n setOpen(event, !open);\n },\n trigger.onClick,\n );\n\n trigger.onFocus = mergeCallbacks(\n (event: React.FocusEvent<HTMLButtonElement> & React.FocusEvent<HTMLInputElement>) => {\n setHasFocus(true);\n },\n trigger.onFocus,\n );\n\n // handle combobox keyboard interaction\n trigger.onKeyDown = mergeCallbacks(\n (event: React.KeyboardEvent<HTMLButtonElement> & React.KeyboardEvent<HTMLInputElement>) => {\n const action = getDropdownActionFromKey(event, { open, multiselect });\n const maxIndex = getCount() - 1;\n const activeIndex = activeOption ? getIndexOfId(activeOption.id) : -1;\n let newIndex = activeIndex;\n\n switch (action) {\n case 'Open':\n event.preventDefault();\n setFocusVisible(true);\n setOpen(event, true);\n break;\n case 'Close':\n // stop propagation for escape key to avoid dismissing any parent popups\n event.stopPropagation();\n event.preventDefault();\n setOpen(event, false);\n break;\n case 'CloseSelect':\n !multiselect && !activeOption?.disabled && setOpen(event, false);\n // fallthrough\n case 'Select':\n activeOption && selectOption(event, activeOption);\n event.preventDefault();\n break;\n case 'Tab':\n !multiselect && activeOption && selectOption(event, activeOption);\n break;\n default:\n newIndex = getIndexFromAction(action, activeIndex, maxIndex);\n }\n if (newIndex !== activeIndex) {\n // prevent default page scroll/keyboard action if the index changed\n event.preventDefault();\n setActiveOption(getOptionAtIndex(newIndex));\n setFocusVisible(true);\n }\n },\n trigger.onKeyDown,\n );\n\n trigger.onMouseOver = mergeCallbacks(\n (event: React.MouseEvent<HTMLButtonElement> & React.MouseEvent<HTMLInputElement>) => {\n setFocusVisible(false);\n },\n trigger.onMouseOver,\n );\n\n return [trigger, listbox];\n}\n"]}
@@ -3,8 +3,6 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
-
7
6
  const tslib_1 = /*#__PURE__*/require("tslib");
8
-
9
7
  tslib_1.__exportStar(require("./components/Combobox/index"), exports);
10
8
  //# sourceMappingURL=Combobox.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["Combobox.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,6BAAA,CAAA,EAAA,OAAA","sourcesContent":["export * from './components/Combobox/index';\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"mappings":";;;;;;AAAAA","names":["tslib_1"],"sourceRoot":"../src/","sources":["packages/react-components/react-combobox/src/Combobox.ts"],"sourcesContent":["export * from './components/Combobox/index';\n"]}
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ const tslib_1 = /*#__PURE__*/require("tslib");
7
+ tslib_1.__exportStar(require("./components/ComboboxField/index"), exports);
8
+ //# sourceMappingURL=ComboboxField.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"mappings":";;;;;;AAAAA","names":["tslib_1"],"sourceRoot":"../src/","sources":["packages/react-components/react-combobox/src/ComboboxField.ts"],"sourcesContent":["export * from './components/ComboboxField/index';\n"]}
@@ -3,8 +3,6 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
-
7
6
  const tslib_1 = /*#__PURE__*/require("tslib");
8
-
9
7
  tslib_1.__exportStar(require("./components/Dropdown/index"), exports);
10
8
  //# sourceMappingURL=Dropdown.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["Dropdown.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,6BAAA,CAAA,EAAA,OAAA","sourcesContent":["export * from './components/Dropdown/index';\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"mappings":";;;;;;AAAAA","names":["tslib_1"],"sourceRoot":"../src/","sources":["packages/react-components/react-combobox/src/Dropdown.ts"],"sourcesContent":["export * from './components/Dropdown/index';\n"]}
@@ -3,8 +3,6 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
-
7
6
  const tslib_1 = /*#__PURE__*/require("tslib");
8
-
9
7
  tslib_1.__exportStar(require("./components/Listbox/index"), exports);
10
8
  //# sourceMappingURL=Listbox.js.map