@fluentui/react-combobox 9.0.0-beta.9 → 9.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (302) hide show
  1. package/CHANGELOG.json +848 -1
  2. package/CHANGELOG.md +248 -2
  3. package/README.md +1 -3
  4. package/dist/index.d.ts +62 -11
  5. package/lib/Combobox.js.map +1 -1
  6. package/lib/ComboboxField.js +2 -0
  7. package/lib/ComboboxField.js.map +1 -0
  8. package/lib/Dropdown.js.map +1 -1
  9. package/lib/Listbox.js.map +1 -1
  10. package/lib/Option.js.map +1 -1
  11. package/lib/OptionGroup.js.map +1 -1
  12. package/lib/components/Combobox/Combobox.js +0 -1
  13. package/lib/components/Combobox/Combobox.js.map +1 -1
  14. package/lib/components/Combobox/Combobox.types.js.map +1 -1
  15. package/lib/components/Combobox/index.js.map +1 -1
  16. package/lib/components/Combobox/renderCombobox.js +10 -6
  17. package/lib/components/Combobox/renderCombobox.js.map +1 -1
  18. package/lib/components/Combobox/useCombobox.js +107 -70
  19. package/lib/components/Combobox/useCombobox.js.map +1 -1
  20. package/lib/components/Combobox/useComboboxStyles.js +246 -185
  21. package/lib/components/Combobox/useComboboxStyles.js.map +1 -1
  22. package/lib/components/ComboboxField/ComboboxField.js +8 -0
  23. package/lib/components/ComboboxField/ComboboxField.js.map +1 -0
  24. package/lib/components/ComboboxField/index.js +2 -0
  25. package/lib/components/ComboboxField/index.js.map +1 -0
  26. package/lib/components/Dropdown/Dropdown.js +0 -1
  27. package/lib/components/Dropdown/Dropdown.js.map +1 -1
  28. package/lib/components/Dropdown/Dropdown.types.js.map +1 -1
  29. package/lib/components/Dropdown/index.js.map +1 -1
  30. package/lib/components/Dropdown/renderDropdown.js +10 -6
  31. package/lib/components/Dropdown/renderDropdown.js.map +1 -1
  32. package/lib/components/Dropdown/useDropdown.js +25 -36
  33. package/lib/components/Dropdown/useDropdown.js.map +1 -1
  34. package/lib/components/Dropdown/useDropdownStyles.js +236 -176
  35. package/lib/components/Dropdown/useDropdownStyles.js.map +1 -1
  36. package/lib/components/Listbox/Listbox.js +0 -1
  37. package/lib/components/Listbox/Listbox.js.map +1 -1
  38. package/lib/components/Listbox/Listbox.types.js.map +1 -1
  39. package/lib/components/Listbox/index.js.map +1 -1
  40. package/lib/components/Listbox/renderListbox.js +2 -2
  41. package/lib/components/Listbox/renderListbox.js.map +1 -1
  42. package/lib/components/Listbox/useListbox.js +15 -17
  43. package/lib/components/Listbox/useListbox.js.map +1 -1
  44. package/lib/components/Listbox/useListboxStyles.js +16 -20
  45. package/lib/components/Listbox/useListboxStyles.js.map +1 -1
  46. package/lib/components/Option/Option.js +0 -1
  47. package/lib/components/Option/Option.js.map +1 -1
  48. package/lib/components/Option/Option.types.js.map +1 -1
  49. package/lib/components/Option/index.js.map +1 -1
  50. package/lib/components/Option/renderOption.js +4 -3
  51. package/lib/components/Option/renderOption.js.map +1 -1
  52. package/lib/components/Option/useOption.js +46 -39
  53. package/lib/components/Option/useOption.js.map +1 -1
  54. package/lib/components/Option/useOptionStyles.js +101 -79
  55. package/lib/components/Option/useOptionStyles.js.map +1 -1
  56. package/lib/components/OptionGroup/OptionGroup.js +0 -1
  57. package/lib/components/OptionGroup/OptionGroup.js.map +1 -1
  58. package/lib/components/OptionGroup/OptionGroup.types.js.map +1 -1
  59. package/lib/components/OptionGroup/index.js.map +1 -1
  60. package/lib/components/OptionGroup/renderOptionGroup.js +4 -3
  61. package/lib/components/OptionGroup/renderOptionGroup.js.map +1 -1
  62. package/lib/components/OptionGroup/useOptionGroup.js +0 -1
  63. package/lib/components/OptionGroup/useOptionGroup.js.map +1 -1
  64. package/lib/components/OptionGroup/useOptionGroupStyles.js +29 -34
  65. package/lib/components/OptionGroup/useOptionGroupStyles.js.map +1 -1
  66. package/lib/contexts/ComboboxContext.js +9 -11
  67. package/lib/contexts/ComboboxContext.js.map +1 -1
  68. package/lib/contexts/ListboxContext.js +7 -9
  69. package/lib/contexts/ListboxContext.js.map +1 -1
  70. package/lib/contexts/useComboboxContextValues.js.map +1 -1
  71. package/lib/contexts/useListboxContextValues.js +2 -2
  72. package/lib/contexts/useListboxContextValues.js.map +1 -1
  73. package/lib/index.js +6 -0
  74. package/lib/index.js.map +1 -1
  75. package/lib/utils/ComboboxBase.types.js.map +1 -1
  76. package/lib/utils/OptionCollection.types.js.map +1 -1
  77. package/lib/utils/Selection.types.js.map +1 -1
  78. package/lib/utils/dropdownKeyActions.js +12 -33
  79. package/lib/utils/dropdownKeyActions.js.map +1 -1
  80. package/lib/utils/internalTokens.js.map +1 -1
  81. package/lib/utils/useComboboxBaseState.js +29 -30
  82. package/lib/utils/useComboboxBaseState.js.map +1 -1
  83. package/lib/utils/useComboboxPopup.js +6 -4
  84. package/lib/utils/useComboboxPopup.js.map +1 -1
  85. package/lib/utils/useOptionCollection.js +13 -23
  86. package/lib/utils/useOptionCollection.js.map +1 -1
  87. package/lib/utils/useScrollOptionsIntoView.js +36 -0
  88. package/lib/utils/useScrollOptionsIntoView.js.map +1 -0
  89. package/lib/utils/useSelection.js +9 -12
  90. package/lib/utils/useSelection.js.map +1 -1
  91. package/lib/utils/useTriggerListboxSlots.js +34 -40
  92. package/lib/utils/useTriggerListboxSlots.js.map +1 -1
  93. package/lib-amd/Combobox.js +6 -0
  94. package/lib-amd/Combobox.js.map +1 -0
  95. package/lib-amd/ComboboxField.js +6 -0
  96. package/lib-amd/ComboboxField.js.map +1 -0
  97. package/lib-amd/Dropdown.js +6 -0
  98. package/lib-amd/Dropdown.js.map +1 -0
  99. package/lib-amd/Listbox.js +6 -0
  100. package/lib-amd/Listbox.js.map +1 -0
  101. package/lib-amd/Option.js +6 -0
  102. package/lib-amd/Option.js.map +1 -0
  103. package/lib-amd/OptionGroup.js +6 -0
  104. package/lib-amd/OptionGroup.js.map +1 -0
  105. package/lib-amd/components/Combobox/Combobox.js +16 -0
  106. package/lib-amd/components/Combobox/Combobox.js.map +1 -0
  107. package/lib-amd/components/Combobox/Combobox.types.js +5 -0
  108. package/lib-amd/components/Combobox/Combobox.types.js.map +1 -0
  109. package/lib-amd/components/Combobox/index.js +10 -0
  110. package/lib-amd/components/Combobox/index.js.map +1 -0
  111. package/lib-amd/components/Combobox/renderCombobox.js +20 -0
  112. package/lib-amd/components/Combobox/renderCombobox.js.map +1 -0
  113. package/lib-amd/components/Combobox/useCombobox.js +206 -0
  114. package/lib-amd/components/Combobox/useCombobox.js.map +1 -0
  115. package/lib-amd/components/Combobox/useComboboxStyles.js +152 -0
  116. package/lib-amd/components/Combobox/useComboboxStyles.js.map +1 -0
  117. package/lib-amd/components/ComboboxField/ComboboxField.js +10 -0
  118. package/lib-amd/components/ComboboxField/ComboboxField.js.map +1 -0
  119. package/lib-amd/components/ComboboxField/index.js +6 -0
  120. package/lib-amd/components/ComboboxField/index.js.map +1 -0
  121. package/lib-amd/components/Dropdown/Dropdown.js +16 -0
  122. package/lib-amd/components/Dropdown/Dropdown.js.map +1 -0
  123. package/lib-amd/components/Dropdown/Dropdown.types.js +5 -0
  124. package/lib-amd/components/Dropdown/Dropdown.types.js.map +1 -0
  125. package/lib-amd/components/Dropdown/index.js +10 -0
  126. package/lib-amd/components/Dropdown/index.js.map +1 -0
  127. package/lib-amd/components/Dropdown/renderDropdown.js +21 -0
  128. package/lib-amd/components/Dropdown/renderDropdown.js.map +1 -0
  129. package/lib-amd/components/Dropdown/useDropdown.js +121 -0
  130. package/lib-amd/components/Dropdown/useDropdown.js.map +1 -0
  131. package/lib-amd/components/Dropdown/useDropdownStyles.js +127 -0
  132. package/lib-amd/components/Dropdown/useDropdownStyles.js.map +1 -0
  133. package/lib-amd/components/Listbox/Listbox.js +16 -0
  134. package/lib-amd/components/Listbox/Listbox.js.map +1 -0
  135. package/lib-amd/components/Listbox/Listbox.types.js +5 -0
  136. package/lib-amd/components/Listbox/Listbox.types.js.map +1 -0
  137. package/lib-amd/components/Listbox/index.js +10 -0
  138. package/lib-amd/components/Listbox/index.js.map +1 -0
  139. package/lib-amd/components/Listbox/renderListbox.js +15 -0
  140. package/lib-amd/components/Listbox/renderListbox.js.map +1 -0
  141. package/lib-amd/components/Listbox/useListbox.js +80 -0
  142. package/lib-amd/components/Listbox/useListbox.js.map +1 -0
  143. package/lib-amd/components/Listbox/useListboxStyles.js +24 -0
  144. package/lib-amd/components/Listbox/useListboxStyles.js.map +1 -0
  145. package/lib-amd/components/Option/Option.js +15 -0
  146. package/lib-amd/components/Option/Option.js.map +1 -0
  147. package/lib-amd/components/Option/Option.types.js +5 -0
  148. package/lib-amd/components/Option/Option.types.js.map +1 -0
  149. package/lib-amd/components/Option/index.js +10 -0
  150. package/lib-amd/components/Option/index.js.map +1 -0
  151. package/lib-amd/components/Option/renderOption.js +16 -0
  152. package/lib-amd/components/Option/renderOption.js.map +1 -0
  153. package/lib-amd/components/Option/useOption.js +117 -0
  154. package/lib-amd/components/Option/useOption.js.map +1 -0
  155. package/lib-amd/components/Option/useOptionStyles.js +73 -0
  156. package/lib-amd/components/Option/useOptionStyles.js.map +1 -0
  157. package/lib-amd/components/OptionGroup/OptionGroup.js +15 -0
  158. package/lib-amd/components/OptionGroup/OptionGroup.js.map +1 -0
  159. package/lib-amd/components/OptionGroup/OptionGroup.types.js +5 -0
  160. package/lib-amd/components/OptionGroup/OptionGroup.types.js.map +1 -0
  161. package/lib-amd/components/OptionGroup/index.js +10 -0
  162. package/lib-amd/components/OptionGroup/index.js.map +1 -0
  163. package/lib-amd/components/OptionGroup/renderOptionGroup.js +16 -0
  164. package/lib-amd/components/OptionGroup/renderOptionGroup.js.map +1 -0
  165. package/lib-amd/components/OptionGroup/useOptionGroup.js +33 -0
  166. package/lib-amd/components/OptionGroup/useOptionGroup.js.map +1 -0
  167. package/lib-amd/components/OptionGroup/useOptionGroupStyles.js +34 -0
  168. package/lib-amd/components/OptionGroup/useOptionGroupStyles.js.map +1 -0
  169. package/lib-amd/contexts/ComboboxContext.js +28 -0
  170. package/lib-amd/contexts/ComboboxContext.js.map +1 -0
  171. package/lib-amd/contexts/ListboxContext.js +23 -0
  172. package/lib-amd/contexts/ListboxContext.js.map +1 -0
  173. package/lib-amd/contexts/useComboboxContextValues.js +23 -0
  174. package/lib-amd/contexts/useComboboxContextValues.js.map +1 -0
  175. package/lib-amd/contexts/useListboxContextValues.js +24 -0
  176. package/lib-amd/contexts/useListboxContextValues.js.map +1 -0
  177. package/lib-amd/index.js +37 -0
  178. package/lib-amd/index.js.map +1 -0
  179. package/lib-amd/utils/ComboboxBase.types.js +5 -0
  180. package/lib-amd/utils/ComboboxBase.types.js.map +1 -0
  181. package/lib-amd/utils/OptionCollection.types.js +5 -0
  182. package/lib-amd/utils/OptionCollection.types.js.map +1 -0
  183. package/lib-amd/utils/Selection.types.js +5 -0
  184. package/lib-amd/utils/Selection.types.js.map +1 -0
  185. package/lib-amd/utils/dropdownKeyActions.js +85 -0
  186. package/lib-amd/utils/dropdownKeyActions.js.map +1 -0
  187. package/lib-amd/utils/internalTokens.js +11 -0
  188. package/lib-amd/utils/internalTokens.js.map +1 -0
  189. package/lib-amd/utils/useComboboxBaseState.js +76 -0
  190. package/lib-amd/utils/useComboboxBaseState.js.map +1 -0
  191. package/lib-amd/utils/useComboboxPopup.js +16 -0
  192. package/lib-amd/utils/useComboboxPopup.js.map +1 -0
  193. package/lib-amd/utils/useOptionCollection.js +65 -0
  194. package/lib-amd/utils/useOptionCollection.js.map +1 -0
  195. package/lib-amd/utils/useScrollOptionsIntoView.js +33 -0
  196. package/lib-amd/utils/useScrollOptionsIntoView.js.map +1 -0
  197. package/lib-amd/utils/useSelection.js +42 -0
  198. package/lib-amd/utils/useSelection.js.map +1 -0
  199. package/lib-amd/utils/useTriggerListboxSlots.js +104 -0
  200. package/lib-amd/utils/useTriggerListboxSlots.js.map +1 -0
  201. package/lib-commonjs/Combobox.js +0 -2
  202. package/lib-commonjs/Combobox.js.map +1 -1
  203. package/lib-commonjs/ComboboxField.js +8 -0
  204. package/lib-commonjs/ComboboxField.js.map +1 -0
  205. package/lib-commonjs/Dropdown.js +0 -2
  206. package/lib-commonjs/Dropdown.js.map +1 -1
  207. package/lib-commonjs/Listbox.js +0 -2
  208. package/lib-commonjs/Listbox.js.map +1 -1
  209. package/lib-commonjs/Option.js +0 -2
  210. package/lib-commonjs/Option.js.map +1 -1
  211. package/lib-commonjs/OptionGroup.js +0 -2
  212. package/lib-commonjs/OptionGroup.js.map +1 -1
  213. package/lib-commonjs/components/Combobox/Combobox.js +0 -7
  214. package/lib-commonjs/components/Combobox/Combobox.js.map +1 -1
  215. package/lib-commonjs/components/Combobox/Combobox.types.js.map +1 -1
  216. package/lib-commonjs/components/Combobox/index.js +0 -6
  217. package/lib-commonjs/components/Combobox/index.js.map +1 -1
  218. package/lib-commonjs/components/Combobox/renderCombobox.js +10 -12
  219. package/lib-commonjs/components/Combobox/renderCombobox.js.map +1 -1
  220. package/lib-commonjs/components/Combobox/useCombobox.js +106 -78
  221. package/lib-commonjs/components/Combobox/useCombobox.js.map +1 -1
  222. package/lib-commonjs/components/Combobox/useComboboxStyles.js +245 -189
  223. package/lib-commonjs/components/Combobox/useComboboxStyles.js.map +1 -1
  224. package/lib-commonjs/components/ComboboxField/ComboboxField.js +14 -0
  225. package/lib-commonjs/components/ComboboxField/ComboboxField.js.map +1 -0
  226. package/lib-commonjs/components/ComboboxField/index.js +8 -0
  227. package/lib-commonjs/components/ComboboxField/index.js.map +1 -0
  228. package/lib-commonjs/components/Dropdown/Dropdown.js +0 -7
  229. package/lib-commonjs/components/Dropdown/Dropdown.js.map +1 -1
  230. package/lib-commonjs/components/Dropdown/Dropdown.types.js.map +1 -1
  231. package/lib-commonjs/components/Dropdown/index.js +0 -6
  232. package/lib-commonjs/components/Dropdown/index.js.map +1 -1
  233. package/lib-commonjs/components/Dropdown/renderDropdown.js +10 -12
  234. package/lib-commonjs/components/Dropdown/renderDropdown.js.map +1 -1
  235. package/lib-commonjs/components/Dropdown/useDropdown.js +25 -47
  236. package/lib-commonjs/components/Dropdown/useDropdown.js.map +1 -1
  237. package/lib-commonjs/components/Dropdown/useDropdownStyles.js +235 -180
  238. package/lib-commonjs/components/Dropdown/useDropdownStyles.js.map +1 -1
  239. package/lib-commonjs/components/Listbox/Listbox.js +0 -7
  240. package/lib-commonjs/components/Listbox/Listbox.js.map +1 -1
  241. package/lib-commonjs/components/Listbox/Listbox.types.js.map +1 -1
  242. package/lib-commonjs/components/Listbox/index.js +0 -6
  243. package/lib-commonjs/components/Listbox/index.js.map +1 -1
  244. package/lib-commonjs/components/Listbox/renderListbox.js +2 -7
  245. package/lib-commonjs/components/Listbox/renderListbox.js.map +1 -1
  246. package/lib-commonjs/components/Listbox/useListbox.js +14 -25
  247. package/lib-commonjs/components/Listbox/useListbox.js.map +1 -1
  248. package/lib-commonjs/components/Listbox/useListboxStyles.js +16 -24
  249. package/lib-commonjs/components/Listbox/useListboxStyles.js.map +1 -1
  250. package/lib-commonjs/components/Option/Option.js +0 -6
  251. package/lib-commonjs/components/Option/Option.js.map +1 -1
  252. package/lib-commonjs/components/Option/Option.types.js.map +1 -1
  253. package/lib-commonjs/components/Option/index.js +0 -6
  254. package/lib-commonjs/components/Option/index.js.map +1 -1
  255. package/lib-commonjs/components/Option/renderOption.js +4 -7
  256. package/lib-commonjs/components/Option/renderOption.js.map +1 -1
  257. package/lib-commonjs/components/Option/useOption.js +45 -45
  258. package/lib-commonjs/components/Option/useOption.js.map +1 -1
  259. package/lib-commonjs/components/Option/useOptionStyles.js +101 -83
  260. package/lib-commonjs/components/Option/useOptionStyles.js.map +1 -1
  261. package/lib-commonjs/components/OptionGroup/OptionGroup.js +0 -6
  262. package/lib-commonjs/components/OptionGroup/OptionGroup.js.map +1 -1
  263. package/lib-commonjs/components/OptionGroup/OptionGroup.types.js.map +1 -1
  264. package/lib-commonjs/components/OptionGroup/index.js +0 -6
  265. package/lib-commonjs/components/OptionGroup/index.js.map +1 -1
  266. package/lib-commonjs/components/OptionGroup/renderOptionGroup.js +4 -7
  267. package/lib-commonjs/components/OptionGroup/renderOptionGroup.js.map +1 -1
  268. package/lib-commonjs/components/OptionGroup/useOptionGroup.js +0 -4
  269. package/lib-commonjs/components/OptionGroup/useOptionGroup.js.map +1 -1
  270. package/lib-commonjs/components/OptionGroup/useOptionGroupStyles.js +29 -38
  271. package/lib-commonjs/components/OptionGroup/useOptionGroupStyles.js.map +1 -1
  272. package/lib-commonjs/contexts/ComboboxContext.js +10 -14
  273. package/lib-commonjs/contexts/ComboboxContext.js.map +1 -1
  274. package/lib-commonjs/contexts/ListboxContext.js +8 -12
  275. package/lib-commonjs/contexts/ListboxContext.js.map +1 -1
  276. package/lib-commonjs/contexts/useComboboxContextValues.js +0 -2
  277. package/lib-commonjs/contexts/useComboboxContextValues.js.map +1 -1
  278. package/lib-commonjs/contexts/useListboxContextValues.js +2 -6
  279. package/lib-commonjs/contexts/useListboxContextValues.js.map +1 -1
  280. package/lib-commonjs/index.js +43 -11
  281. package/lib-commonjs/index.js.map +1 -1
  282. package/lib-commonjs/utils/ComboboxBase.types.js.map +1 -1
  283. package/lib-commonjs/utils/OptionCollection.types.js.map +1 -1
  284. package/lib-commonjs/utils/Selection.types.js.map +1 -1
  285. package/lib-commonjs/utils/dropdownKeyActions.js +12 -37
  286. package/lib-commonjs/utils/dropdownKeyActions.js.map +1 -1
  287. package/lib-commonjs/utils/internalTokens.js.map +1 -1
  288. package/lib-commonjs/utils/useComboboxBaseState.js +29 -36
  289. package/lib-commonjs/utils/useComboboxBaseState.js.map +1 -1
  290. package/lib-commonjs/utils/useComboboxPopup.js +6 -8
  291. package/lib-commonjs/utils/useComboboxPopup.js.map +1 -1
  292. package/lib-commonjs/utils/useOptionCollection.js +13 -26
  293. package/lib-commonjs/utils/useOptionCollection.js.map +1 -1
  294. package/lib-commonjs/utils/useScrollOptionsIntoView.js +43 -0
  295. package/lib-commonjs/utils/useScrollOptionsIntoView.js.map +1 -0
  296. package/lib-commonjs/utils/useSelection.js +9 -15
  297. package/lib-commonjs/utils/useSelection.js.map +1 -1
  298. package/lib-commonjs/utils/useTriggerListboxSlots.js +33 -44
  299. package/lib-commonjs/utils/useTriggerListboxSlots.js.map +1 -1
  300. package/package.json +23 -22
  301. package/Spec-migration.md +0 -13
  302. package/Spec.md +0 -520
@@ -1,10 +1,11 @@
1
1
  import * as React from 'react';
2
- import { getNativeElementProps, mergeCallbacks, useEventCallback } 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
@@ -26,14 +26,14 @@ export const useListbox_unstable = (props, ref) => {
26
26
  getIndexOfId
27
27
  } = optionCollection;
28
28
  const {
29
+ clearSelection,
29
30
  selectedOptions,
30
31
  selectOption
31
32
  } = useSelection(props);
32
- const [activeOption, setActiveOption] = React.useState(); // track whether keyboard focus outline should be shown
33
+ const [activeOption, setActiveOption] = React.useState();
34
+ // track whether keyboard focus outline should be shown
33
35
  // tabster/keyborg doesn't work here, since the actual keyboard focus target doesn't move
34
-
35
36
  const [focusVisible, setFocusVisible] = React.useState(false);
36
-
37
37
  const onKeyDown = event => {
38
38
  const action = getDropdownActionFromKey(event, {
39
39
  open: true
@@ -41,17 +41,14 @@ export const useListbox_unstable = (props, ref) => {
41
41
  const maxIndex = getCount() - 1;
42
42
  const activeIndex = activeOption ? getIndexOfId(activeOption.id) : -1;
43
43
  let newIndex = activeIndex;
44
-
45
44
  switch (action) {
46
45
  case 'Select':
47
46
  case 'CloseSelect':
48
47
  activeOption && selectOption(event, activeOption);
49
48
  break;
50
-
51
49
  default:
52
50
  newIndex = getIndexFromAction(action, activeIndex, maxIndex);
53
51
  }
54
-
55
52
  if (newIndex !== activeIndex) {
56
53
  // prevent default page scroll/keyboard action if the index changed
57
54
  event.preventDefault();
@@ -59,19 +56,17 @@ export const useListbox_unstable = (props, ref) => {
59
56
  setFocusVisible(true);
60
57
  }
61
58
  };
62
-
63
59
  const onMouseOver = event => {
64
60
  setFocusVisible(false);
65
- }; // get state from parent combobox, if it exists
66
-
67
-
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
65
  const comboboxFocusVisible = useContextSelector(ComboboxContext, ctx => ctx.focusVisible);
71
66
  const comboboxSelectedOptions = useContextSelector(ComboboxContext, ctx => ctx.selectedOptions);
72
67
  const comboboxSelectOption = useContextSelector(ComboboxContext, ctx => ctx.selectOption);
73
- const comboboxSetActiveOption = useContextSelector(ComboboxContext, ctx => ctx.setActiveOption); // without a parent combobox context, provide values directly from Listbox
74
-
68
+ const comboboxSetActiveOption = useContextSelector(ComboboxContext, ctx => ctx.setActiveOption);
69
+ // without a parent combobox context, provide values directly from Listbox
75
70
  const optionContextValues = hasComboboxContext ? {
76
71
  activeOption: comboboxActiveOption,
77
72
  focusVisible: comboboxFocusVisible,
@@ -91,16 +86,19 @@ export const useListbox_unstable = (props, ref) => {
91
86
  },
92
87
  root: getNativeElementProps('div', {
93
88
  ref,
94
- role: 'listbox',
89
+ role: multiselect ? 'menu' : 'listbox',
95
90
  'aria-activedescendant': hasComboboxContext ? undefined : activeOption === null || activeOption === void 0 ? void 0 : activeOption.id,
96
91
  'aria-multiselectable': multiselect,
97
92
  tabIndex: 0,
98
93
  ...props
99
94
  }),
100
95
  multiselect,
96
+ clearSelection,
101
97
  ...optionCollection,
102
98
  ...optionContextValues
103
99
  };
100
+ const scrollContainerRef = useScrollOptionsIntoView(state);
101
+ state.root.ref = useMergedRefs(state.root.ref, scrollContainerRef);
104
102
  state.root.onKeyDown = useEventCallback(mergeCallbacks(state.root.onKeyDown, onKeyDown));
105
103
  state.root.onMouseOver = useEventCallback(mergeCallbacks(state.root.onMouseOver, onMouseOver));
106
104
  return state;
@@ -1 +1 @@
1
- {"version":3,"sources":["components/Listbox/useListbox.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,qBAAT,EAAgC,cAAhC,EAAgD,gBAAhD,QAAwE,2BAAxE;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,CAAC,KAAD,EAAsB,GAAtB,KAAmE;EACpG,MAAM;IAAE;EAAF,IAAkB,KAAxB;EACA,MAAM,gBAAgB,GAAG,mBAAmB,EAA5C;EACA,MAAM;IAAE,QAAF;IAAY,gBAAZ;IAA8B;EAA9B,IAA+C,gBAArD;EAEA,MAAM;IAAE,eAAF;IAAmB;EAAnB,IAAoC,YAAY,CAAC,KAAD,CAAtD;EAEA,MAAM,CAAC,YAAD,EAAe,eAAf,IAAkC,KAAK,CAAC,QAAN,EAAxC,CAPoG,CASpG;EACA;;EACA,MAAM,CAAC,YAAD,EAAe,eAAf,IAAkC,KAAK,CAAC,QAAN,CAAe,KAAf,CAAxC;;EAEA,MAAM,SAAS,GAAI,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B,CAAlD,CA9CoG,CAgDpG;;EACA,MAAM,mBAAmB,GAAG,kBAAkB,GAC1C;IACE,YAAY,EAAE,oBADhB;IAEE,YAAY,EAAE,oBAFhB;IAGE,eAAe,EAAE,uBAHnB;IAIE,YAAY,EAAE,oBAJhB;IAKE,eAAe,EAAE;EALnB,CAD0C,GAQ1C;IACE,YADF;IAEE,YAFF;IAGE,eAHF;IAIE,YAJF;IAKE;EALF,CARJ;EAgBA,MAAM,KAAK,GAAiB;IAC1B,UAAU,EAAE;MACV,IAAI,EAAE;IADI,CADc;IAI1B,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,GAAG;IAN8B,CAAR,CAJD;IAY1B,WAZ0B;IAa1B,GAAG,gBAbuB;IAc1B,GAAG;EAduB,CAA5B;EAiBA,KAAK,CAAC,IAAN,CAAW,SAAX,GAAuB,gBAAgB,CAAC,cAAc,CAAC,KAAK,CAAC,IAAN,CAAW,SAAZ,EAAuB,SAAvB,CAAf,CAAvC;EACA,KAAK,CAAC,IAAN,CAAW,WAAX,GAAyB,gBAAgB,CAAC,cAAc,CAAC,KAAK,CAAC,IAAN,CAAW,WAAZ,EAAyB,WAAzB,CAAf,CAAzC;EAEA,OAAO,KAAP;AACD,CAtFM","sourcesContent":["import * as React from 'react';\nimport { getNativeElementProps, mergeCallbacks, useEventCallback } 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, getIndexOfId } = optionCollection;\n\n const { 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: 'listbox',\n 'aria-activedescendant': hasComboboxContext ? undefined : activeOption?.id,\n 'aria-multiselectable': multiselect,\n tabIndex: 0,\n ...props,\n }),\n multiselect,\n ...optionCollection,\n ...optionContextValues,\n };\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"],"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;I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C,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 // 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
+ {"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,22 +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';
4
+ import { CheckmarkFilled, Checkmark12Filled } from '@fluentui/react-icons';
5
5
  import { ComboboxContext } from '../../contexts/ComboboxContext';
6
6
  import { ListboxContext } from '../../contexts/ListboxContext';
7
-
8
- function getValueString(value, children) {
9
- if (value) {
10
- return value;
7
+ function getTextString(text, children) {
8
+ if (text !== undefined) {
9
+ return text;
11
10
  }
12
-
13
- let valueString = '';
11
+ let textString = '';
12
+ let hasNonStringChild = false;
14
13
  React.Children.forEach(children, child => {
15
14
  if (typeof child === 'string') {
16
- valueString += child;
15
+ textString += child;
16
+ } else {
17
+ hasNonStringChild = true;
17
18
  }
18
19
  });
19
- 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;
20
26
  }
21
27
  /**
22
28
  * Create the state required to render Option.
@@ -27,24 +33,26 @@ function getValueString(value, children) {
27
33
  * @param props - props from this instance of Option
28
34
  * @param ref - reference to root HTMLElement of Option
29
35
  */
30
-
31
-
32
36
  export const useOption_unstable = (props, ref) => {
33
37
  const {
38
+ children,
34
39
  disabled,
40
+ text,
35
41
  value
36
42
  } = props;
37
43
  const optionRef = React.useRef(null);
38
- const optionValue = getValueString(value, props.children); // use the id if provided, otherwise use a generated id
39
-
40
- const id = useId('fluent-option', props.id); // data used for context registration & events
41
-
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
42
49
  const optionData = React.useMemo(() => ({
43
50
  id,
44
51
  disabled,
52
+ text: optionText,
45
53
  value: optionValue
46
- }), [id, disabled, optionValue]); // context values
47
-
54
+ }), [id, disabled, optionText, optionValue]);
55
+ // context values
48
56
  const focusVisible = useContextSelector(ListboxContext, ctx => ctx.focusVisible);
49
57
  const multiselect = useContextSelector(ListboxContext, ctx => ctx.multiselect);
50
58
  const registerOption = useContextSelector(ListboxContext, ctx => ctx.registerOption);
@@ -54,46 +62,46 @@ export const useOption_unstable = (props, ref) => {
54
62
  });
55
63
  const selectOption = useContextSelector(ListboxContext, ctx => ctx.selectOption);
56
64
  const setActiveOption = useContextSelector(ListboxContext, ctx => ctx.setActiveOption);
57
- const setOpen = useContextSelector(ComboboxContext, ctx => ctx.setOpen); // current active option?
58
-
65
+ const setOpen = useContextSelector(ComboboxContext, ctx => ctx.setOpen);
66
+ // current active option?
59
67
  const active = useContextSelector(ListboxContext, ctx => {
60
68
  var _a, _b;
61
-
62
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;
63
- }); // check icon
64
-
70
+ });
71
+ // check icon
65
72
  let CheckIcon = /*#__PURE__*/React.createElement(CheckmarkFilled, null);
66
-
67
73
  if (multiselect) {
68
- CheckIcon = selected ? /*#__PURE__*/React.createElement(CheckboxCheckedFilled, null) : /*#__PURE__*/React.createElement(CheckboxUncheckedFilled, null);
74
+ CheckIcon = selected ? /*#__PURE__*/React.createElement(Checkmark12Filled, null) : '';
69
75
  }
70
-
71
76
  const onClick = event => {
72
77
  var _a;
73
-
74
78
  if (disabled) {
75
79
  event.preventDefault();
76
80
  return;
77
- } // clicked option should always become active option
78
-
79
-
80
- setActiveOption(optionData); // close on option click for single-select options in a combobox
81
-
81
+ }
82
+ // clicked option should always become active option
83
+ setActiveOption(optionData);
84
+ // close on option click for single-select options in a combobox
82
85
  if (!multiselect) {
83
86
  setOpen === null || setOpen === void 0 ? void 0 : setOpen(event, false);
84
- } // handle selection change
85
-
86
-
87
+ }
88
+ // handle selection change
87
89
  selectOption(event, optionData);
88
90
  (_a = props.onClick) === null || _a === void 0 ? void 0 : _a.call(props, event);
89
- }; // register option data with context
90
-
91
-
91
+ };
92
+ // register option data with context
92
93
  React.useEffect(() => {
93
94
  if (id && optionRef.current) {
94
95
  return registerOption(optionData, optionRef.current);
95
96
  }
96
97
  }, [id, optionData, registerOption]);
98
+ const semanticProps = multiselect ? {
99
+ role: 'menuitemcheckbox',
100
+ 'aria-checked': selected
101
+ } : {
102
+ role: 'option',
103
+ 'aria-selected': selected
104
+ };
97
105
  return {
98
106
  components: {
99
107
  root: 'div',
@@ -101,10 +109,9 @@ export const useOption_unstable = (props, ref) => {
101
109
  },
102
110
  root: getNativeElementProps('div', {
103
111
  ref: useMergedRefs(ref, optionRef),
104
- role: 'option',
105
112
  'aria-disabled': disabled ? 'true' : undefined,
106
- 'aria-selected': `${selected}`,
107
113
  id,
114
+ ...semanticProps,
108
115
  ...props,
109
116
  onClick
110
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,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,YAvBK;IAwBL,WAxBK;IAyBL;EAzBK,CAAP;AA2BD,CA7FM","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 { 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 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 // 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, value: optionValue }), [\n id,\n disabled,\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 = <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 // 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 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 focusVisible,\n multiselect,\n selected,\n };\n};\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SA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AAgB,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"]}