@fluentui/react-combobox 9.0.0-beta.8 → 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 (304) hide show
  1. package/CHANGELOG.json +964 -4
  2. package/CHANGELOG.md +274 -5
  3. package/README.md +1 -3
  4. package/dist/index.d.ts +84 -24
  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 +11 -8
  17. package/lib/components/Combobox/renderCombobox.js.map +1 -1
  18. package/lib/components/Combobox/useCombobox.js +191 -16
  19. package/lib/components/Combobox/useCombobox.js.map +1 -1
  20. package/lib/components/Combobox/useComboboxStyles.js +253 -161
  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 +11 -8
  31. package/lib/components/Dropdown/renderDropdown.js.map +1 -1
  32. package/lib/components/Dropdown/useDropdown.js +90 -9
  33. package/lib/components/Dropdown/useDropdown.js.map +1 -1
  34. package/lib/components/Dropdown/useDropdownStyles.js +237 -155
  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 +35 -29
  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 +61 -46
  53. package/lib/components/Option/useOption.js.map +1 -1
  54. package/lib/components/Option/useOptionStyles.js +103 -80
  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 +14 -9
  67. package/lib/contexts/ComboboxContext.js.map +1 -1
  68. package/lib/contexts/ListboxContext.js +11 -8
  69. package/lib/contexts/ListboxContext.js.map +1 -1
  70. package/lib/contexts/useComboboxContextValues.js +8 -2
  71. package/lib/contexts/useComboboxContextValues.js.map +1 -1
  72. package/lib/contexts/useListboxContextValues.js +10 -6
  73. package/lib/contexts/useListboxContextValues.js.map +1 -1
  74. package/lib/index.js +6 -0
  75. package/lib/index.js.map +1 -1
  76. package/lib/utils/ComboboxBase.types.js.map +1 -1
  77. package/lib/utils/OptionCollection.types.js.map +1 -1
  78. package/lib/utils/Selection.types.js.map +1 -1
  79. package/lib/utils/dropdownKeyActions.js +14 -42
  80. package/lib/utils/dropdownKeyActions.js.map +1 -1
  81. package/lib/utils/internalTokens.js.map +1 -1
  82. package/lib/utils/useComboboxBaseState.js +48 -44
  83. package/lib/utils/useComboboxBaseState.js.map +1 -1
  84. package/lib/utils/useComboboxPopup.js +10 -6
  85. package/lib/utils/useComboboxPopup.js.map +1 -1
  86. package/lib/utils/useOptionCollection.js +13 -23
  87. package/lib/utils/useOptionCollection.js.map +1 -1
  88. package/lib/utils/useScrollOptionsIntoView.js +36 -0
  89. package/lib/utils/useScrollOptionsIntoView.js.map +1 -0
  90. package/lib/utils/useSelection.js +20 -14
  91. package/lib/utils/useSelection.js.map +1 -1
  92. package/lib/utils/useTriggerListboxSlots.js +46 -57
  93. package/lib/utils/useTriggerListboxSlots.js.map +1 -1
  94. package/lib-amd/Combobox.js +6 -0
  95. package/lib-amd/Combobox.js.map +1 -0
  96. package/lib-amd/ComboboxField.js +6 -0
  97. package/lib-amd/ComboboxField.js.map +1 -0
  98. package/lib-amd/Dropdown.js +6 -0
  99. package/lib-amd/Dropdown.js.map +1 -0
  100. package/lib-amd/Listbox.js +6 -0
  101. package/lib-amd/Listbox.js.map +1 -0
  102. package/lib-amd/Option.js +6 -0
  103. package/lib-amd/Option.js.map +1 -0
  104. package/lib-amd/OptionGroup.js +6 -0
  105. package/lib-amd/OptionGroup.js.map +1 -0
  106. package/lib-amd/components/Combobox/Combobox.js +16 -0
  107. package/lib-amd/components/Combobox/Combobox.js.map +1 -0
  108. package/lib-amd/components/Combobox/Combobox.types.js +5 -0
  109. package/lib-amd/components/Combobox/Combobox.types.js.map +1 -0
  110. package/lib-amd/components/Combobox/index.js +10 -0
  111. package/lib-amd/components/Combobox/index.js.map +1 -0
  112. package/lib-amd/components/Combobox/renderCombobox.js +20 -0
  113. package/lib-amd/components/Combobox/renderCombobox.js.map +1 -0
  114. package/lib-amd/components/Combobox/useCombobox.js +206 -0
  115. package/lib-amd/components/Combobox/useCombobox.js.map +1 -0
  116. package/lib-amd/components/Combobox/useComboboxStyles.js +152 -0
  117. package/lib-amd/components/Combobox/useComboboxStyles.js.map +1 -0
  118. package/lib-amd/components/ComboboxField/ComboboxField.js +10 -0
  119. package/lib-amd/components/ComboboxField/ComboboxField.js.map +1 -0
  120. package/lib-amd/components/ComboboxField/index.js +6 -0
  121. package/lib-amd/components/ComboboxField/index.js.map +1 -0
  122. package/lib-amd/components/Dropdown/Dropdown.js +16 -0
  123. package/lib-amd/components/Dropdown/Dropdown.js.map +1 -0
  124. package/lib-amd/components/Dropdown/Dropdown.types.js +5 -0
  125. package/lib-amd/components/Dropdown/Dropdown.types.js.map +1 -0
  126. package/lib-amd/components/Dropdown/index.js +10 -0
  127. package/lib-amd/components/Dropdown/index.js.map +1 -0
  128. package/lib-amd/components/Dropdown/renderDropdown.js +21 -0
  129. package/lib-amd/components/Dropdown/renderDropdown.js.map +1 -0
  130. package/lib-amd/components/Dropdown/useDropdown.js +121 -0
  131. package/lib-amd/components/Dropdown/useDropdown.js.map +1 -0
  132. package/lib-amd/components/Dropdown/useDropdownStyles.js +127 -0
  133. package/lib-amd/components/Dropdown/useDropdownStyles.js.map +1 -0
  134. package/lib-amd/components/Listbox/Listbox.js +16 -0
  135. package/lib-amd/components/Listbox/Listbox.js.map +1 -0
  136. package/lib-amd/components/Listbox/Listbox.types.js +5 -0
  137. package/lib-amd/components/Listbox/Listbox.types.js.map +1 -0
  138. package/lib-amd/components/Listbox/index.js +10 -0
  139. package/lib-amd/components/Listbox/index.js.map +1 -0
  140. package/lib-amd/components/Listbox/renderListbox.js +15 -0
  141. package/lib-amd/components/Listbox/renderListbox.js.map +1 -0
  142. package/lib-amd/components/Listbox/useListbox.js +80 -0
  143. package/lib-amd/components/Listbox/useListbox.js.map +1 -0
  144. package/lib-amd/components/Listbox/useListboxStyles.js +24 -0
  145. package/lib-amd/components/Listbox/useListboxStyles.js.map +1 -0
  146. package/lib-amd/components/Option/Option.js +15 -0
  147. package/lib-amd/components/Option/Option.js.map +1 -0
  148. package/lib-amd/components/Option/Option.types.js +5 -0
  149. package/lib-amd/components/Option/Option.types.js.map +1 -0
  150. package/lib-amd/components/Option/index.js +10 -0
  151. package/lib-amd/components/Option/index.js.map +1 -0
  152. package/lib-amd/components/Option/renderOption.js +16 -0
  153. package/lib-amd/components/Option/renderOption.js.map +1 -0
  154. package/lib-amd/components/Option/useOption.js +117 -0
  155. package/lib-amd/components/Option/useOption.js.map +1 -0
  156. package/lib-amd/components/Option/useOptionStyles.js +73 -0
  157. package/lib-amd/components/Option/useOptionStyles.js.map +1 -0
  158. package/lib-amd/components/OptionGroup/OptionGroup.js +15 -0
  159. package/lib-amd/components/OptionGroup/OptionGroup.js.map +1 -0
  160. package/lib-amd/components/OptionGroup/OptionGroup.types.js +5 -0
  161. package/lib-amd/components/OptionGroup/OptionGroup.types.js.map +1 -0
  162. package/lib-amd/components/OptionGroup/index.js +10 -0
  163. package/lib-amd/components/OptionGroup/index.js.map +1 -0
  164. package/lib-amd/components/OptionGroup/renderOptionGroup.js +16 -0
  165. package/lib-amd/components/OptionGroup/renderOptionGroup.js.map +1 -0
  166. package/lib-amd/components/OptionGroup/useOptionGroup.js +33 -0
  167. package/lib-amd/components/OptionGroup/useOptionGroup.js.map +1 -0
  168. package/lib-amd/components/OptionGroup/useOptionGroupStyles.js +34 -0
  169. package/lib-amd/components/OptionGroup/useOptionGroupStyles.js.map +1 -0
  170. package/lib-amd/contexts/ComboboxContext.js +28 -0
  171. package/lib-amd/contexts/ComboboxContext.js.map +1 -0
  172. package/lib-amd/contexts/ListboxContext.js +23 -0
  173. package/lib-amd/contexts/ListboxContext.js.map +1 -0
  174. package/lib-amd/contexts/useComboboxContextValues.js +23 -0
  175. package/lib-amd/contexts/useComboboxContextValues.js.map +1 -0
  176. package/lib-amd/contexts/useListboxContextValues.js +24 -0
  177. package/lib-amd/contexts/useListboxContextValues.js.map +1 -0
  178. package/lib-amd/index.js +37 -0
  179. package/lib-amd/index.js.map +1 -0
  180. package/lib-amd/utils/ComboboxBase.types.js +5 -0
  181. package/lib-amd/utils/ComboboxBase.types.js.map +1 -0
  182. package/lib-amd/utils/OptionCollection.types.js +5 -0
  183. package/lib-amd/utils/OptionCollection.types.js.map +1 -0
  184. package/lib-amd/utils/Selection.types.js +5 -0
  185. package/lib-amd/utils/Selection.types.js.map +1 -0
  186. package/lib-amd/utils/dropdownKeyActions.js +85 -0
  187. package/lib-amd/utils/dropdownKeyActions.js.map +1 -0
  188. package/lib-amd/utils/internalTokens.js +11 -0
  189. package/lib-amd/utils/internalTokens.js.map +1 -0
  190. package/lib-amd/utils/useComboboxBaseState.js +76 -0
  191. package/lib-amd/utils/useComboboxBaseState.js.map +1 -0
  192. package/lib-amd/utils/useComboboxPopup.js +16 -0
  193. package/lib-amd/utils/useComboboxPopup.js.map +1 -0
  194. package/lib-amd/utils/useOptionCollection.js +65 -0
  195. package/lib-amd/utils/useOptionCollection.js.map +1 -0
  196. package/lib-amd/utils/useScrollOptionsIntoView.js +33 -0
  197. package/lib-amd/utils/useScrollOptionsIntoView.js.map +1 -0
  198. package/lib-amd/utils/useSelection.js +42 -0
  199. package/lib-amd/utils/useSelection.js.map +1 -0
  200. package/lib-amd/utils/useTriggerListboxSlots.js +104 -0
  201. package/lib-amd/utils/useTriggerListboxSlots.js.map +1 -0
  202. package/lib-commonjs/Combobox.js +0 -2
  203. package/lib-commonjs/Combobox.js.map +1 -1
  204. package/lib-commonjs/ComboboxField.js +8 -0
  205. package/lib-commonjs/ComboboxField.js.map +1 -0
  206. package/lib-commonjs/Dropdown.js +0 -2
  207. package/lib-commonjs/Dropdown.js.map +1 -1
  208. package/lib-commonjs/Listbox.js +0 -2
  209. package/lib-commonjs/Listbox.js.map +1 -1
  210. package/lib-commonjs/Option.js +0 -2
  211. package/lib-commonjs/Option.js.map +1 -1
  212. package/lib-commonjs/OptionGroup.js +0 -2
  213. package/lib-commonjs/OptionGroup.js.map +1 -1
  214. package/lib-commonjs/components/Combobox/Combobox.js +0 -7
  215. package/lib-commonjs/components/Combobox/Combobox.js.map +1 -1
  216. package/lib-commonjs/components/Combobox/Combobox.types.js.map +1 -1
  217. package/lib-commonjs/components/Combobox/index.js +0 -6
  218. package/lib-commonjs/components/Combobox/index.js.map +1 -1
  219. package/lib-commonjs/components/Combobox/renderCombobox.js +11 -14
  220. package/lib-commonjs/components/Combobox/renderCombobox.js.map +1 -1
  221. package/lib-commonjs/components/Combobox/useCombobox.js +190 -24
  222. package/lib-commonjs/components/Combobox/useCombobox.js.map +1 -1
  223. package/lib-commonjs/components/Combobox/useComboboxStyles.js +252 -165
  224. package/lib-commonjs/components/Combobox/useComboboxStyles.js.map +1 -1
  225. package/lib-commonjs/components/ComboboxField/ComboboxField.js +14 -0
  226. package/lib-commonjs/components/ComboboxField/ComboboxField.js.map +1 -0
  227. package/lib-commonjs/components/ComboboxField/index.js +8 -0
  228. package/lib-commonjs/components/ComboboxField/index.js.map +1 -0
  229. package/lib-commonjs/components/Dropdown/Dropdown.js +0 -7
  230. package/lib-commonjs/components/Dropdown/Dropdown.js.map +1 -1
  231. package/lib-commonjs/components/Dropdown/Dropdown.types.js.map +1 -1
  232. package/lib-commonjs/components/Dropdown/index.js +0 -6
  233. package/lib-commonjs/components/Dropdown/index.js.map +1 -1
  234. package/lib-commonjs/components/Dropdown/renderDropdown.js +11 -14
  235. package/lib-commonjs/components/Dropdown/renderDropdown.js.map +1 -1
  236. package/lib-commonjs/components/Dropdown/useDropdown.js +89 -17
  237. package/lib-commonjs/components/Dropdown/useDropdown.js.map +1 -1
  238. package/lib-commonjs/components/Dropdown/useDropdownStyles.js +236 -159
  239. package/lib-commonjs/components/Dropdown/useDropdownStyles.js.map +1 -1
  240. package/lib-commonjs/components/Listbox/Listbox.js +0 -7
  241. package/lib-commonjs/components/Listbox/Listbox.js.map +1 -1
  242. package/lib-commonjs/components/Listbox/Listbox.types.js.map +1 -1
  243. package/lib-commonjs/components/Listbox/index.js +0 -6
  244. package/lib-commonjs/components/Listbox/index.js.map +1 -1
  245. package/lib-commonjs/components/Listbox/renderListbox.js +2 -7
  246. package/lib-commonjs/components/Listbox/renderListbox.js.map +1 -1
  247. package/lib-commonjs/components/Listbox/useListbox.js +34 -37
  248. package/lib-commonjs/components/Listbox/useListbox.js.map +1 -1
  249. package/lib-commonjs/components/Listbox/useListboxStyles.js +16 -24
  250. package/lib-commonjs/components/Listbox/useListboxStyles.js.map +1 -1
  251. package/lib-commonjs/components/Option/Option.js +0 -6
  252. package/lib-commonjs/components/Option/Option.js.map +1 -1
  253. package/lib-commonjs/components/Option/Option.types.js.map +1 -1
  254. package/lib-commonjs/components/Option/index.js +0 -6
  255. package/lib-commonjs/components/Option/index.js.map +1 -1
  256. package/lib-commonjs/components/Option/renderOption.js +4 -7
  257. package/lib-commonjs/components/Option/renderOption.js.map +1 -1
  258. package/lib-commonjs/components/Option/useOption.js +60 -52
  259. package/lib-commonjs/components/Option/useOption.js.map +1 -1
  260. package/lib-commonjs/components/Option/useOptionStyles.js +103 -84
  261. package/lib-commonjs/components/Option/useOptionStyles.js.map +1 -1
  262. package/lib-commonjs/components/OptionGroup/OptionGroup.js +0 -6
  263. package/lib-commonjs/components/OptionGroup/OptionGroup.js.map +1 -1
  264. package/lib-commonjs/components/OptionGroup/OptionGroup.types.js.map +1 -1
  265. package/lib-commonjs/components/OptionGroup/index.js +0 -6
  266. package/lib-commonjs/components/OptionGroup/index.js.map +1 -1
  267. package/lib-commonjs/components/OptionGroup/renderOptionGroup.js +4 -7
  268. package/lib-commonjs/components/OptionGroup/renderOptionGroup.js.map +1 -1
  269. package/lib-commonjs/components/OptionGroup/useOptionGroup.js +0 -4
  270. package/lib-commonjs/components/OptionGroup/useOptionGroup.js.map +1 -1
  271. package/lib-commonjs/components/OptionGroup/useOptionGroupStyles.js +29 -38
  272. package/lib-commonjs/components/OptionGroup/useOptionGroupStyles.js.map +1 -1
  273. package/lib-commonjs/contexts/ComboboxContext.js +15 -12
  274. package/lib-commonjs/contexts/ComboboxContext.js.map +1 -1
  275. package/lib-commonjs/contexts/ListboxContext.js +12 -11
  276. package/lib-commonjs/contexts/ListboxContext.js.map +1 -1
  277. package/lib-commonjs/contexts/useComboboxContextValues.js +8 -4
  278. package/lib-commonjs/contexts/useComboboxContextValues.js.map +1 -1
  279. package/lib-commonjs/contexts/useListboxContextValues.js +10 -10
  280. package/lib-commonjs/contexts/useListboxContextValues.js.map +1 -1
  281. package/lib-commonjs/index.js +43 -11
  282. package/lib-commonjs/index.js.map +1 -1
  283. package/lib-commonjs/utils/ComboboxBase.types.js.map +1 -1
  284. package/lib-commonjs/utils/OptionCollection.types.js.map +1 -1
  285. package/lib-commonjs/utils/Selection.types.js.map +1 -1
  286. package/lib-commonjs/utils/dropdownKeyActions.js +14 -46
  287. package/lib-commonjs/utils/dropdownKeyActions.js.map +1 -1
  288. package/lib-commonjs/utils/internalTokens.js.map +1 -1
  289. package/lib-commonjs/utils/useComboboxBaseState.js +48 -50
  290. package/lib-commonjs/utils/useComboboxBaseState.js.map +1 -1
  291. package/lib-commonjs/utils/useComboboxPopup.js +10 -10
  292. package/lib-commonjs/utils/useComboboxPopup.js.map +1 -1
  293. package/lib-commonjs/utils/useOptionCollection.js +13 -26
  294. package/lib-commonjs/utils/useOptionCollection.js.map +1 -1
  295. package/lib-commonjs/utils/useScrollOptionsIntoView.js +43 -0
  296. package/lib-commonjs/utils/useScrollOptionsIntoView.js.map +1 -0
  297. package/lib-commonjs/utils/useSelection.js +20 -17
  298. package/lib-commonjs/utils/useSelection.js.map +1 -1
  299. package/lib-commonjs/utils/useTriggerListboxSlots.js +45 -61
  300. package/lib-commonjs/utils/useTriggerListboxSlots.js.map +1 -1
  301. package/package.json +24 -23
  302. package/Spec-migration.md +0 -13
  303. package/Spec.md +0 -520
  304. package/dist/tsdoc-metadata.json +0 -11
@@ -4,20 +4,24 @@ export function useListboxContextValues(state) {
4
4
  const hasComboboxContext = useHasParentContext(ComboboxContext);
5
5
  const {
6
6
  activeOption,
7
+ focusVisible,
7
8
  multiselect,
8
- onOptionClick,
9
9
  registerOption,
10
- selectedOptions
11
- } = state; // get register/unregister functions from parent combobox context
12
-
10
+ selectedOptions,
11
+ selectOption,
12
+ setActiveOption
13
+ } = state;
14
+ // get register/unregister functions from parent combobox context
13
15
  const comboboxRegisterOption = useContextSelector(ComboboxContext, ctx => ctx.registerOption);
14
16
  const registerOptionValue = hasComboboxContext ? comboboxRegisterOption : registerOption;
15
17
  const listbox = {
16
18
  activeOption,
19
+ focusVisible,
17
20
  multiselect,
18
- onOptionClick,
21
+ registerOption: registerOptionValue,
19
22
  selectedOptions,
20
- registerOption: registerOptionValue
23
+ selectOption,
24
+ setActiveOption
21
25
  };
22
26
  return {
23
27
  listbox
@@ -1 +1 @@
1
- {"version":3,"sources":["contexts/useListboxContextValues.ts"],"names":[],"mappings":"AAAA,SAAS,kBAAT,EAA6B,mBAA7B,QAAwD,kCAAxD;AAEA,SAAS,eAAT,QAAgC,mBAAhC;AAEA,OAAM,SAAU,uBAAV,CAAkC,KAAlC,EAAqD;EACzD,MAAM,kBAAkB,GAAG,mBAAmB,CAAC,eAAD,CAA9C;EACA,MAAM;IAAE,YAAF;IAAgB,WAAhB;IAA6B,aAA7B;IAA4C,cAA5C;IAA4D;EAA5D,IAAgF,KAAtF,CAFyD,CAIzD;;EACA,MAAM,sBAAsB,GAAG,kBAAkB,CAAC,eAAD,EAAkB,GAAG,IAAI,GAAG,CAAC,cAA7B,CAAjD;EAEA,MAAM,mBAAmB,GAAG,kBAAkB,GAAG,sBAAH,GAA4B,cAA1E;EAEA,MAAM,OAAO,GAAG;IACd,YADc;IAEd,WAFc;IAGd,aAHc;IAId,eAJc;IAKd,cAAc,EAAE;EALF,CAAhB;EAQA,OAAO;IAAE;EAAF,CAAP;AACD","sourcesContent":["import { useContextSelector, useHasParentContext } from '@fluentui/react-context-selector';\nimport { ListboxContextValues, ListboxState } from '../components/Listbox/Listbox.types';\nimport { ComboboxContext } from './ComboboxContext';\n\nexport function useListboxContextValues(state: ListboxState): ListboxContextValues {\n const hasComboboxContext = useHasParentContext(ComboboxContext);\n const { activeOption, multiselect, onOptionClick, registerOption, selectedOptions } = state;\n\n // get register/unregister functions from parent combobox context\n const comboboxRegisterOption = useContextSelector(ComboboxContext, ctx => ctx.registerOption);\n\n const registerOptionValue = hasComboboxContext ? comboboxRegisterOption : registerOption;\n\n const listbox = {\n activeOption,\n multiselect,\n onOptionClick,\n selectedOptions,\n registerOption: registerOptionValue,\n };\n\n return { listbox };\n}\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"mappings":"AAAA,SAASA,kBAAkB,EAAEC,mBAAmB,QAAQ,kCAAkC;AAE1F,SAASC,eAAe,QAAQ,mBAAmB;AAEnD,OAAM,SAAUC,uBAAuB,CAACC,KAAmB;EACzD,MAAMC,kBAAkB,GAAGJ,mBAAmB,CAACC,eAAe,CAAC;EAC/D,MAAM;IACJI,YAAY;IACZC,YAAY;IACZC,WAAW;IACXC,cAAc;IACdC,eAAe;IACfC,YAAY;IACZC;EAAe,CAChB,GAAGR,KAAK;EAET;EACA,MAAMS,sBAAsB,GAAGb,kBAAkB,CAACE,eAAe,EAAEY,GAAG,IAAIA,GAAG,CAACL,cAAc,CAAC;EAE7F,MAAMM,mBAAmB,GAAGV,kBAAkB,GAAGQ,sBAAsB,GAAGJ,cAAc;EAExF,MAAMO,OAAO,GAAG;IACdV,YAAY;IACZC,YAAY;IACZC,WAAW;IACXC,cAAc,EAAEM,mBAAmB;IACnCL,eAAe;IACfC,YAAY;IACZC;GACD;EAED,OAAO;IAAEI;EAAO,CAAE;AACpB","names":["useContextSelector","useHasParentContext","ComboboxContext","useListboxContextValues","state","hasComboboxContext","activeOption","focusVisible","multiselect","registerOption","selectedOptions","selectOption","setActiveOption","comboboxRegisterOption","ctx","registerOptionValue","listbox"],"sourceRoot":"../src/","sources":["packages/react-components/react-combobox/src/contexts/useListboxContextValues.ts"],"sourcesContent":["import { useContextSelector, useHasParentContext } from '@fluentui/react-context-selector';\nimport { ListboxContextValues, ListboxState } from '../components/Listbox/Listbox.types';\nimport { ComboboxContext } from './ComboboxContext';\n\nexport function useListboxContextValues(state: ListboxState): ListboxContextValues {\n const hasComboboxContext = useHasParentContext(ComboboxContext);\n const {\n activeOption,\n focusVisible,\n multiselect,\n registerOption,\n selectedOptions,\n selectOption,\n setActiveOption,\n } = state;\n\n // get register/unregister functions from parent combobox context\n const comboboxRegisterOption = useContextSelector(ComboboxContext, ctx => ctx.registerOption);\n\n const registerOptionValue = hasComboboxContext ? comboboxRegisterOption : registerOption;\n\n const listbox = {\n activeOption,\n focusVisible,\n multiselect,\n registerOption: registerOptionValue,\n selectedOptions,\n selectOption,\n setActiveOption,\n };\n\n return { listbox };\n}\n"]}
package/lib/index.js CHANGED
@@ -1,6 +1,12 @@
1
+ export { ComboboxProvider } from './contexts/ComboboxContext';
2
+ export { ListboxProvider } from './contexts/ListboxContext';
3
+ export { useComboboxContextValues } from './contexts/useComboboxContextValues';
4
+ export { useListboxContextValues } from './contexts/useListboxContextValues';
1
5
  export { Listbox, listboxClassNames, renderListbox_unstable, useListboxStyles_unstable, useListbox_unstable } from './Listbox';
2
6
  export { Option, optionClassNames, renderOption_unstable, useOptionStyles_unstable, useOption_unstable } from './Option';
3
7
  export { Combobox, comboboxClassNames, renderCombobox_unstable, useComboboxStyles_unstable, useCombobox_unstable } from './Combobox';
4
8
  export { Dropdown, dropdownClassNames, renderDropdown_unstable, useDropdownStyles_unstable, useDropdown_unstable } from './Dropdown';
5
9
  export { OptionGroup, optionGroupClassNames, renderOptionGroup_unstable, useOptionGroupStyles_unstable, useOptionGroup_unstable } from './OptionGroup';
10
+ // eslint-disable-next-line deprecation/deprecation
11
+ export { ComboboxField as ComboboxField_unstable, comboboxFieldClassNames } from './ComboboxField';
6
12
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["index.ts"],"names":[],"mappings":"AAAA,SACE,OADF,EAEE,iBAFF,EAGE,sBAHF,EAIE,yBAJF,EAKE,mBALF,QAMO,WANP;AAQA,SACE,MADF,EAEE,gBAFF,EAGE,qBAHF,EAIE,wBAJF,EAKE,kBALF,QAMO,UANP;AAQA,SACE,QADF,EAEE,kBAFF,EAGE,uBAHF,EAIE,0BAJF,EAKE,oBALF,QAMO,YANP;AAeA,SACE,QADF,EAEE,kBAFF,EAGE,uBAHF,EAIE,0BAJF,EAKE,oBALF,QAMO,YANP;AAeA,SACE,WADF,EAEE,qBAFF,EAGE,0BAHF,EAIE,6BAJF,EAKE,uBALF,QAMO,eANP","sourcesContent":["export {\n Listbox,\n listboxClassNames,\n renderListbox_unstable,\n useListboxStyles_unstable,\n useListbox_unstable,\n} from './Listbox';\nexport type { ListboxContextValues, ListboxProps, ListboxSlots, ListboxState } from './Listbox';\nexport {\n Option,\n optionClassNames,\n renderOption_unstable,\n useOptionStyles_unstable,\n useOption_unstable,\n} from './Option';\nexport type { OptionProps, OptionSlots, OptionState } from './Option';\nexport {\n Combobox,\n comboboxClassNames,\n renderCombobox_unstable,\n useComboboxStyles_unstable,\n useCombobox_unstable,\n} from './Combobox';\nexport type {\n ComboboxContextValues,\n ComboboxOpenChangeData,\n ComboboxOpenEvents,\n ComboboxProps,\n ComboboxSlots,\n ComboboxState,\n} from './Combobox';\nexport {\n Dropdown,\n dropdownClassNames,\n renderDropdown_unstable,\n useDropdownStyles_unstable,\n useDropdown_unstable,\n} from './Dropdown';\nexport type {\n DropdownContextValues,\n DropdownOpenChangeData,\n DropdownOpenEvents,\n DropdownProps,\n DropdownSlots,\n DropdownState,\n} from './Dropdown';\nexport {\n OptionGroup,\n optionGroupClassNames,\n renderOptionGroup_unstable,\n useOptionGroupStyles_unstable,\n useOptionGroup_unstable,\n} from './OptionGroup';\nexport type { OptionGroupProps, OptionGroupSlots, OptionGroupState } from './OptionGroup';\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"mappings":"AAAA,SAASA,gBAAgB,QAAQ,4BAA4B;AAE7D,SAASC,eAAe,QAAQ,2BAA2B;AAE3D,SAASC,wBAAwB,QAAQ,qCAAqC;AAC9E,SAASC,uBAAuB,QAAQ,oCAAoC;AAC5E,SACEC,OAAO,EACPC,iBAAiB,EACjBC,sBAAsB,EACtBC,yBAAyB,EACzBC,mBAAmB,QACd,WAAW;AAElB,SACEC,MAAM,EACNC,gBAAgB,EAChBC,qBAAqB,EACrBC,wBAAwB,EACxBC,kBAAkB,QACb,UAAU;AAEjB,SACEC,QAAQ,EACRC,kBAAkB,EAClBC,uBAAuB,EACvBC,0BAA0B,EAC1BC,oBAAoB,QACf,YAAY;AASnB,SACEC,QAAQ,EACRC,kBAAkB,EAClBC,uBAAuB,EACvBC,0BAA0B,EAC1BC,oBAAoB,QACf,YAAY;AASnB,SACEC,WAAW,EACXC,qBAAqB,EACrBC,0BAA0B,EAC1BC,6BAA6B,EAC7BC,uBAAuB,QAClB,eAAe;AAGtB;AACA,SAASC,aAAa,IAAIC,sBAAsB,EAAEC,uBAAuB,QAAQ,iBAAiB","names":["ComboboxProvider","ListboxProvider","useComboboxContextValues","useListboxContextValues","Listbox","listboxClassNames","renderListbox_unstable","useListboxStyles_unstable","useListbox_unstable","Option","optionClassNames","renderOption_unstable","useOptionStyles_unstable","useOption_unstable","Combobox","comboboxClassNames","renderCombobox_unstable","useComboboxStyles_unstable","useCombobox_unstable","Dropdown","dropdownClassNames","renderDropdown_unstable","useDropdownStyles_unstable","useDropdown_unstable","OptionGroup","optionGroupClassNames","renderOptionGroup_unstable","useOptionGroupStyles_unstable","useOptionGroup_unstable","ComboboxField","ComboboxField_unstable","comboboxFieldClassNames"],"sourceRoot":"../src/","sources":["packages/react-components/react-combobox/src/index.ts"],"sourcesContent":["export { ComboboxProvider } from './contexts/ComboboxContext';\nexport type { ComboboxContextValue } from './contexts/ComboboxContext';\nexport { ListboxProvider } from './contexts/ListboxContext';\nexport type { ListboxContextValue } from './contexts/ListboxContext';\nexport { useComboboxContextValues } from './contexts/useComboboxContextValues';\nexport { useListboxContextValues } from './contexts/useListboxContextValues';\nexport {\n Listbox,\n listboxClassNames,\n renderListbox_unstable,\n useListboxStyles_unstable,\n useListbox_unstable,\n} from './Listbox';\nexport type { ListboxContextValues, ListboxProps, ListboxSlots, ListboxState } from './Listbox';\nexport {\n Option,\n optionClassNames,\n renderOption_unstable,\n useOptionStyles_unstable,\n useOption_unstable,\n} from './Option';\nexport type { OptionProps, OptionSlots, OptionState } from './Option';\nexport {\n Combobox,\n comboboxClassNames,\n renderCombobox_unstable,\n useComboboxStyles_unstable,\n useCombobox_unstable,\n} from './Combobox';\nexport type {\n ComboboxContextValues,\n ComboboxOpenChangeData,\n ComboboxOpenEvents,\n ComboboxProps,\n ComboboxSlots,\n ComboboxState,\n} from './Combobox';\nexport {\n Dropdown,\n dropdownClassNames,\n renderDropdown_unstable,\n useDropdownStyles_unstable,\n useDropdown_unstable,\n} from './Dropdown';\nexport type {\n DropdownContextValues,\n DropdownOpenChangeData,\n DropdownOpenEvents,\n DropdownProps,\n DropdownSlots,\n DropdownState,\n} from './Dropdown';\nexport {\n OptionGroup,\n optionGroupClassNames,\n renderOptionGroup_unstable,\n useOptionGroupStyles_unstable,\n useOptionGroup_unstable,\n} from './OptionGroup';\nexport type { OptionGroupProps, OptionGroupSlots, OptionGroupState } from './OptionGroup';\n\n// eslint-disable-next-line deprecation/deprecation\nexport { ComboboxField as ComboboxField_unstable, comboboxFieldClassNames } from './ComboboxField';\n// eslint-disable-next-line deprecation/deprecation\nexport type { ComboboxFieldProps as ComboboxFieldProps_unstable } from './ComboboxField';\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"ComboboxBase.types.js","sourceRoot":"../src/","sources":["utils/ComboboxBase.types.ts"],"names":[],"mappings":"","sourcesContent":["import * as React from 'react';\nimport type { PositioningShorthand } from '@fluentui/react-positioning';\nimport type { ComboboxContextValue } from '../contexts/ComboboxContext';\nimport type { OptionValue, OptionCollectionState } from '../utils/OptionCollection.types';\nimport { SelectionEvents, SelectionProps, SelectionState } from '../utils/Selection.types';\n\n/**\n * ComboboxBase Props\n * Shared types between Combobox and Dropdown components\n */\nexport type ComboboxBaseProps = SelectionProps & {\n /**\n * Controls the colors and borders of the combobox trigger.\n * @default 'outline'\n */\n appearance?: 'filled-darker' | 'filled-lighter' | 'outline' | 'underline';\n\n /**\n * The default open state when open is uncontrolled\n */\n defaultOpen?: boolean;\n\n /**\n * The default value when the combobox's value is uncontrolled\n */\n defaultValue?: string;\n\n /**\n * Render the combobox's popup inline in the DOM.\n * This has accessibility benefits, particularly for touch screen readers.\n */\n inlinePopup?: boolean;\n\n /**\n * Callback when the open/closed state of the dropdown changes\n */\n onOpenChange?: (e: ComboboxBaseOpenEvents, data: ComboboxBaseOpenChangeData) => void;\n\n /**\n * Sets the open/closed state of the dropdown.\n * Use together with onOpenChange to fully control the dropdown's visibility\n */\n open?: boolean;\n\n /**\n * If set, the placeholder will show when no value is selected\n */\n placeholder?: string;\n\n /**\n * Configure the positioning of the combobox dropdown\n *\n * @defaultvalue below\n */\n positioning?: PositioningShorthand;\n\n /**\n * Controls the size of the combobox faceplate\n * @default 'medium'\n */\n size?: 'small' | 'medium' | 'large';\n\n /**\n * The value displayed by the Combobox.\n * Use this with `onSelect` to directly control the displayed value string\n */\n value?: string;\n};\n\n/**\n * State used in rendering Combobox\n */\nexport type ComboboxBaseState = Required<Pick<ComboboxBaseProps, 'appearance' | 'open' | 'inlinePopup' | 'size'>> &\n Pick<ComboboxBaseProps, 'placeholder' | 'value'> &\n OptionCollectionState &\n SelectionState & {\n /* Option data for the currently highlighted option (not the selected option) */\n activeOption?: OptionValue;\n\n /* Callback when an option is clicked, for internal use */\n onOptionClick(event: React.MouseEvent, option: OptionValue): void;\n\n selectOption(event: SelectionEvents, option: OptionValue): void;\n\n setActiveOption(option?: OptionValue): void;\n\n setOpen(event: ComboboxBaseOpenEvents, newState: boolean): void;\n };\n\n/**\n * Data for the Combobox onOpenChange event.\n */\nexport type ComboboxBaseOpenChangeData = {\n open: boolean;\n};\n\n/* Possible event types for onOpen */\nexport type ComboboxBaseOpenEvents =\n | React.MouseEvent<HTMLElement>\n | React.KeyboardEvent<HTMLElement>\n | React.FocusEvent<HTMLElement>;\n\nexport type ComboboxBaseContextValues = {\n combobox: ComboboxContextValue;\n};\n"]}
1
+ {"version":3,"file":"ComboboxBase.types.js","sourceRoot":"../src/","sources":["packages/react-components/react-combobox/src/utils/ComboboxBase.types.ts"],"names":[],"mappings":"","sourcesContent":["import * as React from 'react';\nimport type { PositioningShorthand } from '@fluentui/react-positioning';\nimport type { ComboboxContextValue } from '../contexts/ComboboxContext';\nimport type { OptionValue, OptionCollectionState } from '../utils/OptionCollection.types';\nimport { SelectionProps, SelectionState } from '../utils/Selection.types';\n\n/**\n * ComboboxBase Props\n * Shared types between Combobox and Dropdown components\n */\nexport type ComboboxBaseProps = SelectionProps & {\n /**\n * Controls the colors and borders of the combobox trigger.\n * @default 'outline'\n */\n appearance?: 'filled-darker' | 'filled-lighter' | 'outline' | 'underline';\n\n /**\n * The default open state when open is uncontrolled\n */\n defaultOpen?: boolean;\n\n /**\n * The default value displayed in the trigger input or button when the combobox's value is uncontrolled\n */\n defaultValue?: string;\n\n /**\n * Render the combobox's popup inline in the DOM.\n * This has accessibility benefits, particularly for touch screen readers.\n */\n inlinePopup?: boolean;\n\n /**\n * Callback when the open/closed state of the dropdown changes\n */\n onOpenChange?: (e: ComboboxBaseOpenEvents, data: ComboboxBaseOpenChangeData) => void;\n\n /**\n * Sets the open/closed state of the dropdown.\n * Use together with onOpenChange to fully control the dropdown's visibility\n */\n open?: boolean;\n\n /**\n * If set, the placeholder will show when no value is selected\n */\n placeholder?: string;\n\n /**\n * Configure the positioning of the combobox dropdown\n *\n * @defaultvalue below\n */\n positioning?: PositioningShorthand;\n\n /**\n * Controls the size of the combobox faceplate\n * @default 'medium'\n */\n size?: 'small' | 'medium' | 'large';\n\n /**\n * The value displayed by the Combobox.\n * Use this with `onOptionSelect` to directly control the displayed value string\n */\n value?: string;\n};\n\n/**\n * State used in rendering Combobox\n */\nexport type ComboboxBaseState = Required<Pick<ComboboxBaseProps, 'appearance' | 'open' | 'inlinePopup' | 'size'>> &\n Pick<ComboboxBaseProps, 'placeholder' | 'value' | 'multiselect'> &\n OptionCollectionState &\n SelectionState & {\n /* Option data for the currently highlighted option (not the selected option) */\n activeOption?: OptionValue;\n\n // Whether the keyboard focus outline style should be visible\n focusVisible: boolean;\n\n // whether the combobox/dropdown currently has focus\n hasFocus: boolean;\n\n /* Whether the next blur event should be ignored, and the combobox/dropdown will not close.*/\n ignoreNextBlur: React.MutableRefObject<boolean>;\n\n setActiveOption(option?: OptionValue): void;\n\n setFocusVisible(focusVisible: boolean): void;\n\n setHasFocus(hasFocus: boolean): void;\n\n setOpen(event: ComboboxBaseOpenEvents, newState: boolean): void;\n\n setValue(newValue: string | undefined): void;\n };\n\n/**\n * Data for the Combobox onOpenChange event.\n */\nexport type ComboboxBaseOpenChangeData = {\n open: boolean;\n};\n\n/* Possible event types for onOpen */\nexport type ComboboxBaseOpenEvents =\n | React.MouseEvent<HTMLElement>\n | React.KeyboardEvent<HTMLElement>\n | React.FocusEvent<HTMLElement>;\n\nexport type ComboboxBaseContextValues = {\n combobox: ComboboxContextValue;\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"OptionCollection.types.js","sourceRoot":"../src/","sources":["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 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. */\n getOptionsMatchingValue(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"]}
1
+ {"version":3,"file":"OptionCollection.types.js","sourceRoot":"../src/","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"]}
@@ -1 +1 @@
1
- {"version":3,"file":"Selection.types.js","sourceRoot":"../src/","sources":["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 onSelect?(event: SelectionEvents, data: OnSelectData): void;\n\n /**\n * An array of selected option keys.\n * Use this with `onSelect` to directly control the selected option(s)\n */\n selectedOptions?: string[];\n};\n\nexport type SelectionState = Required<Pick<SelectionProps, 'selectedOptions'>> & Pick<SelectionProps, 'multiselect'>;\n\n/* Values returned by the useSelection hook */\nexport type SelectionValue = {\n selectedOptions: string[];\n selectOption: (event: SelectionEvents, option: OptionValue) => void;\n};\n\n/* Data for the onSelect callback */\nexport type OnSelectData = { optionValue: string; selectedOptions: string[] };\n\n/* Possible event types for onSelect */\nexport type SelectionEvents = React.MouseEvent<HTMLElement> | React.KeyboardEvent<HTMLElement>;\n"]}
1
+ {"version":3,"file":"Selection.types.js","sourceRoot":"../src/","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"]}
@@ -2,7 +2,6 @@ import * as keys from '@fluentui/keyboard-keys';
2
2
  /**
3
3
  * Converts a keyboard interaction into a defined action
4
4
  */
5
-
6
5
  export function getDropdownActionFromKey(e, options = {}) {
7
6
  const {
8
7
  open = true,
@@ -14,99 +13,72 @@ export function getDropdownActionFromKey(e, options = {}) {
14
13
  ctrlKey,
15
14
  key,
16
15
  metaKey
17
- } = e; // typing action occurs whether open or closed
18
-
16
+ } = e;
17
+ // typing action occurs whether open or closed
19
18
  if (key.length === 1 && code !== keys.Space && !altKey && !ctrlKey && !metaKey) {
20
19
  return 'Type';
21
- } // handle opening the dropdown if closed
22
-
23
-
20
+ }
21
+ // handle opening the dropdown if closed
24
22
  if (!open) {
25
23
  if (code === keys.ArrowDown || code === keys.ArrowUp || code === keys.Enter || code === keys.Space) {
26
24
  return 'Open';
27
- } // if the dropdown is closed and an action did not match the above, do nothing
28
-
29
-
25
+ }
26
+ // if the dropdown is closed and an action did not match the above, do nothing
30
27
  return 'None';
31
- } // select or close actions
32
-
33
-
28
+ }
29
+ // select or close actions
34
30
  if (code === keys.ArrowUp && altKey || code === keys.Enter || !multiselect && code === keys.Space) {
35
31
  return 'CloseSelect';
36
32
  }
37
-
38
33
  if (multiselect && code === keys.Space) {
39
34
  return 'Select';
40
35
  }
41
-
42
36
  if (code === keys.Escape) {
43
37
  return 'Close';
44
- } // navigation interactions
45
-
46
-
47
- if (code === keys.ArrowRight || code === keys.ArrowDown) {
38
+ }
39
+ // navigation interactions
40
+ if (code === keys.ArrowDown) {
48
41
  return 'Next';
49
42
  }
50
-
51
- if (code === keys.ArrowLeft || code === keys.ArrowUp) {
43
+ if (code === keys.ArrowUp) {
52
44
  return 'Previous';
53
45
  }
54
-
55
46
  if (code === keys.Home) {
56
47
  return 'First';
57
48
  }
58
-
59
49
  if (code === keys.End) {
60
50
  return 'Last';
61
51
  }
62
-
63
52
  if (code === keys.PageUp) {
64
53
  return 'PageUp';
65
54
  }
66
-
67
55
  if (code === keys.PageDown) {
68
56
  return 'PageDown';
69
57
  }
70
-
71
58
  if (code === keys.Tab) {
72
59
  return 'Tab';
73
- } // if nothing matched, return none
74
-
75
-
60
+ }
61
+ // if nothing matched, return none
76
62
  return 'None';
77
63
  }
78
64
  /**
79
65
  * Returns the requested option index from an action
80
66
  */
81
-
82
67
  export function getIndexFromAction(action, currentIndex, maxIndex) {
83
68
  switch (action) {
84
69
  case 'Next':
85
70
  return Math.min(maxIndex, currentIndex + 1);
86
71
  break;
87
-
88
72
  case 'Previous':
89
73
  return Math.max(0, currentIndex - 1);
90
-
91
74
  case 'First':
92
75
  return 0;
93
-
94
76
  case 'Last':
95
77
  return maxIndex;
96
-
97
78
  case 'PageDown':
98
79
  return Math.min(maxIndex, currentIndex + 10);
99
-
100
80
  case 'PageUp':
101
81
  return Math.max(0, currentIndex - 10);
102
- // case 'Type':
103
- // // always prevent default and stop propagation when typing
104
- // e.preventDefault();
105
- // e.stopPropagation();
106
- // const matchingIndex = findByCharacter(e.key);
107
- // return matchingIndex > -1 ? matchingIndex : activeIndex;
108
- // break;
109
-
110
82
  default:
111
83
  return currentIndex;
112
84
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["utils/dropdownKeyActions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAZ,MAAsB,yBAAtB;AA2BA;;AAEG;;AACH,OAAM,SAAU,wBAAV,CACJ,CADI,EAEJ,OAAA,GAAiC,EAF7B,EAE+B;EAEnC,MAAM;IAAE,IAAI,GAAG,IAAT;IAAe,WAAW,GAAG;EAA7B,IAAuC,OAA7C;EACA,MAAM,IAAI,GAAG,CAAC,CAAC,GAAf;EACA,MAAM;IAAE,MAAF;IAAU,OAAV;IAAmB,GAAnB;IAAwB;EAAxB,IAAoC,CAA1C,CAJmC,CAMnC;;EAC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0B;IACxB,OAAO,QAAP;EACD;;EACD,IAAI,IAAI,KAAK,IAAI,CAAC,QAAlB,EAA4B;IAC1B,OAAO,UAAP;EACD;;EACD,IAAI,IAAI,KAAK,IAAI,CAAC,GAAlB,EAAuB;IACrB,OAAO,KAAP;EACD,CArDkC,CAuDnC;;;EACA,OAAO,MAAP;AACD;AAED;;AAEG;;AACH,OAAM,SAAU,kBAAV,CAA6B,MAA7B,EAAsD,YAAtD,EAA4E,QAA5E,EAA4F;EAChG,QAAQ,MAAR;IACE,KAAK,MAAL;MACE,OAAO,IAAI,CAAC,GAAL,CAAS,QAAT,EAAmB,YAAY,GAAG,CAAlC,CAAP;MACA;;IACF,KAAK,UAAL;MACE,OAAO,IAAI,CAAC,GAAL,CAAS,CAAT,EAAY,YAAY,GAAG,CAA3B,CAAP;;IACF,KAAK,OAAL;MACE,OAAO,CAAP;;IACF,KAAK,MAAL;MACE,OAAO,QAAP;;IACF,KAAK,UAAL;MACE,OAAO,IAAI,CAAC,GAAL,CAAS,QAAT,EAAmB,YAAY,GAAG,EAAlC,CAAP;;IACF,KAAK,QAAL;MACE,OAAO,IAAI,CAAC,GAAL,CAAS,CAAT,EAAY,YAAY,GAAG,EAA3B,CAAP;IACF;IACA;IACA;IACA;IAEA;IACA;IACA;;IACA;MACE,OAAO,YAAP;EAvBJ;AAyBD","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.ArrowRight || code === keys.ArrowDown) {\n return 'Next';\n }\n if (code === keys.ArrowLeft || 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 // case 'Type':\n // // always prevent default and stop propagation when typing\n // e.preventDefault();\n // e.stopPropagation();\n\n // const matchingIndex = findByCharacter(e.key);\n // return matchingIndex > -1 ? matchingIndex : activeIndex;\n // break;\n default:\n return currentIndex;\n }\n}\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"mappings":"AAAA,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R,IAAI,KAAKN,IAAI,CAACiB,IAAI,EAAE;IACtB,OAAO,OAAO;;EAEhB,IAAIX,IAAI,KAAKN,IAAI,CAACkB,GAAG,EAAE;IACrB,OAAO,MAAM;;EAEf,IAAIZ,IAAI,KAAKN,IAAI,CAACmB,MAAM,EAAE;IACxB,OAAO,QAAQ;;EAEjB,IAAIb,IAAI,KAAKN,IAAI,CAACoB,QAAQ,EAAE;IAC1B,OAAO,UAAU;;EAEnB,IAAId,IAAI,KAAKN,IAAI,CAACqB,GAAG,EAAE;IACrB,OAAO,KAAK;;EAGd;EACA,OAAO,MAAM;AACf;AAEA;;;AAGA,OAAM,SAAUC,kBAAkB,CAACC,MAAuB,EAAEC,YAAoB,EAAEC,QAAgB;EAChG,QAAQF,MAAM;IACZ,KAAK,MAAM;MACT,OAAOG,IAAI,CAACC,GAAG,CAACF,QAAQ,EAAED,YAAY,GAAG,CAAC,CAAC;MAC3C;IACF,KAAK,UAAU;MACb,OAAOE,IAAI,CAACE,GAAG,CAAC,CAAC,EAAEJ,YAAY,GAAG,CAAC,CAAC;IACtC,KAAK,OAAO;MACV,OAAO,CAAC;IACV,KAAK,MAAM;MACT,OAAOC,QAAQ;IACjB,KAAK,UAAU;MACb,OAAOC,IAAI,CAACC,GAAG,CAACF,QAAQ,EAAED,YAAY,GAAG,EAAE,CAAC;IAC9C,KAAK,QAAQ;MACX,OAAOE,IAAI,CAACE,GAAG,CAAC,CAAC,EAAEJ,YAAY,GAAG,EAAE,CAAC;IACvC;MACE,OAAOA,YAAY;EAAC;AAE1B","names":["keys","getDropdownActionFromKey","e","options","open","multiselect","code","key","altKey","ctrlKey","metaKey","length","Space","ArrowDown","ArrowUp","Enter","Escape","Home","End","PageUp","PageDown","Tab","getIndexFromAction","action","currentIndex","maxIndex","Math","min","max"],"sourceRoot":"../src/","sources":["packages/react-components/react-combobox/src/utils/dropdownKeyActions.ts"],"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"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["utils/internalTokens.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,SAAS,GAAG;EACvB,KAAK,EAAE,MADgB;EAEvB,MAAM,EAAE,MAFe;EAGvB,KAAK,EAAE;AAHgB,CAAlB","sourcesContent":["export const iconSizes = {\n small: '16px',\n medium: '20px',\n large: '24px',\n};\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"mappings":"AAAA,OAAO,MAAMA,SAAS,GAAG;EACvBC,KAAK,EAAE,MAAM;EACbC,MAAM,EAAE,MAAM;EACdC,KAAK,EAAE;CACR","names":["iconSizes","small","medium","large"],"sourceRoot":"../src/","sources":["packages/react-components/react-combobox/src/utils/internalTokens.ts"],"sourcesContent":["export const iconSizes = {\n small: '16px',\n medium: '20px',\n large: '24px',\n};\n"]}
@@ -5,10 +5,11 @@ import { useSelection } from '../utils/useSelection';
5
5
  /**
6
6
  * State shared between Combobox and Dropdown components
7
7
  */
8
-
9
8
  export const useComboboxBaseState = props => {
10
9
  const {
11
10
  appearance = 'outline',
11
+ children,
12
+ editable = false,
12
13
  inlinePopup = false,
13
14
  multiselect,
14
15
  onOpenChange,
@@ -17,83 +18,86 @@ export const useComboboxBaseState = props => {
17
18
  const optionCollection = useOptionCollection();
18
19
  const {
19
20
  getOptionAtIndex,
20
- getOptionById,
21
- getOptionsMatchingValue
21
+ getOptionsMatchingText
22
22
  } = optionCollection;
23
23
  const [activeOption, setActiveOption] = React.useState();
24
+ // track whether keyboard focus outline should be shown
25
+ // tabster/keyborg doesn't work here, since the actual keyboard focus target doesn't move
26
+ const [focusVisible, setFocusVisible] = React.useState(false);
27
+ // track focused state to conditionally render collapsed listbox
28
+ const [hasFocus, setHasFocus] = React.useState(false);
29
+ const ignoreNextBlur = React.useRef(false);
30
+ const selectionState = useSelection(props);
24
31
  const {
25
- selectedOptions,
26
- selectOption
27
- } = useSelection(props); // update value based on selectedOptions
28
-
32
+ selectedOptions
33
+ } = selectionState;
34
+ // calculate value based on props, internal value changes, and selected options
29
35
  const isFirstMount = useFirstMount();
36
+ const [controllableValue, setValue] = useControllableState({
37
+ state: props.value,
38
+ initialState: undefined
39
+ });
30
40
  const value = React.useMemo(() => {
31
- // don't compute value if it is defined through props,
32
- if (props.value !== undefined) {
33
- return props.value;
41
+ // don't compute the value if it is defined through props or setValue,
42
+ if (controllableValue !== undefined) {
43
+ return controllableValue;
34
44
  }
35
-
45
+ // handle defaultValue here, so it is overridden by selection
36
46
  if (isFirstMount && props.defaultValue !== undefined) {
37
47
  return props.defaultValue;
38
48
  }
39
-
40
49
  if (multiselect) {
41
- return selectedOptions.join(', ');
50
+ // editable inputs should not display multiple selected options in the input as text
51
+ return editable ? '' : selectedOptions.join(', ');
42
52
  }
43
-
44
53
  return selectedOptions[0];
45
- }, [isFirstMount, multiselect, props.defaultValue, props.value, selectedOptions]); // Handle open state, which is shared with options in context
46
-
54
+ }, [controllableValue, editable, isFirstMount, multiselect, props.defaultValue, selectedOptions]);
55
+ // Handle open state, which is shared with options in context
47
56
  const [open, setOpenState] = useControllableState({
48
57
  state: props.open,
49
58
  defaultState: props.defaultOpen,
50
59
  initialState: false
51
60
  });
52
-
53
- const setOpen = (event, newState) => {
61
+ const setOpen = React.useCallback((event, newState) => {
54
62
  onOpenChange === null || onOpenChange === void 0 ? void 0 : onOpenChange(event, {
55
63
  open: newState
56
64
  });
57
65
  setOpenState(newState);
58
- };
59
-
60
- const onOptionClick = (event, option) => {
61
- // clicked option should always become active option
62
- setActiveOption(getOptionById(option.id)); // close on option click for single-select
63
-
64
- !multiselect && setOpen(event, false); // handle selection change
65
-
66
- selectOption(event, option);
67
- }; // update active option based on change in open state
68
-
69
-
66
+ }, [onOpenChange, setOpenState]);
67
+ // update active option based on change in open state or children
70
68
  React.useEffect(() => {
71
- if (open) {
72
- // if there is a selection, start at the most recently selected item
73
- if (selectedOptions.length > 0) {
74
- const lastSelectedOption = getOptionsMatchingValue(v => v === selectedOptions[selectedOptions.length - 1]).pop();
75
- lastSelectedOption && setActiveOption(lastSelectedOption);
76
- } // default to starting at the first option
69
+ if (open && !activeOption) {
70
+ // if it is single-select and there is a selected option, start at the selected option
71
+ if (!multiselect && selectedOptions.length > 0) {
72
+ const selectedOption = getOptionsMatchingText(v => v === selectedOptions[0]).pop();
73
+ selectedOption && setActiveOption(selectedOption);
74
+ }
75
+ // default to starting at the first option
77
76
  else {
78
77
  setActiveOption(getOptionAtIndex(0));
79
78
  }
80
- } else {
79
+ } else if (!open) {
81
80
  // reset the active option when closing
82
81
  setActiveOption(undefined);
83
- } // this should only be run in response to changes in the open state
82
+ }
83
+ // this should only be run in response to changes in the open state or children
84
84
  // eslint-disable-next-line react-hooks/exhaustive-deps
85
-
86
- }, [open]);
87
- return { ...optionCollection,
85
+ }, [open, children]);
86
+ return {
87
+ ...optionCollection,
88
+ ...selectionState,
88
89
  activeOption,
89
90
  appearance,
91
+ focusVisible,
92
+ hasFocus,
93
+ ignoreNextBlur,
90
94
  inlinePopup,
91
- onOptionClick,
92
95
  open,
93
- selectedOptions,
94
- selectOption,
95
96
  setActiveOption,
97
+ setFocusVisible,
98
+ setHasFocus,
96
99
  setOpen,
100
+ setValue,
97
101
  size,
98
102
  value
99
103
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["utils/useComboboxBaseState.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,oBAAT,EAA+B,aAA/B,QAAoD,2BAApD;AACA,SAAS,mBAAT,QAAoC,8BAApC;AAEA,SAAS,YAAT,QAA6B,uBAA7B;AAGA;;AAEG;;AACH,OAAO,MAAM,oBAAoB,GAAI,KAAD,IAA6B;EAC/D,MAAM;IAAE,UAAU,GAAG,SAAf;IAA0B,WAAW,GAAG,KAA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AV,CAAZ;IACA,YAAY,CAAC,QAAD,CAAZ;EACD,CAHD;;EAKA,MAAM,aAAa,GAAG,CAAC,KAAD,EAAuC,MAAvC,KAA8D;IAClF;IACA,eAAe,CAAC,aAAa,CAAC,MAAM,CAAC,EAAR,CAAd,CAAf,CAFkF,CAIlF;;IACA,CAAC,WAAD,IAAgB,OAAO,CAAC,KAAD,EAAQ,KAAR,CAAvB,CALkF,CAOlF;;IACA,YAAY,CAAC,KAAD,EAAQ,MAAR,CAAZ;EACD,CATD,CAxC+D,CAmD/D;;;EACA,KAAK,CAAC,SAAN,CAAgB,MAAK;IACnB,IAAI,IAAJ,EAAU;MACR;MACA,IAAI,eAAe,CAAC,MAAhB,GAAyB,CAA7B,EAAgC;QAC9B,MAAM,kBAAkB,GAAG,uBAAuB,CAChD,CAAC,IAAI,CAAC,KAAK,eAAe,CAAC,eAAe,CAAC,MAAhB,GAAyB,CAA1B,CADsB,CAAvB,CAEzB,GAFyB,EAA3B;QAGA,kBAAkB,IAAI,eAAe,CAAC,kBAAD,CAArC;MACD,CALD,CAMA;MANA,KAOK;QACH,eAAe,CAAC,gBAAgB,CAAC,CAAD,CAAjB,CAAf;MACD;IACF,CAZD,MAYO;MACL;MACA,eAAe,CAAC,SAAD,CAAf;IACD,CAhBkB,CAiBnB;IACA;;EACD,CAnBD,EAmBG,CAAC,IAAD,CAnBH;EAqBA,OAAO,EACL,GAAG,gBADE;IAEL,YAFK;IAGL,UAHK;IAIL,WAJK;IAKL,aALK;IAML,IANK;IAOL,eAPK;IAQL,YARK;IASL,eATK;IAUL,OAVK;IAWL,IAXK;IAYL;EAZK,CAAP;AAcD,CAvFM","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 } from './ComboboxBase.types';\n\n/**\n * State shared between Combobox and Dropdown components\n */\nexport const useComboboxBaseState = (props: ComboboxBaseProps) => {\n const { appearance = 'outline', inlinePopup = false, multiselect, onOpenChange, size = 'medium' } = props;\n\n const optionCollection = useOptionCollection();\n const { getOptionAtIndex, getOptionById, getOptionsMatchingValue } = optionCollection;\n\n const [activeOption, setActiveOption] = React.useState<OptionValue | undefined>();\n const { selectedOptions, selectOption } = useSelection(props);\n\n // update value based on selectedOptions\n const isFirstMount = useFirstMount();\n const value = React.useMemo(() => {\n // don't compute value if it is defined through props,\n if (props.value !== undefined) {\n return props.value;\n }\n\n if (isFirstMount && props.defaultValue !== undefined) {\n return props.defaultValue;\n }\n\n if (multiselect) {\n return selectedOptions.join(', ');\n }\n\n return selectedOptions[0];\n }, [isFirstMount, multiselect, props.defaultValue, props.value, 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 = (event: ComboboxBaseOpenEvents, newState: boolean) => {\n onOpenChange?.(event, { open: newState });\n setOpenState(newState);\n };\n\n const onOptionClick = (event: React.MouseEvent<HTMLElement>, option: OptionValue) => {\n // clicked option should always become active option\n setActiveOption(getOptionById(option.id));\n\n // close on option click for single-select\n !multiselect && setOpen(event, false);\n\n // handle selection change\n selectOption(event, option);\n };\n\n // update active option based on change in open state\n React.useEffect(() => {\n if (open) {\n // if there is a selection, start at the most recently selected item\n if (selectedOptions.length > 0) {\n const lastSelectedOption = getOptionsMatchingValue(\n v => v === selectedOptions[selectedOptions.length - 1],\n ).pop();\n lastSelectedOption && setActiveOption(lastSelectedOption);\n }\n // default to starting at the first option\n else {\n setActiveOption(getOptionAtIndex(0));\n }\n } else {\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\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [open]);\n\n return {\n ...optionCollection,\n activeOption,\n appearance,\n inlinePopup,\n onOptionClick,\n open,\n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C,CAAC,CAACuB,GAAG,EAAE;QAClFF,cAAc,IAAI9B,eAAe,CAAC8B,cAAc,CAAC;;MAEnD;MAAA,KACK;QACH9B,eAAe,CAACH,gBAAgB,CAAC,CAAC,CAAC,CAAC;;KAEvC,MAAM,IAAI,CAACuB,IAAI,EAAE;MAChB;MACApB,eAAe,CAACgB,SAAS,CAAC;;IAE5B;IACA;EACF,CAAC,EAAE,CAACI,IAAI,EAAE9B,QAAQ,CAAC,CAAC;EAEpB,OAAO;IACL,GAAGM,gBAAgB;IACnB,GAAGY,cAAc;IACjBT,YAAY;IACZV,UAAU;IACVa,YAAY;IACZE,QAAQ;IACRE,cAAc;IACdd,WAAW;IACX4B,IAAI;IACJpB,eAAe;IACfG,eAAe;IACfE,WAAW;IACXmB,OAAO;IACPZ,QAAQ;IACRjB,IAAI;IACJmB;GACD;AACH,CAAC","names":["React","useControllableState","useFirstMount","useOptionCollection","useSelection","useComboboxBaseState","props","appearance","children","editable","inlinePopup","multiselect","onOpenChange","size","optionCollection","getOptionAtIndex","getOptionsMatchingText","activeOption","setActiveOption","useState","focusVisible","setFocusVisible","hasFocus","setHasFocus","ignoreNextBlur","useRef","selectionState","selectedOptions","isFirstMount","controllableValue","setValue","state","value","initialState","undefined","useMemo","defaultValue","join","open","setOpenState","defaultState","defaultOpen","setOpen","useCallback","event","newState","useEffect","length","selectedOption","v","pop"],"sourceRoot":"../src/","sources":["packages/react-components/react-combobox/src/utils/useComboboxBaseState.ts"],"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"]}
@@ -3,8 +3,8 @@ import { useMergedRefs } from '@fluentui/react-utilities';
3
3
  export function useComboboxPopup(props, triggerShorthand, listboxShorthand) {
4
4
  const {
5
5
  positioning
6
- } = props; // popper options
7
-
6
+ } = props;
7
+ // popper options
8
8
  const popperOptions = {
9
9
  position: 'below',
10
10
  align: 'start',
@@ -18,10 +18,14 @@ export function useComboboxPopup(props, triggerShorthand, listboxShorthand) {
18
18
  targetRef,
19
19
  containerRef
20
20
  } = usePositioning(popperOptions);
21
- return [{ ...triggerShorthand,
21
+ const listboxRef = useMergedRefs(listboxShorthand === null || listboxShorthand === void 0 ? void 0 : listboxShorthand.ref, containerRef);
22
+ const listbox = listboxShorthand && {
23
+ ...listboxShorthand,
24
+ ref: listboxRef
25
+ };
26
+ return [{
27
+ ...triggerShorthand,
22
28
  ref: useMergedRefs(triggerShorthand === null || triggerShorthand === void 0 ? void 0 : triggerShorthand.ref, targetRef)
23
- }, { ...listboxShorthand,
24
- ref: useMergedRefs(listboxShorthand === null || listboxShorthand === void 0 ? void 0 : listboxShorthand.ref, containerRef)
25
- }];
29
+ }, listbox];
26
30
  }
27
31
  //# sourceMappingURL=useComboboxPopup.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["utils/useComboboxPopup.ts"],"names":[],"mappings":"AAAA,SAAS,2BAAT,EAAsC,cAAtC,QAA4D,6BAA5D;AACA,SAAiC,aAAjC,QAAsD,2BAAtD;AAeA,OAAM,SAAU,gBAAV,CACJ,KADI,EAEJ,gBAFI,EAGJ,gBAHI,EAGqD;EAEzD,MAAM;IAAE;EAAF,IAAkB,KAAxB,CAFyD,CAIzD;;EACA,MAAM,aAAa,GAAG;IACpB,QAAQ,EAAE,OADU;IAEpB,KAAK,EAAE,OAFa;IAGpB,MAAM,EAAE;MAAE,SAAS,EAAE,CAAb;MAAgB,QAAQ,EAAE;IAA1B,CAHY;IAIpB,GAAG,2BAA2B,CAAC,WAAD;EAJV,CAAtB;EAOA,MAAM;IAAE,SAAF;IAAa;EAAb,IAA8B,cAAc,CAAC,aAAD,CAAlD;EAEA,OAAO,CACL,EAAE,GAAG,gBAAL;IAAuB,GAAG,EAAE,aAAa,CAAC,gBAAgB,KAAA,IAAhB,IAAA,gBAAgB,KAAA,KAAA,CAAhB,GAAgB,KAAA,CAAhB,GAAA,gBAAgB,CAAE,GAAnB,EAAwB,SAAxB;EAAzC,CADK,EAEL,EAAE,GAAG,gBAAL;IAAuB,GAAG,EAAE,aAAa,CAAC,gBAAgB,KAAA,IAAhB,IAAA,gBAAgB,KAAA,KAAA,CAAhB,GAAgB,KAAA,CAAhB,GAAA,gBAAgB,CAAE,GAAnB,EAAwB,YAAxB;EAAzC,CAFK,CAAP;AAID","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): [ExtractSlotProps<Slot<'button'>>, ExtractSlotProps<Slot<typeof Listbox>>];\nexport function useComboboxPopup(\n props: ComboboxBaseProps,\n triggerShorthand?: ExtractSlotProps<Slot<'input'>>,\n listboxShorthand?: ExtractSlotProps<Slot<typeof Listbox>>,\n): [ExtractSlotProps<Slot<'input'>>, 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): [ExtractSlotProps<Slot<'input'>> | ExtractSlotProps<Slot<'button'>>, ExtractSlotProps<Slot<typeof Listbox>>] {\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 return [\n { ...triggerShorthand, ref: useMergedRefs(triggerShorthand?.ref, targetRef) },\n { ...listboxShorthand, ref: useMergedRefs(listboxShorthand?.ref, containerRef) },\n ];\n}\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"mappings":"AAAA,SAASA,2BAA2B,EAAEC,cAAc,QAAQ,6BAA6B;AACzF,SAAiCC,aAAa,QAAQ,2BAA2B;AAejF,OAAM,SAAUC,gBAAgB,CAC9BC,KAAwB,EACxBC,gBAAqF,EACrFC,gBAAyD;EAKzD,MAAM;IAAEC;EAAW,CAAE,GAAGH,KAAK;EAE7B;EACA,MAAMI,aAAa,GAAG;IACpBC,QAAQ,EAAE,OAAgB;IAC1BC,KAAK,EAAE,OAAgB;IACvBC,MAAM,EAAE;MAAEC,SAAS,EAAE,CAAC;MAAEC,QAAQ,EAAE;IAAC,CAAE;IACrC,GAAGb,2BAA2B,CAACO,WAAW;GAC3C;EAED,MAAM;IAAEO,SAAS;IAAEC;EAAY,CAAE,GAAGd,cAAc,CAACO,aAAa,CAAC;EAEjE,MAAMQ,UAAU,GAAGd,aAAa,CAACI,gBAAgB,aAAhBA,gBAAgB,uBAAhBA,gBAAgB,CAAEW,GAAG,EAAEF,YAAY,CAAC;EACrE,MAAMG,OAAO,GAAGZ,gBAAgB,IAAI;IAAE,GAAGA,gBAAgB;IAAEW,GAAG,EAAED;EAAU,CAAE;EAE5E,OAAO,CAAC;IAAE,GAAGX,gBAAgB;IAAEY,GAAG,EAAEf,aAAa,CAACG,gBAAgB,aAAhBA,gBAAgB,uBAAhBA,gBAAgB,CAAEY,GAAG,EAAEH,SAAS;EAAC,CAAE,EAAEI,OAAO,CAAC;AACjG","names":["resolvePositioningShorthand","usePositioning","useMergedRefs","useComboboxPopup","props","triggerShorthand","listboxShorthand","positioning","popperOptions","position","align","offset","crossAxis","mainAxis","targetRef","containerRef","listboxRef","ref","listbox"],"sourceRoot":"../src/","sources":["packages/react-components/react-combobox/src/utils/useComboboxPopup.ts"],"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"]}
@@ -2,73 +2,63 @@ import * as React from 'react';
2
2
  /**
3
3
  * A hook for managing a collection of child Options
4
4
  */
5
-
6
5
  export const useOptionCollection = () => {
7
6
  const nodes = React.useRef([]);
8
7
  const collectionAPI = React.useMemo(() => {
9
8
  const getCount = () => nodes.current.length;
10
-
11
9
  const getOptionAtIndex = index => {
12
10
  var _a;
13
-
14
11
  return (_a = nodes.current[index]) === null || _a === void 0 ? void 0 : _a.option;
15
12
  };
16
-
17
13
  const getIndexOfId = id => nodes.current.findIndex(node => node.option.id === id);
18
-
19
14
  const getOptionById = id => {
20
15
  const item = nodes.current.find(node => node.option.id === id);
21
16
  return item === null || item === void 0 ? void 0 : item.option;
22
17
  };
23
-
24
- const getOptionsMatchingValue = matcher => {
25
- return nodes.current.filter(node => matcher(node.option.value)).map(node => node.option);
18
+ const getOptionsMatchingText = matcher => {
19
+ return nodes.current.filter(node => matcher(node.option.text)).map(node => node.option);
26
20
  };
27
-
28
21
  return {
29
22
  getCount,
30
23
  getOptionAtIndex,
31
24
  getIndexOfId,
32
25
  getOptionById,
33
- getOptionsMatchingValue
26
+ getOptionsMatchingText
34
27
  };
35
28
  }, []);
36
29
  const registerOption = React.useCallback((option, element) => {
37
30
  var _a;
38
-
39
31
  const index = nodes.current.findIndex(node => {
40
32
  if (!node.element || !element) {
41
33
  return false;
42
34
  }
43
-
44
35
  if (node.option.id === option.id) {
45
36
  return true;
46
- } // use the DOM method compareDocumentPosition to order the current node against registered nodes
37
+ }
38
+ // use the DOM method compareDocumentPosition to order the current node against registered nodes
47
39
  // eslint-disable-next-line no-bitwise
48
-
49
-
50
40
  return node.element.compareDocumentPosition(element) & Node.DOCUMENT_POSITION_PRECEDING;
51
- }); // do not register the option if it already exists
52
-
41
+ });
42
+ // do not register the option if it already exists
53
43
  if (((_a = nodes.current[index]) === null || _a === void 0 ? void 0 : _a.option.id) !== option.id) {
54
44
  const newItem = {
55
45
  element,
56
46
  option
57
- }; // If an index is not found we will push the element to the end.
58
-
47
+ };
48
+ // If an index is not found we will push the element to the end.
59
49
  if (index === -1) {
60
50
  nodes.current = [...nodes.current, newItem];
61
51
  } else {
62
52
  nodes.current.splice(index, 0, newItem);
63
53
  }
64
- } // return the unregister function
65
-
66
-
54
+ }
55
+ // return the unregister function
67
56
  return () => {
68
57
  nodes.current = nodes.current.filter(node => node.option.id !== option.id);
69
58
  };
70
59
  }, []);
71
- return { ...collectionAPI,
60
+ return {
61
+ ...collectionAPI,
72
62
  options: nodes.current.map(node => node.option),
73
63
  registerOption
74
64
  };