@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
@@ -1,10 +1,11 @@
1
1
  import * as React from 'react';
2
- import { getNativeElementProps } from '@fluentui/react-utilities';
2
+ import { getNativeElementProps, mergeCallbacks, useEventCallback, useMergedRefs } from '@fluentui/react-utilities';
3
3
  import { useContextSelector, useHasParentContext } from '@fluentui/react-context-selector';
4
- import { useSelection } from '../../utils/useSelection';
5
4
  import { getDropdownActionFromKey, getIndexFromAction } from '../../utils/dropdownKeyActions';
6
- import { ComboboxContext } from '../../contexts/ComboboxContext';
7
5
  import { useOptionCollection } from '../../utils/useOptionCollection';
6
+ import { useScrollOptionsIntoView } from '../../utils/useScrollOptionsIntoView';
7
+ import { useSelection } from '../../utils/useSelection';
8
+ import { ComboboxContext } from '../../contexts/ComboboxContext';
8
9
  /**
9
10
  * Create the state required to render Listbox.
10
11
  *
@@ -14,7 +15,6 @@ import { useOptionCollection } from '../../utils/useOptionCollection';
14
15
  * @param props - props from this instance of Listbox
15
16
  * @param ref - reference to root HTMLElement of Listbox
16
17
  */
17
-
18
18
  export const useListbox_unstable = (props, ref) => {
19
19
  const {
20
20
  multiselect
@@ -23,22 +23,17 @@ export const useListbox_unstable = (props, ref) => {
23
23
  const {
24
24
  getCount,
25
25
  getOptionAtIndex,
26
- getOptionById,
27
26
  getIndexOfId
28
27
  } = optionCollection;
29
28
  const {
29
+ clearSelection,
30
30
  selectedOptions,
31
31
  selectOption
32
32
  } = useSelection(props);
33
33
  const [activeOption, setActiveOption] = React.useState();
34
-
35
- const onOptionClick = (event, option) => {
36
- // clicked option should always become active option
37
- setActiveOption(getOptionById(option.id)); // handle selection change
38
-
39
- selectOption(event, option);
40
- };
41
-
34
+ // track whether keyboard focus outline should be shown
35
+ // tabster/keyborg doesn't work here, since the actual keyboard focus target doesn't move
36
+ const [focusVisible, setFocusVisible] = React.useState(false);
42
37
  const onKeyDown = event => {
43
38
  const action = getDropdownActionFromKey(event, {
44
39
  open: true
@@ -46,55 +41,66 @@ export const useListbox_unstable = (props, ref) => {
46
41
  const maxIndex = getCount() - 1;
47
42
  const activeIndex = activeOption ? getIndexOfId(activeOption.id) : -1;
48
43
  let newIndex = activeIndex;
49
-
50
44
  switch (action) {
51
45
  case 'Select':
52
46
  case 'CloseSelect':
53
47
  activeOption && selectOption(event, activeOption);
54
48
  break;
55
-
56
49
  default:
57
50
  newIndex = getIndexFromAction(action, activeIndex, maxIndex);
58
51
  }
59
-
60
52
  if (newIndex !== activeIndex) {
61
53
  // prevent default page scroll/keyboard action if the index changed
62
54
  event.preventDefault();
63
55
  setActiveOption(getOptionAtIndex(newIndex));
56
+ setFocusVisible(true);
64
57
  }
65
- }; // get state from parent combobox, if it exists
66
-
67
-
58
+ };
59
+ const onMouseOver = event => {
60
+ setFocusVisible(false);
61
+ };
62
+ // get state from parent combobox, if it exists
68
63
  const hasComboboxContext = useHasParentContext(ComboboxContext);
69
64
  const comboboxActiveOption = useContextSelector(ComboboxContext, ctx => ctx.activeOption);
70
- const comboboxOnOptionClick = useContextSelector(ComboboxContext, ctx => ctx.onOptionClick);
71
- const comboboxSelectedOptions = useContextSelector(ComboboxContext, ctx => ctx.selectedOptions); // without a parent combobox context, provide values directly from Listbox
72
-
65
+ const comboboxFocusVisible = useContextSelector(ComboboxContext, ctx => ctx.focusVisible);
66
+ const comboboxSelectedOptions = useContextSelector(ComboboxContext, ctx => ctx.selectedOptions);
67
+ const comboboxSelectOption = useContextSelector(ComboboxContext, ctx => ctx.selectOption);
68
+ const comboboxSetActiveOption = useContextSelector(ComboboxContext, ctx => ctx.setActiveOption);
69
+ // without a parent combobox context, provide values directly from Listbox
73
70
  const optionContextValues = hasComboboxContext ? {
74
71
  activeOption: comboboxActiveOption,
75
- onOptionClick: comboboxOnOptionClick,
76
- selectedOptions: comboboxSelectedOptions
72
+ focusVisible: comboboxFocusVisible,
73
+ selectedOptions: comboboxSelectedOptions,
74
+ selectOption: comboboxSelectOption,
75
+ setActiveOption: comboboxSetActiveOption
77
76
  } : {
78
77
  activeOption,
79
- onOptionClick,
80
- selectedOptions
78
+ focusVisible,
79
+ selectedOptions,
80
+ selectOption,
81
+ setActiveOption
81
82
  };
82
- return {
83
+ const state = {
83
84
  components: {
84
85
  root: 'div'
85
86
  },
86
87
  root: getNativeElementProps('div', {
87
88
  ref,
88
- role: 'listbox',
89
+ role: multiselect ? 'menu' : 'listbox',
89
90
  'aria-activedescendant': hasComboboxContext ? undefined : activeOption === null || activeOption === void 0 ? void 0 : activeOption.id,
90
91
  'aria-multiselectable': multiselect,
91
92
  tabIndex: 0,
92
- onKeyDown,
93
93
  ...props
94
94
  }),
95
95
  multiselect,
96
+ clearSelection,
96
97
  ...optionCollection,
97
98
  ...optionContextValues
98
99
  };
100
+ const scrollContainerRef = useScrollOptionsIntoView(state);
101
+ state.root.ref = useMergedRefs(state.root.ref, scrollContainerRef);
102
+ state.root.onKeyDown = useEventCallback(mergeCallbacks(state.root.onKeyDown, onKeyDown));
103
+ state.root.onMouseOver = useEventCallback(mergeCallbacks(state.root.onMouseOver, onMouseOver));
104
+ return state;
99
105
  };
100
106
  //# sourceMappingURL=useListbox.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["components/Listbox/useListbox.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,qBAAT,QAAsC,2BAAtC;AACA,SAAS,kBAAT,EAA6B,mBAA7B,QAAwD,kCAAxD;AACA,SAAS,YAAT,QAA6B,0BAA7B;AACA,SAAS,wBAAT,EAAmC,kBAAnC,QAA6D,gCAA7D;AACA,SAAS,eAAT,QAAgC,gCAAhC;AAEA,SAAS,mBAAT,QAAoC,iCAApC;AAGA;;;;;;;;AAQG;;AACH,OAAO,MAAM,mBAAmB,GAAG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MAAM,oBAAoB,GAAG,kBAAkB,CAAC,eAAD,EAAkB,GAAG,IAAI,GAAG,CAAC,YAA7B,CAA/C;EACA,MAAM,qBAAqB,GAAG,kBAAkB,CAAC,eAAD,EAAkB,GAAG,IAAI,GAAG,CAAC,aAA7B,CAAhD;EACA,MAAM,uBAAuB,GAAG,kBAAkB,CAAC,eAAD,EAAkB,GAAG,IAAI,GAAG,CAAC,eAA7B,CAAlD,CA3CoG,CA6CpG;;EACA,MAAM,mBAAmB,GAAG,kBAAkB,GAC1C;IACE,YAAY,EAAE,oBADhB;IAEE,aAAa,EAAE,qBAFjB;IAGE,eAAe,EAAE;EAHnB,CAD0C,GAM1C;IACE,YADF;IAEE,aAFF;IAGE;EAHF,CANJ;EAYA,OAAO;IACL,UAAU,EAAE;MACV,IAAI,EAAE;IADI,CADP;IAIL,IAAI,EAAE,qBAAqB,CAAC,KAAD,EAAQ;MACjC,GADiC;MAEjC,IAAI,EAAE,SAF2B;MAGjC,yBAAyB,kBAAkB,GAAG,SAAH,GAAe,YAAY,KAAA,IAAZ,IAAA,YAAY,KAAA,KAAA,CAAZ,GAAY,KAAA,CAAZ,GAAA,YAAY,CAAE,EAHvC;MAIjC,wBAAwB,WAJS;MAKjC,QAAQ,EAAE,CALuB;MAMjC,SANiC;MAOjC,GAAG;IAP8B,CAAR,CAJtB;IAaL,WAbK;IAcL,GAAG,gBAdE;IAeL,GAAG;EAfE,CAAP;AAiBD,CA3EM","sourcesContent":["import * as React from 'react';\nimport { getNativeElementProps } from '@fluentui/react-utilities';\nimport { useContextSelector, useHasParentContext } from '@fluentui/react-context-selector';\nimport { useSelection } from '../../utils/useSelection';\nimport { getDropdownActionFromKey, getIndexFromAction } from '../../utils/dropdownKeyActions';\nimport { ComboboxContext } from '../../contexts/ComboboxContext';\nimport type { ListboxProps, ListboxState } from './Listbox.types';\nimport { useOptionCollection } from '../../utils/useOptionCollection';\nimport { OptionValue } from '../../utils/OptionCollection.types';\n\n/**\n * Create the state required to render Listbox.\n *\n * The returned state can be modified with hooks such as useListboxStyles_unstable,\n * before being passed to renderListbox_unstable.\n *\n * @param props - props from this instance of Listbox\n * @param ref - reference to root HTMLElement of Listbox\n */\nexport const useListbox_unstable = (props: ListboxProps, ref: React.Ref<HTMLElement>): ListboxState => {\n const { multiselect } = props;\n const optionCollection = useOptionCollection();\n const { getCount, getOptionAtIndex, getOptionById, getIndexOfId } = optionCollection;\n\n const { selectedOptions, selectOption } = useSelection(props);\n\n const [activeOption, setActiveOption] = React.useState<OptionValue | undefined>();\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 // handle selection change\n selectOption(event, option);\n };\n\n const onKeyDown = (event: React.KeyboardEvent<HTMLElement>) => {\n const action = getDropdownActionFromKey(event, { open: true });\n const maxIndex = getCount() - 1;\n const activeIndex = activeOption ? getIndexOfId(activeOption.id) : -1;\n let newIndex = activeIndex;\n\n switch (action) {\n case 'Select':\n case 'CloseSelect':\n activeOption && selectOption(event, activeOption);\n break;\n default:\n newIndex = getIndexFromAction(action, activeIndex, maxIndex);\n }\n\n if (newIndex !== activeIndex) {\n // prevent default page scroll/keyboard action if the index changed\n event.preventDefault();\n setActiveOption(getOptionAtIndex(newIndex));\n }\n };\n\n // get state from parent combobox, if it exists\n const hasComboboxContext = useHasParentContext(ComboboxContext);\n const comboboxActiveOption = useContextSelector(ComboboxContext, ctx => ctx.activeOption);\n const comboboxOnOptionClick = useContextSelector(ComboboxContext, ctx => ctx.onOptionClick);\n const comboboxSelectedOptions = useContextSelector(ComboboxContext, ctx => ctx.selectedOptions);\n\n // without a parent combobox context, provide values directly from Listbox\n const optionContextValues = hasComboboxContext\n ? {\n activeOption: comboboxActiveOption,\n onOptionClick: comboboxOnOptionClick,\n selectedOptions: comboboxSelectedOptions,\n }\n : {\n activeOption,\n onOptionClick,\n selectedOptions,\n };\n\n return {\n components: {\n root: 'div',\n },\n root: getNativeElementProps('div', {\n ref,\n role: 'listbox',\n 'aria-activedescendant': hasComboboxContext ? undefined : activeOption?.id,\n 'aria-multiselectable': multiselect,\n tabIndex: 0,\n onKeyDown,\n ...props,\n }),\n multiselect,\n ...optionCollection,\n ...optionContextValues,\n };\n};\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SAASC,qBAAqB,EAAEC,cAAc,EAAEC,gBAAgB,EAAEC,aAAa,QAAQ,2BAA2B;AAClH,SAASC,kBAAkB,EAAEC,mBAAmB,QAAQ,kCAAkC;AAC1F,SAASC,wBAAwB,EAAEC,kBAAkB,QAAQ,gCAAgC;AAE7F,SAASC,mBAAmB,QAAQ,iCAAiC;AACrE,SAASC,wBAAwB,QAAQ,sCAAsC;AAC/E,SAASC,YAAY,QAAQ,0BAA0B;AACvD,SAASC,eAAe,QAAQ,gCAAgC;AAGhE;;;;;;;;;AASA,OAAO,MAAMC,mBAAmB,GAAG,CAACC,KAAmB,EAAEC,GAA2B,KAAkB;EACpG,MAAM;IAAEC;EAAW,CAAE,GAAGF,KAAK;EAC7B,MAAMG,gBAAgB,GAAGR,mBAAmB,EAAE;EAC9C,MAAM;IAAES,QAAQ;IAAEC,gBAAgB;IAAEC;EAAY,CAAE,GAAGH,gBAAgB;EAErE,MAAM;IAAEI,cAAc;IAAEC,eAAe;IAAEC;EAAY,CAAE,GAAGZ,YAAY,CAACG,KAAK,CAAC;EAE7E,MAAM,CAACU,YAAY,EAAEC,eAAe,CAAC,GAAGzB,KAAK,CAAC0B,QAAQ,EAA2B;EAEjF;EACA;EACA,MAAM,CAACC,YAAY,EAAEC,eAAe,CAAC,GAAG5B,KAAK,CAAC0B,QAAQ,CAAC,KAAK,CAAC;EAE7D,MAAMG,SAAS,GAAIC,KAAuC,IAAI;IAC5D,MAAMC,MAAM,GAAGxB,wBAAwB,CAACuB,KAAK,EAAE;MAAEE,IAAI,EAAE;IAAI,CAAE,CAAC;IAC9D,M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AAGP,kBAAkB,GAC1C;IACEf,YAAY,EAAEgB,oBAAoB;IAClCb,YAAY,EAAEe,oBAAoB;IAClCpB,eAAe,EAAEqB,uBAAuB;IACxCpB,YAAY,EAAEqB,oBAAoB;IAClCnB,eAAe,EAAEoB;GAClB,GACD;IACErB,YAAY;IACZG,YAAY;IACZL,eAAe;IACfC,YAAY;IACZE;GACD;EAEL,MAAMsB,KAAK,GAAiB;IAC1BC,UAAU,EAAE;MACVC,IAAI,EAAE;KACP;IACDA,IAAI,EAAEhD,qBAAqB,CAAC,KAAK,EAAE;MACjCc,GAAG;MACHmC,IAAI,EAAElC,WAAW,GAAG,MAAM,GAAG,SAAS;MACtC,uBAAuB,EAAEuB,kBAAkB,GAAGY,SAAS,GAAG3B,YAAY,aAAZA,YAAY,uBAAZA,YAAY,CAAEW,EAAE;MAC1E,sBAAsB,EAAEnB,WAAW;MACnCoC,QAAQ,EAAE,CAAC;MACX,GAAGtC;KACJ,CAAC;IACFE,WAAW;IACXK,cAAc;IACd,GAAGJ,gBAAgB;IACnB,GAAG6B;GACJ;EAED,MAAMO,kBAAkB,GAAG3C,wBAAwB,CAACqC,KAAK,CAAC;EAC1DA,KAAK,CAACE,IAAI,CAAClC,GAAG,GAAGX,aAAa,CAAC2C,KAAK,CAACE,IAAI,CAAClC,GAAG,EAAEsC,kBAAkB,CAAC;EAElEN,KAAK,CAACE,IAAI,CAACpB,SAAS,GAAG1B,gBAAgB,CAACD,cAAc,CAAC6C,KAAK,CAACE,IAAI,CAACpB,SAAS,EAAEA,SAAS,CAAC,CAAC;EACxFkB,KAAK,CAACE,IAAI,CAACX,WAAW,GAAGnC,gBAAgB,CAACD,cAAc,CAAC6C,KAAK,CAACE,IAAI,CAACX,WAAW,EAAEA,WAAW,CAAC,CAAC;EAE9F,OAAOS,KAAK;AACd,CAAC","names":["React","getNativeElementProps","mergeCallbacks","useEventCallback","useMergedRefs","useContextSelector","useHasParentContext","getDropdownActionFromKey","getIndexFromAction","useOptionCollection","useScrollOptionsIntoView","useSelection","ComboboxContext","useListbox_unstable","props","ref","multiselect","optionCollection","getCount","getOptionAtIndex","getIndexOfId","clearSelection","selectedOptions","selectOption","activeOption","setActiveOption","useState","focusVisible","setFocusVisible","onKeyDown","event","action","open","maxIndex","activeIndex","id","newIndex","preventDefault","onMouseOver","hasComboboxContext","comboboxActiveOption","ctx","comboboxFocusVisible","comboboxSelectedOptions","comboboxSelectOption","comboboxSetActiveOption","optionContextValues","state","components","root","role","undefined","tabIndex","scrollContainerRef"],"sourceRoot":"../src/","sources":["packages/react-components/react-combobox/src/components/Listbox/useListbox.ts"],"sourcesContent":["import * as React from 'react';\nimport { getNativeElementProps, mergeCallbacks, useEventCallback, useMergedRefs } from '@fluentui/react-utilities';\nimport { useContextSelector, useHasParentContext } from '@fluentui/react-context-selector';\nimport { getDropdownActionFromKey, getIndexFromAction } from '../../utils/dropdownKeyActions';\nimport type { OptionValue } from '../../utils/OptionCollection.types';\nimport { useOptionCollection } from '../../utils/useOptionCollection';\nimport { useScrollOptionsIntoView } from '../../utils/useScrollOptionsIntoView';\nimport { useSelection } from '../../utils/useSelection';\nimport { ComboboxContext } from '../../contexts/ComboboxContext';\nimport type { ListboxProps, ListboxState } from './Listbox.types';\n\n/**\n * Create the state required to render Listbox.\n *\n * The returned state can be modified with hooks such as useListboxStyles_unstable,\n * before being passed to renderListbox_unstable.\n *\n * @param props - props from this instance of Listbox\n * @param ref - reference to root HTMLElement of Listbox\n */\nexport const useListbox_unstable = (props: ListboxProps, ref: React.Ref<HTMLElement>): ListboxState => {\n const { multiselect } = props;\n const optionCollection = useOptionCollection();\n const { getCount, getOptionAtIndex, getIndexOfId } = optionCollection;\n\n const { clearSelection, selectedOptions, selectOption } = useSelection(props);\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 const onKeyDown = (event: React.KeyboardEvent<HTMLElement>) => {\n const action = getDropdownActionFromKey(event, { open: true });\n const maxIndex = getCount() - 1;\n const activeIndex = activeOption ? getIndexOfId(activeOption.id) : -1;\n let newIndex = activeIndex;\n\n switch (action) {\n case 'Select':\n case 'CloseSelect':\n activeOption && selectOption(event, activeOption);\n break;\n default:\n newIndex = getIndexFromAction(action, activeIndex, maxIndex);\n }\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\n const onMouseOver = (event: React.MouseEvent<HTMLElement>) => {\n setFocusVisible(false);\n };\n\n // get state from parent combobox, if it exists\n const hasComboboxContext = useHasParentContext(ComboboxContext);\n const comboboxActiveOption = useContextSelector(ComboboxContext, ctx => ctx.activeOption);\n const comboboxFocusVisible = useContextSelector(ComboboxContext, ctx => ctx.focusVisible);\n const comboboxSelectedOptions = useContextSelector(ComboboxContext, ctx => ctx.selectedOptions);\n const comboboxSelectOption = useContextSelector(ComboboxContext, ctx => ctx.selectOption);\n const comboboxSetActiveOption = useContextSelector(ComboboxContext, ctx => ctx.setActiveOption);\n\n // without a parent combobox context, provide values directly from Listbox\n const optionContextValues = hasComboboxContext\n ? {\n activeOption: comboboxActiveOption,\n focusVisible: comboboxFocusVisible,\n selectedOptions: comboboxSelectedOptions,\n selectOption: comboboxSelectOption,\n setActiveOption: comboboxSetActiveOption,\n }\n : {\n activeOption,\n focusVisible,\n selectedOptions,\n selectOption,\n setActiveOption,\n };\n\n const state: ListboxState = {\n components: {\n root: 'div',\n },\n root: getNativeElementProps('div', {\n ref,\n role: multiselect ? 'menu' : 'listbox',\n 'aria-activedescendant': hasComboboxContext ? undefined : activeOption?.id,\n 'aria-multiselectable': multiselect,\n tabIndex: 0,\n ...props,\n }),\n multiselect,\n clearSelection,\n ...optionCollection,\n ...optionContextValues,\n };\n\n const scrollContainerRef = useScrollOptionsIntoView(state);\n state.root.ref = useMergedRefs(state.root.ref, scrollContainerRef);\n\n state.root.onKeyDown = useEventCallback(mergeCallbacks(state.root.onKeyDown, onKeyDown));\n state.root.onMouseOver = useEventCallback(mergeCallbacks(state.root.onMouseOver, onMouseOver));\n\n return state;\n};\n"]}
@@ -6,33 +6,29 @@ export const listboxClassNames = {
6
6
  /**
7
7
  * Styles for the root slot
8
8
  */
9
-
10
9
  const useStyles = /*#__PURE__*/__styles({
11
- "root": {
12
- "E5pizo": "f1hg901r",
13
- "B7ck84d": "f1ewtqcl",
14
- "Bbmb7ep": ["f1aa9q02", "f16jpd5f"],
15
- "Beyfa6y": ["f16jpd5f", "f1aa9q02"],
16
- "B7oj6ja": ["f1jar5jt", "fyu767a"],
17
- "Btl43ni": ["fyu767a", "f1jar5jt"],
18
- "De3pzq": "fxugw4r",
19
- "mc9l5x": "f22iagw",
20
- "Beiy3e4": "f1vx9l62",
21
- "Bf4jedk": "f3hsy1e",
22
- "z8tnut": "f1x4af0m",
23
- "z189sj": ["f7x41pl", "fruq291"],
24
- "Byoj8tv": "fd55psn",
25
- "uwmqm3": ["fruq291", "f7x41pl"],
26
- "Belr9w4": "fiut8dr"
10
+ root: {
11
+ De3pzq: "fxugw4r",
12
+ B7ck84d: "f1ewtqcl",
13
+ mc9l5x: "f22iagw",
14
+ Beiy3e4: "f1vx9l62",
15
+ Bf4jedk: "f3hsy1e",
16
+ Bmxbyg5: "f5zp4f",
17
+ Bpd4iqm: "fpvhumw",
18
+ oeaueh: "f1yog68k",
19
+ Bw0xxkn: "f13sgyd8",
20
+ z8tnut: "f1x4af0m",
21
+ z189sj: ["f7x41pl", "fruq291"],
22
+ Byoj8tv: "fd55psn",
23
+ uwmqm3: ["fruq291", "f7x41pl"],
24
+ Belr9w4: "fiut8dr"
27
25
  }
28
26
  }, {
29
- "d": [".f1hg901r{box-shadow:var(--shadow16);}", ".f1ewtqcl{box-sizing:border-box;}", ".f1aa9q02{border-bottom-right-radius:var(--borderRadiusMedium);}", ".f16jpd5f{border-bottom-left-radius:var(--borderRadiusMedium);}", ".f1jar5jt{border-top-right-radius:var(--borderRadiusMedium);}", ".fyu767a{border-top-left-radius:var(--borderRadiusMedium);}", ".fxugw4r{background-color:var(--colorNeutralBackground1);}", ".f22iagw{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;}", ".f1vx9l62{-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;}", ".f3hsy1e{min-width:160px;}", ".f1x4af0m{padding-top:var(--spacingHorizontalXS);}", ".f7x41pl{padding-right:var(--spacingHorizontalXS);}", ".fruq291{padding-left:var(--spacingHorizontalXS);}", ".fd55psn{padding-bottom:var(--spacingHorizontalXS);}", ".fiut8dr{row-gap:var(--spacingHorizontalXXS);}"]
27
+ d: [".fxugw4r{background-color:var(--colorNeutralBackground1);}", ".f1ewtqcl{box-sizing:border-box;}", ".f22iagw{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;}", ".f1vx9l62{-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;}", ".f3hsy1e{min-width:160px;}", ".f5zp4f{overflow-y:auto;}", ".fpvhumw{outline-width:1px;}", ".f1yog68k{outline-style:solid;}", ".f13sgyd8{outline-color:var(--colorTransparentStroke);}", ".f1x4af0m{padding-top:var(--spacingHorizontalXS);}", ".f7x41pl{padding-right:var(--spacingHorizontalXS);}", ".fruq291{padding-left:var(--spacingHorizontalXS);}", ".fd55psn{padding-bottom:var(--spacingHorizontalXS);}", ".fiut8dr{row-gap:var(--spacingHorizontalXXS);}"]
30
28
  });
31
29
  /**
32
30
  * Apply styling to the Listbox slots based on the state
33
31
  */
34
-
35
-
36
32
  export const useListboxStyles_unstable = state => {
37
33
  const styles = useStyles();
38
34
  state.root.className = mergeClasses(listboxClassNames.root, styles.root, state.root.className);
@@ -1 +1 @@
1
- {"version":3,"sources":["components/Listbox/useListboxStyles.ts"],"names":[],"mappings":"AAAA,SAAS,MAAT,QAAuB,uBAAvB;AAEA,mBAAqB,YAArB,EAAmC,UAAnC,QAAqD,gBAArD;AAGA,OAAO,MAAM,iBAAiB,GAAiC;EAC7D,IAAI,EAAE;AADuD,CAAxD;AAIP;;AAEG;;AACH,MAAM,SAAS,gBAAG;EAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;EAAA;AAAA;EAAA;AAAA,EAAlB;AAcA;;AAEG;;;AACH,OAAO,MAAM,yBAAyB,GAAI,KAAD,IAAsC;EAC7E,MAAM,MAAM,GAAG,SAAS,EAAxB;EACA,KAAK,CAAC,IAAN,CAAW,SAAX,GAAuB,YAAY,CAAC,iBAAiB,CAAC,IAAnB,EAAyB,MAAM,CAAC,IAAhC,EAAsC,KAAK,CAAC,IAAN,CAAW,SAAjD,CAAnC;EAEA,OAAO,KAAP;AACD,CALM","sourcesContent":["import { tokens } from '@fluentui/react-theme';\nimport { SlotClassNames } from '@fluentui/react-utilities';\nimport { makeStyles, mergeClasses, shorthands } from '@griffel/react';\nimport type { ListboxSlots, ListboxState } from './Listbox.types';\n\nexport const listboxClassNames: SlotClassNames<ListboxSlots> = {\n root: 'fui-Listbox',\n};\n\n/**\n * Styles for the root slot\n */\nconst useStyles = makeStyles({\n root: {\n boxShadow: `${tokens.shadow16}`,\n boxSizing: 'border-box',\n ...shorthands.borderRadius(tokens.borderRadiusMedium),\n backgroundColor: tokens.colorNeutralBackground1,\n display: 'flex',\n flexDirection: 'column',\n minWidth: '160px',\n ...shorthands.padding(tokens.spacingHorizontalXS),\n rowGap: tokens.spacingHorizontalXXS,\n },\n});\n\n/**\n * Apply styling to the Listbox slots based on the state\n */\nexport const useListboxStyles_unstable = (state: ListboxState): ListboxState => {\n const styles = useStyles();\n state.root.className = mergeClasses(listboxClassNames.root, styles.root, state.root.className);\n\n return state;\n};\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"mappings":"AAAA,SAASA,MAAM,QAAQ,uBAAuB;AAE9C,mBAAqBC,YAAY,EAAEC,UAAU,QAAQ,gBAAgB;AAGrE,OAAO,MAAMC,iBAAiB,GAAiC;EAC7DC,IAAI,EAAE;CACP;AAED;;;AAGA,MAAMC,SAAS,gBAAG;EAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;EAAA;AAAA;EAAA;AAAA,EAYhB;AAEF;;;AAGA,OAAO,MAAMC,yBAAyB,GAAIC,KAAmB,IAAkB;EAC7E,MAAMC,MAAM,GAAGH,SAAS,EAAE;EAC1BE,KAAK,CAACH,IAAI,CAACK,SAAS,GAAGR,YAAY,CAACE,iBAAiB,CAACC,IAAI,EAAEI,MAAM,CAACJ,IAAI,EAAEG,KAAK,CAACH,IAAI,CAACK,SAAS,CAAC;EAE9F,OAAOF,KAAK;AACd,CAAC","names":["tokens","mergeClasses","shorthands","listboxClassNames","root","useStyles","useListboxStyles_unstable","state","styles","className"],"sourceRoot":"../src/","sources":["packages/react-components/react-combobox/src/components/Listbox/useListboxStyles.ts"],"sourcesContent":["import { tokens } from '@fluentui/react-theme';\nimport { SlotClassNames } from '@fluentui/react-utilities';\nimport { makeStyles, mergeClasses, shorthands } from '@griffel/react';\nimport type { ListboxSlots, ListboxState } from './Listbox.types';\n\nexport const listboxClassNames: SlotClassNames<ListboxSlots> = {\n root: 'fui-Listbox',\n};\n\n/**\n * Styles for the root slot\n */\nconst useStyles = makeStyles({\n root: {\n backgroundColor: tokens.colorNeutralBackground1,\n boxSizing: 'border-box',\n display: 'flex',\n flexDirection: 'column',\n minWidth: '160px',\n overflowY: 'auto',\n ...shorthands.outline('1px', 'solid', tokens.colorTransparentStroke),\n ...shorthands.padding(tokens.spacingHorizontalXS),\n rowGap: tokens.spacingHorizontalXXS,\n },\n});\n\n/**\n * Apply styling to the Listbox slots based on the state\n */\nexport const useListboxStyles_unstable = (state: ListboxState): ListboxState => {\n const styles = useStyles();\n state.root.className = mergeClasses(listboxClassNames.root, styles.root, state.root.className);\n\n return state;\n};\n"]}
@@ -5,7 +5,6 @@ import { useOptionStyles_unstable } from './useOptionStyles';
5
5
  /**
6
6
  * Option component: a styled child option of a Combobox
7
7
  */
8
-
9
8
  export const Option = /*#__PURE__*/React.forwardRef((props, ref) => {
10
9
  const state = useOption_unstable(props, ref);
11
10
  useOptionStyles_unstable(state);
@@ -1 +1 @@
1
- {"version":3,"sources":["components/Option/Option.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,kBAAT,QAAmC,aAAnC;AACA,SAAS,qBAAT,QAAsC,gBAAtC;AACA,SAAS,wBAAT,QAAyC,mBAAzC;AAIA;;AAEG;;AACH,OAAO,MAAM,MAAM,gBAAqC,KAAK,CAAC,UAAN,CAAiB,CAAC,KAAD,EAAQ,GAAR,KAAe;EACtF,MAAM,KAAK,GAAG,kBAAkB,CAAC,KAAD,EAAQ,GAAR,CAAhC;EAEA,wBAAwB,CAAC,KAAD,CAAxB;EACA,OAAO,qBAAqB,CAAC,KAAD,CAA5B;AACD,CALuD,CAAjD;AAOP,MAAM,CAAC,WAAP,GAAqB,QAArB","sourcesContent":["import * as React from 'react';\nimport { useOption_unstable } from './useOption';\nimport { renderOption_unstable } from './renderOption';\nimport { useOptionStyles_unstable } from './useOptionStyles';\nimport type { OptionProps } from './Option.types';\nimport type { ForwardRefComponent } from '@fluentui/react-utilities';\n\n/**\n * Option component: a styled child option of a Combobox\n */\nexport const Option: ForwardRefComponent<OptionProps> = React.forwardRef((props, ref) => {\n const state = useOption_unstable(props, ref);\n\n useOptionStyles_unstable(state);\n return renderOption_unstable(state);\n});\n\nOption.displayName = 'Option';\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SAASC,kBAAkB,QAAQ,aAAa;AAChD,SAASC,qBAAqB,QAAQ,gBAAgB;AACtD,SAASC,wBAAwB,QAAQ,mBAAmB;AAI5D;;;AAGA,OAAO,MAAMC,MAAM,gBAAqCJ,KAAK,CAACK,UAAU,CAAC,CAACC,KAAK,EAAEC,GAAG,KAAI;EACtF,MAAMC,KAAK,GAAGP,kBAAkB,CAACK,KAAK,EAAEC,GAAG,CAAC;EAE5CJ,wBAAwB,CAACK,KAAK,CAAC;EAC/B,OAAON,qBAAqB,CAACM,KAAK,CAAC;AACrC,CAAC,CAAC;AAEFJ,MAAM,CAACK,WAAW,GAAG,QAAQ","names":["React","useOption_unstable","renderOption_unstable","useOptionStyles_unstable","Option","forwardRef","props","ref","state","displayName"],"sourceRoot":"../src/","sources":["packages/react-components/react-combobox/src/components/Option/Option.tsx"],"sourcesContent":["import * as React from 'react';\nimport { useOption_unstable } from './useOption';\nimport { renderOption_unstable } from './renderOption';\nimport { useOptionStyles_unstable } from './useOptionStyles';\nimport type { OptionProps } from './Option.types';\nimport type { ForwardRefComponent } from '@fluentui/react-utilities';\n\n/**\n * Option component: a styled child option of a Combobox\n */\nexport const Option: ForwardRefComponent<OptionProps> = React.forwardRef((props, ref) => {\n const state = useOption_unstable(props, ref);\n\n useOptionStyles_unstable(state);\n return renderOption_unstable(state);\n});\n\nOption.displayName = 'Option';\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"Option.types.js","sourceRoot":"../src/","sources":["components/Option/Option.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';\n\nexport type OptionSlots = {\n /* The root option slot, with role=\"option\" */\n root: NonNullable<Slot<'div'>>;\n\n /* The check icon that is visible for selected options */\n checkIcon: Slot<'span'>;\n};\n\n/**\n * Option Props\n */\nexport type OptionProps = ComponentProps<Partial<OptionSlots>> & {\n /**\n * Sets an option to the `disabled` state.\n * Disabled options cannot be selected, but are still keyboard navigable\n */\n disabled?: boolean;\n\n /*\n * Defines a string value for the option, used for the parent Combobox's value.\n * Use this if the children are not a string, or you wish the value to differ from the displayed text.\n */\n value?: string;\n};\n\n/**\n * State used in rendering Option\n */\nexport type OptionState = ComponentState<OptionSlots> &\n Pick<OptionProps, 'disabled'> & {\n /* If true, this is the currently highlighted option */\n active: boolean;\n\n /* If true, the option is part of a multiselect combobox or listbox */\n multiselect?: boolean;\n\n /* If true, the option is selected */\n selected: boolean;\n };\n"]}
1
+ {"version":3,"file":"Option.types.js","sourceRoot":"../src/","sources":["packages/react-components/react-combobox/src/components/Option/Option.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';\nimport * as React from 'react';\n\nexport type OptionSlots = {\n /* The root option slot, with role=\"option\" */\n root: NonNullable<Slot<'div'>>;\n\n /* The check icon that is visible for selected options */\n checkIcon: Slot<'span'>;\n};\n\n/**\n * Option Props\n */\nexport type OptionProps = ComponentProps<Partial<OptionSlots>> & {\n /**\n * Sets an option to the `disabled` state.\n * Disabled options cannot be selected, but are still keyboard navigable\n */\n disabled?: boolean;\n\n /*\n * Defines a unique identifier for the option.\n * Use this to control selectedOptions, or to get the option value in the onOptionSelect callback.\n * Defaults to `text` if not provided.\n */\n value?: string;\n} & (\n | {\n /**\n * An optional override the string value of the Option's display text,\n * defaulting to the Option's child content.\n * This is used as the Dropdown button's or Combobox input's value when the option is selected,\n * and as the comparison for type-to-find keyboard functionality.\n */\n text?: string;\n children: string;\n }\n | {\n /**\n * The string value of the Option's display text when the Option's children are not a string.\n * This is used as the Dropdown button's or Combobox input's value when the option is selected,\n * and as the comparison for type-to-find keyboard functionality.\n */\n text: string;\n children?: React.ReactNode;\n }\n );\n\n/**\n * State used in rendering Option\n */\nexport type OptionState = ComponentState<OptionSlots> &\n Pick<OptionProps, 'disabled'> & {\n /* If true, this is the currently highlighted option */\n active: boolean;\n\n // Whether the keyboard focus outline style should be visible\n focusVisible: boolean;\n\n /* If true, the option is part of a multiselect combobox or listbox */\n multiselect?: boolean;\n\n /* If true, the option is selected */\n selected: boolean;\n };\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"../src/","sources":["components/Option/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC","sourcesContent":["export * from './Option';\nexport * from './Option.types';\nexport * from './renderOption';\nexport * from './useOption';\nexport * from './useOptionStyles';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"../src/","sources":["packages/react-components/react-combobox/src/components/Option/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC","sourcesContent":["export * from './Option';\nexport * from './Option.types';\nexport * from './renderOption';\nexport * from './useOption';\nexport * from './useOptionStyles';\n"]}
@@ -3,14 +3,15 @@ import { getSlots } from '@fluentui/react-utilities';
3
3
  /**
4
4
  * Render the final JSX of Option
5
5
  */
6
-
7
6
  export const renderOption_unstable = state => {
8
7
  const {
9
8
  slots,
10
9
  slotProps
11
10
  } = getSlots(state);
12
- return /*#__PURE__*/React.createElement(slots.root, { ...slotProps.root
13
- }, /*#__PURE__*/React.createElement(slots.checkIcon, { ...slotProps.checkIcon
11
+ return /*#__PURE__*/React.createElement(slots.root, {
12
+ ...slotProps.root
13
+ }, /*#__PURE__*/React.createElement(slots.checkIcon, {
14
+ ...slotProps.checkIcon
14
15
  }), slotProps.root.children);
15
16
  };
16
17
  //# sourceMappingURL=renderOption.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["components/Option/renderOption.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,QAAT,QAAyB,2BAAzB;AAGA;;AAEG;;AACH,OAAO,MAAM,qBAAqB,GAAI,KAAD,IAAuB;EAC1D,MAAM;IAAE,KAAF;IAAS;EAAT,IAAuB,QAAQ,CAAc,KAAd,CAArC;EAEA,oBACE,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,IAAP,EAAW,EAAA,GAAK,SAAS,CAAC;EAAf,CAAX,eACE,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,SAAP,EAAgB,EAAA,GAAK,SAAS,CAAC;EAAf,CAAhB,CADF,EAEG,SAAS,CAAC,IAAV,CAAe,QAFlB,CADF;AAMD,CATM","sourcesContent":["import * as React from 'react';\nimport { getSlots } from '@fluentui/react-utilities';\nimport type { OptionState, OptionSlots } from './Option.types';\n\n/**\n * Render the final JSX of Option\n */\nexport const renderOption_unstable = (state: OptionState) => {\n const { slots, slotProps } = getSlots<OptionSlots>(state);\n\n return (\n <slots.root {...slotProps.root}>\n <slots.checkIcon {...slotProps.checkIcon} />\n {slotProps.root.children}\n </slots.root>\n );\n};\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SAASC,QAAQ,QAAQ,2BAA2B;AAGpD;;;AAGA,OAAO,MAAMC,qBAAqB,GAAIC,KAAkB,IAAI;EAC1D,MAAM;IAAEC,KAAK;IAAEC;EAAS,CAAE,GAAGJ,QAAQ,CAAcE,KAAK,CAAC;EAEzD,oBACEH,oBAACI,KAAK,CAACE,IAAI;IAAA,GAAKD,SAAS,CAACC;EAAI,gBAC5BN,oBAACI,KAAK,CAACG,SAAS;IAAA,GAAKF,SAAS,CAACE;EAAS,EAAI,EAC3CF,SAAS,CAACC,IAAI,CAACE,QAAQ,CACb;AAEjB,CAAC","names":["React","getSlots","renderOption_unstable","state","slots","slotProps","root","checkIcon","children"],"sourceRoot":"../src/","sources":["packages/react-components/react-combobox/src/components/Option/renderOption.tsx"],"sourcesContent":["import * as React from 'react';\nimport { getSlots } from '@fluentui/react-utilities';\nimport type { OptionState, OptionSlots } from './Option.types';\n\n/**\n * Render the final JSX of Option\n */\nexport const renderOption_unstable = (state: OptionState) => {\n const { slots, slotProps } = getSlots<OptionSlots>(state);\n\n return (\n <slots.root {...slotProps.root}>\n <slots.checkIcon {...slotProps.checkIcon} />\n {slotProps.root.children}\n </slots.root>\n );\n};\n"]}
@@ -1,21 +1,28 @@
1
1
  import * as React from 'react';
2
2
  import { getNativeElementProps, resolveShorthand, useId, useMergedRefs } from '@fluentui/react-utilities';
3
3
  import { useContextSelector } from '@fluentui/react-context-selector';
4
- import { CheckmarkFilled, CheckboxUncheckedFilled, CheckboxCheckedFilled } from '@fluentui/react-icons';
5
- import { ListboxContext } from '../../contexts/ListboxContext'; // TODO: refine this more
6
-
7
- function getValueString(value, children) {
8
- if (value) {
9
- return value;
4
+ import { CheckmarkFilled, Checkmark12Filled } from '@fluentui/react-icons';
5
+ import { ComboboxContext } from '../../contexts/ComboboxContext';
6
+ import { ListboxContext } from '../../contexts/ListboxContext';
7
+ function getTextString(text, children) {
8
+ if (text !== undefined) {
9
+ return text;
10
10
  }
11
-
12
- let valueString = '';
11
+ let textString = '';
12
+ let hasNonStringChild = false;
13
13
  React.Children.forEach(children, child => {
14
14
  if (typeof child === 'string') {
15
- valueString += child;
15
+ textString += child;
16
+ } else {
17
+ hasNonStringChild = true;
16
18
  }
17
19
  });
18
- return valueString;
20
+ // warn if an Option has non-string children and no text prop
21
+ if (hasNonStringChild) {
22
+ // eslint-disable-next-line no-console
23
+ console.warn('Provide a `text` prop to Option components when they contain non-string children.');
24
+ }
25
+ return textString;
19
26
  }
20
27
  /**
21
28
  * Create the state required to render Option.
@@ -26,67 +33,75 @@ function getValueString(value, children) {
26
33
  * @param props - props from this instance of Option
27
34
  * @param ref - reference to root HTMLElement of Option
28
35
  */
29
-
30
-
31
36
  export const useOption_unstable = (props, ref) => {
32
37
  const {
38
+ children,
33
39
  disabled,
40
+ text,
34
41
  value
35
42
  } = props;
36
43
  const optionRef = React.useRef(null);
37
- const optionValue = getValueString(value, props.children); // context values
38
-
44
+ const optionText = getTextString(text, children);
45
+ const optionValue = value !== null && value !== void 0 ? value : optionText;
46
+ // use the id if provided, otherwise use a generated id
47
+ const id = useId('fluent-option', props.id);
48
+ // data used for context registration & events
49
+ const optionData = React.useMemo(() => ({
50
+ id,
51
+ disabled,
52
+ text: optionText,
53
+ value: optionValue
54
+ }), [id, disabled, optionText, optionValue]);
55
+ // context values
56
+ const focusVisible = useContextSelector(ListboxContext, ctx => ctx.focusVisible);
39
57
  const multiselect = useContextSelector(ListboxContext, ctx => ctx.multiselect);
40
- const onOptionClick = useContextSelector(ListboxContext, ctx => ctx.onOptionClick);
41
58
  const registerOption = useContextSelector(ListboxContext, ctx => ctx.registerOption);
42
59
  const selected = useContextSelector(ListboxContext, ctx => {
43
60
  const selectedOptions = ctx.selectedOptions;
44
61
  return !!optionValue && !!selectedOptions.find(o => o === optionValue);
45
- }); // use the id if provided, otherwise use a generated id
46
-
47
- const defaultId = useId('fluent-option');
48
- const id = React.useMemo(() => {
49
- return props.id || defaultId;
50
- }, [props.id, defaultId]); // current active option?
51
-
62
+ });
63
+ const selectOption = useContextSelector(ListboxContext, ctx => ctx.selectOption);
64
+ const setActiveOption = useContextSelector(ListboxContext, ctx => ctx.setActiveOption);
65
+ const setOpen = useContextSelector(ComboboxContext, ctx => ctx.setOpen);
66
+ // current active option?
52
67
  const active = useContextSelector(ListboxContext, ctx => {
53
68
  var _a, _b;
54
-
55
69
  return ((_a = ctx.activeOption) === null || _a === void 0 ? void 0 : _a.id) !== undefined && ((_b = ctx.activeOption) === null || _b === void 0 ? void 0 : _b.id) === id;
56
- }); // check icon
57
-
70
+ });
71
+ // check icon
58
72
  let CheckIcon = /*#__PURE__*/React.createElement(CheckmarkFilled, null);
59
-
60
73
  if (multiselect) {
61
- CheckIcon = selected ? /*#__PURE__*/React.createElement(CheckboxCheckedFilled, null) : /*#__PURE__*/React.createElement(CheckboxUncheckedFilled, null);
74
+ CheckIcon = selected ? /*#__PURE__*/React.createElement(Checkmark12Filled, null) : '';
62
75
  }
63
-
64
76
  const onClick = event => {
65
77
  var _a;
66
-
67
78
  if (disabled) {
68
79
  event.preventDefault();
69
80
  return;
70
81
  }
71
-
72
- onOptionClick(event, {
73
- id,
74
- disabled,
75
- value: optionValue
76
- });
82
+ // clicked option should always become active option
83
+ setActiveOption(optionData);
84
+ // close on option click for single-select options in a combobox
85
+ if (!multiselect) {
86
+ setOpen === null || setOpen === void 0 ? void 0 : setOpen(event, false);
87
+ }
88
+ // handle selection change
89
+ selectOption(event, optionData);
77
90
  (_a = props.onClick) === null || _a === void 0 ? void 0 : _a.call(props, event);
78
- }; // register option data with context
79
-
80
-
91
+ };
92
+ // register option data with context
81
93
  React.useEffect(() => {
82
94
  if (id && optionRef.current) {
83
- return registerOption({
84
- id,
85
- disabled,
86
- value: optionValue
87
- }, optionRef.current);
95
+ return registerOption(optionData, optionRef.current);
88
96
  }
89
- }, [registerOption, id, disabled, optionValue]);
97
+ }, [id, optionData, registerOption]);
98
+ const semanticProps = multiselect ? {
99
+ role: 'menuitemcheckbox',
100
+ 'aria-checked': selected
101
+ } : {
102
+ role: 'option',
103
+ 'aria-selected': selected
104
+ };
90
105
  return {
91
106
  components: {
92
107
  root: 'div',
@@ -94,10 +109,9 @@ export const useOption_unstable = (props, ref) => {
94
109
  },
95
110
  root: getNativeElementProps('div', {
96
111
  ref: useMergedRefs(ref, optionRef),
97
- role: 'option',
98
112
  'aria-disabled': disabled ? 'true' : undefined,
99
- 'aria-selected': `${selected}`,
100
113
  id,
114
+ ...semanticProps,
101
115
  ...props,
102
116
  onClick
103
117
  }),
@@ -110,6 +124,7 @@ export const useOption_unstable = (props, ref) => {
110
124
  }),
111
125
  active,
112
126
  disabled,
127
+ focusVisible,
113
128
  multiselect,
114
129
  selected
115
130
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["components/Option/useOption.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,qBAAT,EAAgC,gBAAhC,EAAkD,KAAlD,EAAyD,aAAzD,QAA8E,2BAA9E;AACA,SAAS,kBAA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A,CAAb,KAAa,EAAG,KAAH,CAAb;EACD,CARD,CAhCiG,CA0CjG;;;EACA,KAAK,CAAC,SAAN,CAAgB,MAAK;IACnB,IAAI,EAAE,IAAI,SAAS,CAAC,OAApB,EAA6B;MAC3B,OAAO,cAAc,CAAC;QAAE,EAAF;QAAM,QAAN;QAAgB,KAAK,EAAE;MAAvB,CAAD,EAAuC,SAAS,CAAC,OAAjD,CAArB;IACD;EACF,CAJD,EAIG,CAAC,cAAD,EAAiB,EAAjB,EAAqB,QAArB,EAA+B,WAA/B,CAJH;EAMA,OAAO;IACL,UAAU,EAAE;MACV,IAAI,EAAE,KADI;MAEV,SAAS,EAAE;IAFD,CADP;IAKL,IAAI,EAAE,qBAAqB,CAAC,KAAD,EAAQ;MACjC,GAAG,EAAE,aAAa,CAAC,GAAD,EAAM,SAAN,CADe;MAEjC,IAAI,EAAE,QAF2B;MAGjC,iBAAiB,QAAQ,GAAG,MAAH,GAAY,SAHJ;MAIjC,iBAAiB,GAAG,QAAQ,EAJK;MAKjC,EALiC;MAMjC,GAAG,KAN8B;MAOjC;IAPiC,CAAR,CALtB;IAcL,SAAS,EAAE,gBAAgB,CAAC,KAAK,CAAC,SAAP,EAAkB;MAC3C,QAAQ,EAAE,IADiC;MAE3C,YAAY,EAAE;QACZ,eAAe,MADH;QAEZ,QAAQ,EAAE;MAFE;IAF6B,CAAlB,CAdtB;IAqBL,MArBK;IAsBL,QAtBK;IAuBL,WAvBK;IAwBL;EAxBK,CAAP;AA0BD,CA3EM","sourcesContent":["import * as React from 'react';\nimport { getNativeElementProps, resolveShorthand, useId, useMergedRefs } from '@fluentui/react-utilities';\nimport { useContextSelector } from '@fluentui/react-context-selector';\nimport { CheckmarkFilled, CheckboxUncheckedFilled, CheckboxCheckedFilled } from '@fluentui/react-icons';\nimport { ListboxContext } from '../../contexts/ListboxContext';\nimport type { OptionProps, OptionState } from './Option.types';\n\n// TODO: refine this more\nfunction getValueString(value: string | undefined, children: React.ReactNode) {\n if (value) {\n return value;\n }\n\n let valueString = '';\n React.Children.forEach(children, child => {\n if (typeof child === 'string') {\n valueString += child;\n }\n });\n return valueString;\n}\n\n/**\n * Create the state required to render Option.\n *\n * The returned state can be modified with hooks such as useOptionStyles_unstable,\n * before being passed to renderOption_unstable.\n *\n * @param props - props from this instance of Option\n * @param ref - reference to root HTMLElement of Option\n */\nexport const useOption_unstable = (props: OptionProps, ref: React.Ref<HTMLElement>): OptionState => {\n const { disabled, value } = props;\n const optionRef = React.useRef<HTMLElement>(null);\n const optionValue = getValueString(value, props.children);\n\n // context values\n const multiselect = useContextSelector(ListboxContext, ctx => ctx.multiselect);\n const onOptionClick = useContextSelector(ListboxContext, ctx => ctx.onOptionClick);\n const registerOption = useContextSelector(ListboxContext, ctx => ctx.registerOption);\n const selected = useContextSelector(ListboxContext, ctx => {\n const selectedOptions = ctx.selectedOptions;\n\n return !!optionValue && !!selectedOptions.find(o => o === optionValue);\n });\n\n // use the id if provided, otherwise use a generated id\n const defaultId = useId('fluent-option');\n const id = React.useMemo(() => {\n return props.id || defaultId;\n }, [props.id, defaultId]);\n\n // current active option?\n const active = useContextSelector(ListboxContext, ctx => {\n return ctx.activeOption?.id !== undefined && ctx.activeOption?.id === id;\n });\n\n // check icon\n let CheckIcon = <CheckmarkFilled />;\n if (multiselect) {\n CheckIcon = selected ? <CheckboxCheckedFilled /> : <CheckboxUncheckedFilled />;\n }\n\n const onClick = (event: React.MouseEvent<HTMLDivElement>) => {\n if (disabled) {\n event.preventDefault();\n return;\n }\n\n onOptionClick(event, { id, disabled, value: optionValue });\n props.onClick?.(event);\n };\n\n // register option data with context\n React.useEffect(() => {\n if (id && optionRef.current) {\n return registerOption({ id, disabled, value: optionValue }, optionRef.current);\n }\n }, [registerOption, id, disabled, optionValue]);\n\n return {\n components: {\n root: 'div',\n checkIcon: 'span',\n },\n root: getNativeElementProps('div', {\n ref: useMergedRefs(ref, optionRef),\n role: 'option',\n 'aria-disabled': disabled ? 'true' : undefined,\n 'aria-selected': `${selected}`,\n id,\n ...props,\n onClick,\n }),\n checkIcon: resolveShorthand(props.checkIcon, {\n required: true,\n defaultProps: {\n 'aria-hidden': 'true',\n children: CheckIcon,\n },\n }),\n active,\n disabled,\n multiselect,\n selected,\n };\n};\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SAASC,qBAAqB,EAAEC,gBAAgB,EAAEC,KAAK,EAAEC,aAAa,QAAQ,2BAA2B;AACzG,SAASC,kBAAkB,QAAQ,kCAAkC;AACrE,SAASC,eAAe,EAAEC,iBAAiB,QAAQ,uBAAuB;AAC1E,SAASC,eAAe,QAAQ,gCAAgC;AAChE,SAASC,cAAc,QAAQ,+BAA+B;AAI9D,SAASC,aAAa,CAACC,IAAwB,EAAEC,QAAyB;EACxE,IAAID,IAAI,KAAKE,SAAS,EAAE;IACtB,OAAOF,IAAI;;EAGb,IAAIG,UAAU,GAAG,EAAE;EACnB,IAAIC,iBAAiB,GAAG,KAAK;EAC7Bf,KAAK,CAACgB,QAAQ,CAACC,OAAO,CAACL,QAAQ,EAAEM,KAAK,IAAG;IACvC,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE;MAC7BJ,UAAU,IAAII,KAAK;KACpB,MAAM;MACLH,iBAAiB,GAAG,IAAI;;EAE5B,CAAC,CAAC;EAEF;EACA,IAAIA,iBAAiB,EAAE;IACrB;IACAI,OAAO,CAACC,IAAI,CAAC,mFAAmF,CAAC;;EAGnG,OAAON,UAAU;AACnB;AAEA;;;;;;;;;AASA,OAAO,MAAMO,kBAAkB,GAAG,CAACC,KAAkB,EAAEC,GAA2B,KAAiB;EACjG,MAAM;IAAEX,QAAQ;IAAEY,QAAQ;IAAEb,IAAI;IAAEc;EAAK,CAAE,GAAGH,KAAK;EACjD,MAAMI,SAAS,GAAG1B,KAAK,CAAC2B,MAAM,CAAc,IAAI,CAAC;EACjD,MAAMC,UAAU,GAAGlB,aAAa,CAACC,IAA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EAAEtD,qBAAqB,CAAC,KAAK,EAAE;MACjCsB,GAAG,EAAEnB,aAAa,CAACmB,GAAG,EAAEG,SAAS,CAAC;MAClC,eAAe,EAAEF,QAAQ,GAAG,MAAM,GAAGX,SAAS;MAC9CiB,EAAE;MACF,GAAGsB,aAAa;MAChB,GAAG9B,KAAK;MACRyB;KACD,CAAC;IACFS,SAAS,EAAEtD,gBAAgB,CAACoB,KAAK,CAACkC,SAAS,EAAE;MAC3CC,QAAQ,EAAE,IAAI;MACdC,YAAY,EAAE;QACZ,aAAa,EAAE,MAAM;QACrB9C,QAAQ,EAAEkC;;KAEb,CAAC;IACFF,MAAM;IACNpB,QAAQ;IACRS,YAAY;IACZE,WAAW;IACXE;GACD;AACH,CAAC","names":["React","getNativeElementProps","resolveShorthand","useId","useMergedRefs","useContextSelector","CheckmarkFilled","Checkmark12Filled","ComboboxContext","ListboxContext","getTextString","text","children","undefined","textString","hasNonStringChild","Children","forEach","child","console","warn","useOption_unstable","props","ref","disabled","value","optionRef","useRef","optionText","optionValue","id","optionData","useMemo","focusVisible","ctx","multiselect","registerOption","selected","selectedOptions","find","o","selectOption","setActiveOption","setOpen","active","activeOption","CheckIcon","onClick","event","preventDefault","useEffect","current","semanticProps","role","components","root","checkIcon","required","defaultProps"],"sourceRoot":"../src/","sources":["packages/react-components/react-combobox/src/components/Option/useOption.tsx"],"sourcesContent":["import * as React from 'react';\nimport { getNativeElementProps, resolveShorthand, useId, useMergedRefs } from '@fluentui/react-utilities';\nimport { useContextSelector } from '@fluentui/react-context-selector';\nimport { CheckmarkFilled, Checkmark12Filled } from '@fluentui/react-icons';\nimport { ComboboxContext } from '../../contexts/ComboboxContext';\nimport { ListboxContext } from '../../contexts/ListboxContext';\nimport type { OptionValue } from '../../utils/OptionCollection.types';\nimport type { OptionProps, OptionState } from './Option.types';\n\nfunction getTextString(text: string | undefined, children: React.ReactNode) {\n if (text !== undefined) {\n return text;\n }\n\n let textString = '';\n let hasNonStringChild = false;\n React.Children.forEach(children, child => {\n if (typeof child === 'string') {\n textString += child;\n } else {\n hasNonStringChild = true;\n }\n });\n\n // warn if an Option has non-string children and no text prop\n if (hasNonStringChild) {\n // eslint-disable-next-line no-console\n console.warn('Provide a `text` prop to Option components when they contain non-string children.');\n }\n\n return textString;\n}\n\n/**\n * Create the state required to render Option.\n *\n * The returned state can be modified with hooks such as useOptionStyles_unstable,\n * before being passed to renderOption_unstable.\n *\n * @param props - props from this instance of Option\n * @param ref - reference to root HTMLElement of Option\n */\nexport const useOption_unstable = (props: OptionProps, ref: React.Ref<HTMLElement>): OptionState => {\n const { children, disabled, text, value } = props;\n const optionRef = React.useRef<HTMLElement>(null);\n const optionText = getTextString(text, children);\n const optionValue = value ?? optionText;\n\n // use the id if provided, otherwise use a generated id\n const id = useId('fluent-option', props.id);\n\n // data used for context registration & events\n const optionData = React.useMemo<OptionValue>(() => ({ id, disabled, text: optionText, value: optionValue }), [\n id,\n disabled,\n optionText,\n optionValue,\n ]);\n\n // context values\n const focusVisible = useContextSelector(ListboxContext, ctx => ctx.focusVisible);\n const multiselect = useContextSelector(ListboxContext, ctx => ctx.multiselect);\n const registerOption = useContextSelector(ListboxContext, ctx => ctx.registerOption);\n const selected = useContextSelector(ListboxContext, ctx => {\n const selectedOptions = ctx.selectedOptions;\n\n return !!optionValue && !!selectedOptions.find(o => o === optionValue);\n });\n const selectOption = useContextSelector(ListboxContext, ctx => ctx.selectOption);\n const setActiveOption = useContextSelector(ListboxContext, ctx => ctx.setActiveOption);\n const setOpen = useContextSelector(ComboboxContext, ctx => ctx.setOpen);\n\n // current active option?\n const active = useContextSelector(ListboxContext, ctx => {\n return ctx.activeOption?.id !== undefined && ctx.activeOption?.id === id;\n });\n\n // check icon\n let CheckIcon: React.ReactNode = <CheckmarkFilled />;\n if (multiselect) {\n CheckIcon = selected ? <Checkmark12Filled /> : '';\n }\n\n const onClick = (event: React.MouseEvent<HTMLDivElement>) => {\n if (disabled) {\n event.preventDefault();\n return;\n }\n\n // clicked option should always become active option\n setActiveOption(optionData);\n\n // close on option click for single-select options in a combobox\n if (!multiselect) {\n setOpen?.(event, false);\n }\n\n // handle selection change\n selectOption(event, optionData);\n\n props.onClick?.(event);\n };\n\n // register option data with context\n React.useEffect(() => {\n if (id && optionRef.current) {\n return registerOption(optionData, optionRef.current);\n }\n }, [id, optionData, registerOption]);\n\n const semanticProps = multiselect\n ? { role: 'menuitemcheckbox', 'aria-checked': selected }\n : { role: 'option', 'aria-selected': selected };\n\n return {\n components: {\n root: 'div',\n checkIcon: 'span',\n },\n root: getNativeElementProps('div', {\n ref: useMergedRefs(ref, optionRef),\n 'aria-disabled': disabled ? 'true' : undefined,\n id,\n ...semanticProps,\n ...props,\n onClick,\n }),\n checkIcon: resolveShorthand(props.checkIcon, {\n required: true,\n defaultProps: {\n 'aria-hidden': 'true',\n children: CheckIcon,\n },\n }),\n active,\n disabled,\n focusVisible,\n multiselect,\n selected,\n };\n};\n"]}