@fluentui/react-combobox 9.0.0-beta.19 → 9.0.0-beta.21

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 (166) hide show
  1. package/CHANGELOG.json +117 -1
  2. package/CHANGELOG.md +32 -2
  3. package/lib/components/Combobox/Combobox.js +0 -1
  4. package/lib/components/Combobox/Combobox.js.map +1 -1
  5. package/lib/components/Combobox/renderCombobox.js +10 -6
  6. package/lib/components/Combobox/renderCombobox.js.map +1 -1
  7. package/lib/components/Combobox/useCombobox.js +41 -53
  8. package/lib/components/Combobox/useCombobox.js.map +1 -1
  9. package/lib/components/Combobox/useComboboxStyles.js +209 -217
  10. package/lib/components/Combobox/useComboboxStyles.js.map +1 -1
  11. package/lib/components/ComboboxField/ComboboxField.js.map +1 -1
  12. package/lib/components/Dropdown/Dropdown.js +0 -1
  13. package/lib/components/Dropdown/Dropdown.js.map +1 -1
  14. package/lib/components/Dropdown/renderDropdown.js +10 -6
  15. package/lib/components/Dropdown/renderDropdown.js.map +1 -1
  16. package/lib/components/Dropdown/useDropdown.js +20 -32
  17. package/lib/components/Dropdown/useDropdown.js.map +1 -1
  18. package/lib/components/Dropdown/useDropdownStyles.js +199 -206
  19. package/lib/components/Dropdown/useDropdownStyles.js.map +1 -1
  20. package/lib/components/Listbox/Listbox.js +0 -1
  21. package/lib/components/Listbox/Listbox.js.map +1 -1
  22. package/lib/components/Listbox/renderListbox.js +2 -2
  23. package/lib/components/Listbox/renderListbox.js.map +1 -1
  24. package/lib/components/Listbox/useListbox.js +6 -13
  25. package/lib/components/Listbox/useListbox.js.map +1 -1
  26. package/lib/components/Listbox/useListboxStyles.js +18 -21
  27. package/lib/components/Listbox/useListboxStyles.js.map +1 -1
  28. package/lib/components/Option/Option.js +0 -1
  29. package/lib/components/Option/Option.js.map +1 -1
  30. package/lib/components/Option/renderOption.js +4 -3
  31. package/lib/components/Option/renderOption.js.map +1 -1
  32. package/lib/components/Option/useOption.js +20 -32
  33. package/lib/components/Option/useOption.js.map +1 -1
  34. package/lib/components/Option/useOptionStyles.js +74 -79
  35. package/lib/components/Option/useOptionStyles.js.map +1 -1
  36. package/lib/components/OptionGroup/OptionGroup.js +0 -1
  37. package/lib/components/OptionGroup/OptionGroup.js.map +1 -1
  38. package/lib/components/OptionGroup/renderOptionGroup.js +4 -3
  39. package/lib/components/OptionGroup/renderOptionGroup.js.map +1 -1
  40. package/lib/components/OptionGroup/useOptionGroup.js +0 -1
  41. package/lib/components/OptionGroup/useOptionGroup.js.map +1 -1
  42. package/lib/components/OptionGroup/useOptionGroupStyles.js +29 -34
  43. package/lib/components/OptionGroup/useOptionGroupStyles.js.map +1 -1
  44. package/lib/contexts/ComboboxContext.js +8 -11
  45. package/lib/contexts/ComboboxContext.js.map +1 -1
  46. package/lib/contexts/ListboxContext.js +6 -9
  47. package/lib/contexts/ListboxContext.js.map +1 -1
  48. package/lib/contexts/useComboboxContextValues.js.map +1 -1
  49. package/lib/contexts/useListboxContextValues.js +2 -2
  50. package/lib/contexts/useListboxContextValues.js.map +1 -1
  51. package/lib/index.js.map +1 -1
  52. package/lib/utils/dropdownKeyActions.js +12 -33
  53. package/lib/utils/dropdownKeyActions.js.map +1 -1
  54. package/lib/utils/internalTokens.js.map +1 -1
  55. package/lib/utils/useComboboxBaseState.js +23 -27
  56. package/lib/utils/useComboboxBaseState.js.map +1 -1
  57. package/lib/utils/useComboboxPopup.js +6 -4
  58. package/lib/utils/useComboboxPopup.js.map +1 -1
  59. package/lib/utils/useOptionCollection.js +10 -20
  60. package/lib/utils/useOptionCollection.js.map +1 -1
  61. package/lib/utils/useScrollOptionsIntoView.js +2 -5
  62. package/lib/utils/useScrollOptionsIntoView.js.map +1 -1
  63. package/lib/utils/useSelection.js +7 -12
  64. package/lib/utils/useSelection.js.map +1 -1
  65. package/lib/utils/useTriggerListboxSlots.js +31 -39
  66. package/lib/utils/useTriggerListboxSlots.js.map +1 -1
  67. package/lib-commonjs/Combobox.js +0 -2
  68. package/lib-commonjs/Combobox.js.map +1 -1
  69. package/lib-commonjs/ComboboxField.js +0 -2
  70. package/lib-commonjs/ComboboxField.js.map +1 -1
  71. package/lib-commonjs/Dropdown.js +0 -2
  72. package/lib-commonjs/Dropdown.js.map +1 -1
  73. package/lib-commonjs/Listbox.js +0 -2
  74. package/lib-commonjs/Listbox.js.map +1 -1
  75. package/lib-commonjs/Option.js +0 -2
  76. package/lib-commonjs/Option.js.map +1 -1
  77. package/lib-commonjs/OptionGroup.js +0 -2
  78. package/lib-commonjs/OptionGroup.js.map +1 -1
  79. package/lib-commonjs/components/Combobox/Combobox.js +0 -7
  80. package/lib-commonjs/components/Combobox/Combobox.js.map +1 -1
  81. package/lib-commonjs/components/Combobox/Combobox.types.js.map +1 -1
  82. package/lib-commonjs/components/Combobox/index.js +0 -6
  83. package/lib-commonjs/components/Combobox/index.js.map +1 -1
  84. package/lib-commonjs/components/Combobox/renderCombobox.js +10 -12
  85. package/lib-commonjs/components/Combobox/renderCombobox.js.map +1 -1
  86. package/lib-commonjs/components/Combobox/useCombobox.js +41 -63
  87. package/lib-commonjs/components/Combobox/useCombobox.js.map +1 -1
  88. package/lib-commonjs/components/Combobox/useComboboxStyles.js +209 -222
  89. package/lib-commonjs/components/Combobox/useComboboxStyles.js.map +1 -1
  90. package/lib-commonjs/components/ComboboxField/ComboboxField.js +0 -4
  91. package/lib-commonjs/components/ComboboxField/ComboboxField.js.map +1 -1
  92. package/lib-commonjs/components/ComboboxField/index.js +0 -2
  93. package/lib-commonjs/components/ComboboxField/index.js.map +1 -1
  94. package/lib-commonjs/components/Dropdown/Dropdown.js +0 -7
  95. package/lib-commonjs/components/Dropdown/Dropdown.js.map +1 -1
  96. package/lib-commonjs/components/Dropdown/Dropdown.types.js.map +1 -1
  97. package/lib-commonjs/components/Dropdown/index.js +0 -6
  98. package/lib-commonjs/components/Dropdown/index.js.map +1 -1
  99. package/lib-commonjs/components/Dropdown/renderDropdown.js +10 -12
  100. package/lib-commonjs/components/Dropdown/renderDropdown.js.map +1 -1
  101. package/lib-commonjs/components/Dropdown/useDropdown.js +20 -43
  102. package/lib-commonjs/components/Dropdown/useDropdown.js.map +1 -1
  103. package/lib-commonjs/components/Dropdown/useDropdownStyles.js +199 -211
  104. package/lib-commonjs/components/Dropdown/useDropdownStyles.js.map +1 -1
  105. package/lib-commonjs/components/Listbox/Listbox.js +0 -7
  106. package/lib-commonjs/components/Listbox/Listbox.js.map +1 -1
  107. package/lib-commonjs/components/Listbox/Listbox.types.js.map +1 -1
  108. package/lib-commonjs/components/Listbox/index.js +0 -6
  109. package/lib-commonjs/components/Listbox/index.js.map +1 -1
  110. package/lib-commonjs/components/Listbox/renderListbox.js +2 -7
  111. package/lib-commonjs/components/Listbox/renderListbox.js.map +1 -1
  112. package/lib-commonjs/components/Listbox/useListbox.js +6 -23
  113. package/lib-commonjs/components/Listbox/useListbox.js.map +1 -1
  114. package/lib-commonjs/components/Listbox/useListboxStyles.js +18 -25
  115. package/lib-commonjs/components/Listbox/useListboxStyles.js.map +1 -1
  116. package/lib-commonjs/components/Option/Option.js +0 -6
  117. package/lib-commonjs/components/Option/Option.js.map +1 -1
  118. package/lib-commonjs/components/Option/Option.types.js.map +1 -1
  119. package/lib-commonjs/components/Option/index.js +0 -6
  120. package/lib-commonjs/components/Option/index.js.map +1 -1
  121. package/lib-commonjs/components/Option/renderOption.js +4 -7
  122. package/lib-commonjs/components/Option/renderOption.js.map +1 -1
  123. package/lib-commonjs/components/Option/useOption.js +20 -39
  124. package/lib-commonjs/components/Option/useOption.js.map +1 -1
  125. package/lib-commonjs/components/Option/useOptionStyles.js +74 -83
  126. package/lib-commonjs/components/Option/useOptionStyles.js.map +1 -1
  127. package/lib-commonjs/components/OptionGroup/OptionGroup.js +0 -6
  128. package/lib-commonjs/components/OptionGroup/OptionGroup.js.map +1 -1
  129. package/lib-commonjs/components/OptionGroup/OptionGroup.types.js.map +1 -1
  130. package/lib-commonjs/components/OptionGroup/index.js +0 -6
  131. package/lib-commonjs/components/OptionGroup/index.js.map +1 -1
  132. package/lib-commonjs/components/OptionGroup/renderOptionGroup.js +4 -7
  133. package/lib-commonjs/components/OptionGroup/renderOptionGroup.js.map +1 -1
  134. package/lib-commonjs/components/OptionGroup/useOptionGroup.js +0 -4
  135. package/lib-commonjs/components/OptionGroup/useOptionGroup.js.map +1 -1
  136. package/lib-commonjs/components/OptionGroup/useOptionGroupStyles.js +29 -38
  137. package/lib-commonjs/components/OptionGroup/useOptionGroupStyles.js.map +1 -1
  138. package/lib-commonjs/contexts/ComboboxContext.js +8 -13
  139. package/lib-commonjs/contexts/ComboboxContext.js.map +1 -1
  140. package/lib-commonjs/contexts/ListboxContext.js +6 -11
  141. package/lib-commonjs/contexts/ListboxContext.js.map +1 -1
  142. package/lib-commonjs/contexts/useComboboxContextValues.js +0 -2
  143. package/lib-commonjs/contexts/useComboboxContextValues.js.map +1 -1
  144. package/lib-commonjs/contexts/useListboxContextValues.js +2 -6
  145. package/lib-commonjs/contexts/useListboxContextValues.js.map +1 -1
  146. package/lib-commonjs/index.js +0 -20
  147. package/lib-commonjs/index.js.map +1 -1
  148. package/lib-commonjs/utils/ComboboxBase.types.js.map +1 -1
  149. package/lib-commonjs/utils/OptionCollection.types.js.map +1 -1
  150. package/lib-commonjs/utils/Selection.types.js.map +1 -1
  151. package/lib-commonjs/utils/dropdownKeyActions.js +12 -37
  152. package/lib-commonjs/utils/dropdownKeyActions.js.map +1 -1
  153. package/lib-commonjs/utils/internalTokens.js.map +1 -1
  154. package/lib-commonjs/utils/useComboboxBaseState.js +23 -33
  155. package/lib-commonjs/utils/useComboboxBaseState.js.map +1 -1
  156. package/lib-commonjs/utils/useComboboxPopup.js +6 -8
  157. package/lib-commonjs/utils/useComboboxPopup.js.map +1 -1
  158. package/lib-commonjs/utils/useOptionCollection.js +10 -23
  159. package/lib-commonjs/utils/useOptionCollection.js.map +1 -1
  160. package/lib-commonjs/utils/useScrollOptionsIntoView.js +2 -9
  161. package/lib-commonjs/utils/useScrollOptionsIntoView.js.map +1 -1
  162. package/lib-commonjs/utils/useSelection.js +7 -15
  163. package/lib-commonjs/utils/useSelection.js.map +1 -1
  164. package/lib-commonjs/utils/useTriggerListboxSlots.js +30 -43
  165. package/lib-commonjs/utils/useTriggerListboxSlots.js.map +1 -1
  166. package/package.json +9 -9
@@ -1 +1 @@
1
- {"version":3,"sources":["packages/react-components/react-combobox/src/components/Listbox/index.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,WAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,iBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,iBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,cAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,oBAAA,CAAA,EAAA,OAAA","sourcesContent":["export * from './Listbox';\nexport * from './Listbox.types';\nexport * from './renderListbox';\nexport * from './useListbox';\nexport * from './useListboxStyles';\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"mappings":";;;;;;AAAAA;AACAA;AACAA;AACAA;AACAA","names":["tslib_1"],"sourceRoot":"../src/","sources":["packages/react-components/react-combobox/src/components/Listbox/index.ts"],"sourcesContent":["export * from './Listbox';\nexport * from './Listbox.types';\nexport * from './renderListbox';\nexport * from './useListbox';\nexport * from './useListboxStyles';\n"]}
@@ -4,17 +4,12 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.renderListbox_unstable = void 0;
7
-
8
7
  const React = /*#__PURE__*/require("react");
9
-
10
8
  const react_utilities_1 = /*#__PURE__*/require("@fluentui/react-utilities");
11
-
12
9
  const ListboxContext_1 = /*#__PURE__*/require("../../contexts/ListboxContext");
13
10
  /**
14
11
  * Render the final JSX of Listbox
15
12
  */
16
-
17
-
18
13
  const renderListbox_unstable = (state, contextValues) => {
19
14
  const {
20
15
  slots,
@@ -22,9 +17,9 @@ const renderListbox_unstable = (state, contextValues) => {
22
17
  } = react_utilities_1.getSlots(state);
23
18
  return React.createElement(ListboxContext_1.ListboxContext.Provider, {
24
19
  value: contextValues.listbox
25
- }, React.createElement(slots.root, { ...slotProps.root
20
+ }, React.createElement(slots.root, {
21
+ ...slotProps.root
26
22
  }));
27
23
  };
28
-
29
24
  exports.renderListbox_unstable = renderListbox_unstable;
30
25
  //# sourceMappingURL=renderListbox.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["packages/react-components/react-combobox/src/components/Listbox/renderListbox.tsx"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AACA,MAAA,iBAAA,gBAAA,OAAA,CAAA,2BAAA,CAAA;;AAEA,MAAA,gBAAA,gBAAA,OAAA,CAAA,+BAAA,CAAA;AAEA;;AAEG;;;AACI,MAAM,sBAAsB,GAAG,CAAC,KAAD,EAAsB,aAAtB,KAA6D;EACjG,MAAM;IAAE,KAAF;IAAS;EAAT,IAAuB,iBAAA,CAAA,QAAA,CAAuB,KAAvB,CAA7B;EAEA,OACE,KAAA,CAAA,aAAA,CAAC,gBAAA,CAAA,cAAA,CAAe,QAAhB,EAAwB;IAAC,KAAK,EAAE,aAAa,CAAC;EAAtB,CAAxB,EACE,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,IAAP,EAAW,EAAA,GAAK,SAAS,CAAC;EAAf,CAAX,CADF,CADF;AAKD,CARM;;AAAM,OAAA,CAAA,sBAAA,GAAsB,sBAAtB","sourcesContent":["import * as React from 'react';\nimport { getSlots } from '@fluentui/react-utilities';\nimport type { ListboxContextValues, ListboxState, ListboxSlots } from './Listbox.types';\nimport { ListboxContext } from '../../contexts/ListboxContext';\n\n/**\n * Render the final JSX of Listbox\n */\nexport const renderListbox_unstable = (state: ListboxState, contextValues: ListboxContextValues) => {\n const { slots, slotProps } = getSlots<ListboxSlots>(state);\n\n return (\n <ListboxContext.Provider value={contextValues.listbox}>\n <slots.root {...slotProps.root} />\n </ListboxContext.Provider>\n );\n};\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"mappings":";;;;;;AAAA;AACA;AAEA;AAEA;;;AAGO,MAAMA,sBAAsB,GAAG,CAACC,KAAmB,EAAEC,aAAmC,KAAI;EACjG,MAAM;IAAEC,KAAK;IAAEC;EAAS,CAAE,GAAGC,0BAAQ,CAAeJ,KAAK,CAAC;EAE1D,OACEK,oBAACC,+BAAc,CAACC,QAAQ;IAACC,KAAK,EAAEP,aAAa,CAACQ;EAAO,GACnDJ,oBAACH,KAAK,CAACQ,IAAI;IAAA,GAAKP,SAAS,CAACO;EAAI,EAAI,CACV;AAE9B,CAAC;AARYC,8BAAsB","names":["renderListbox_unstable","state","contextValues","slots","slotProps","react_utilities_1","React","ListboxContext_1","Provider","value","listbox","root","exports"],"sourceRoot":"../src/","sources":["packages/react-components/react-combobox/src/components/Listbox/renderListbox.tsx"],"sourcesContent":["import * as React from 'react';\nimport { getSlots } from '@fluentui/react-utilities';\nimport type { ListboxContextValues, ListboxState, ListboxSlots } from './Listbox.types';\nimport { ListboxContext } from '../../contexts/ListboxContext';\n\n/**\n * Render the final JSX of Listbox\n */\nexport const renderListbox_unstable = (state: ListboxState, contextValues: ListboxContextValues) => {\n const { slots, slotProps } = getSlots<ListboxSlots>(state);\n\n return (\n <ListboxContext.Provider value={contextValues.listbox}>\n <slots.root {...slotProps.root} />\n </ListboxContext.Provider>\n );\n};\n"]}
@@ -4,21 +4,13 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.useListbox_unstable = void 0;
7
-
8
7
  const React = /*#__PURE__*/require("react");
9
-
10
8
  const react_utilities_1 = /*#__PURE__*/require("@fluentui/react-utilities");
11
-
12
9
  const react_context_selector_1 = /*#__PURE__*/require("@fluentui/react-context-selector");
13
-
14
10
  const dropdownKeyActions_1 = /*#__PURE__*/require("../../utils/dropdownKeyActions");
15
-
16
11
  const useOptionCollection_1 = /*#__PURE__*/require("../../utils/useOptionCollection");
17
-
18
12
  const useScrollOptionsIntoView_1 = /*#__PURE__*/require("../../utils/useScrollOptionsIntoView");
19
-
20
13
  const useSelection_1 = /*#__PURE__*/require("../../utils/useSelection");
21
-
22
14
  const ComboboxContext_1 = /*#__PURE__*/require("../../contexts/ComboboxContext");
23
15
  /**
24
16
  * Create the state required to render Listbox.
@@ -29,8 +21,6 @@ const ComboboxContext_1 = /*#__PURE__*/require("../../contexts/ComboboxContext")
29
21
  * @param props - props from this instance of Listbox
30
22
  * @param ref - reference to root HTMLElement of Listbox
31
23
  */
32
-
33
-
34
24
  const useListbox_unstable = (props, ref) => {
35
25
  const {
36
26
  multiselect
@@ -46,11 +36,10 @@ const useListbox_unstable = (props, ref) => {
46
36
  selectedOptions,
47
37
  selectOption
48
38
  } = useSelection_1.useSelection(props);
49
- const [activeOption, setActiveOption] = React.useState(); // track whether keyboard focus outline should be shown
39
+ const [activeOption, setActiveOption] = React.useState();
40
+ // track whether keyboard focus outline should be shown
50
41
  // tabster/keyborg doesn't work here, since the actual keyboard focus target doesn't move
51
-
52
42
  const [focusVisible, setFocusVisible] = React.useState(false);
53
-
54
43
  const onKeyDown = event => {
55
44
  const action = dropdownKeyActions_1.getDropdownActionFromKey(event, {
56
45
  open: true
@@ -58,17 +47,14 @@ const useListbox_unstable = (props, ref) => {
58
47
  const maxIndex = getCount() - 1;
59
48
  const activeIndex = activeOption ? getIndexOfId(activeOption.id) : -1;
60
49
  let newIndex = activeIndex;
61
-
62
50
  switch (action) {
63
51
  case 'Select':
64
52
  case 'CloseSelect':
65
53
  activeOption && selectOption(event, activeOption);
66
54
  break;
67
-
68
55
  default:
69
56
  newIndex = dropdownKeyActions_1.getIndexFromAction(action, activeIndex, maxIndex);
70
57
  }
71
-
72
58
  if (newIndex !== activeIndex) {
73
59
  // prevent default page scroll/keyboard action if the index changed
74
60
  event.preventDefault();
@@ -76,19 +62,17 @@ const useListbox_unstable = (props, ref) => {
76
62
  setFocusVisible(true);
77
63
  }
78
64
  };
79
-
80
65
  const onMouseOver = event => {
81
66
  setFocusVisible(false);
82
- }; // get state from parent combobox, if it exists
83
-
84
-
67
+ };
68
+ // get state from parent combobox, if it exists
85
69
  const hasComboboxContext = react_context_selector_1.useHasParentContext(ComboboxContext_1.ComboboxContext);
86
70
  const comboboxActiveOption = react_context_selector_1.useContextSelector(ComboboxContext_1.ComboboxContext, ctx => ctx.activeOption);
87
71
  const comboboxFocusVisible = react_context_selector_1.useContextSelector(ComboboxContext_1.ComboboxContext, ctx => ctx.focusVisible);
88
72
  const comboboxSelectedOptions = react_context_selector_1.useContextSelector(ComboboxContext_1.ComboboxContext, ctx => ctx.selectedOptions);
89
73
  const comboboxSelectOption = react_context_selector_1.useContextSelector(ComboboxContext_1.ComboboxContext, ctx => ctx.selectOption);
90
- const comboboxSetActiveOption = react_context_selector_1.useContextSelector(ComboboxContext_1.ComboboxContext, ctx => ctx.setActiveOption); // without a parent combobox context, provide values directly from Listbox
91
-
74
+ const comboboxSetActiveOption = react_context_selector_1.useContextSelector(ComboboxContext_1.ComboboxContext, ctx => ctx.setActiveOption);
75
+ // without a parent combobox context, provide values directly from Listbox
92
76
  const optionContextValues = hasComboboxContext ? {
93
77
  activeOption: comboboxActiveOption,
94
78
  focusVisible: comboboxFocusVisible,
@@ -125,6 +109,5 @@ const useListbox_unstable = (props, ref) => {
125
109
  state.root.onMouseOver = react_utilities_1.useEventCallback(react_utilities_1.mergeCallbacks(state.root.onMouseOver, onMouseOver));
126
110
  return state;
127
111
  };
128
-
129
112
  exports.useListbox_unstable = useListbox_unstable;
130
113
  //# sourceMappingURL=useListbox.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["packages/react-components/react-combobox/src/components/Listbox/useListbox.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AACA,M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backs, 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"],"sourceRoot":"../src/"}
1
+ {"version":3,"mappings":";;;;;;AAAA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AAGA;;;;;;;;;AASO,MAAMA,mBAAmB,GAAG,CAACC,KAAmB,EAAEC,GAA2B,KAAkB;EACpG,MAAM;IAAEC;EAAW,CAAE,GAAGF,KAAK;EAC7B,MAAMG,gBAAgB,GAAGC,yCAAmB,EAAE;EAC9C,MAAM;IAA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AGyC,+BAAa,CAACH,KAAK,CAACE,IAAI,CAACxC,GAAG,EAAE6C,kBAAkB,CAAC;EAElEP,KAAK,CAACE,IAAI,CAACvB,SAAS,GAAGwB,kCAAgB,CAACA,gCAAc,CAACH,KAAK,CAACE,IAAI,CAACvB,SAAS,EAAEA,SAAS,CAAC,CAAC;EACxFqB,KAAK,CAACE,IAAI,CAACb,WAAW,GAAGc,kCAAgB,CAACA,gCAAc,CAACH,KAAK,CAACE,IAAI,CAACb,WAAW,EAAEA,WAAW,CAAC,CAAC;EAE9F,OAAOW,KAAK;AACd,CAAC;AA1FYS,2BAAmB","names":["useListbox_unstable","props","ref","multiselect","optionCollection","useOptionCollection_1","getCount","getOptionAtIndex","getIndexOfId","clearSelection","selectedOptions","selectOption","useSelection_1","activeOption","setActiveOption","React","useState","focusVisible","setFocusVisible","onKeyDown","event","action","dropdownKeyActions_1","open","maxIndex","activeIndex","id","newIndex","preventDefault","onMouseOver","hasComboboxContext","react_context_selector_1","ComboboxContext_1","comboboxActiveOption","ctx","comboboxFocusVisible","comboboxSelectedOptions","comboboxSelectOption","comboboxSetActiveOption","optionContextValues","state","components","root","react_utilities_1","role","undefined","tabIndex","scrollContainerRef","useScrollOptionsIntoView_1","exports"],"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"]}
@@ -4,50 +4,43 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.useListboxStyles_unstable = exports.listboxClassNames = void 0;
7
-
8
7
  const react_theme_1 = /*#__PURE__*/require("@fluentui/react-theme");
9
-
10
8
  const react_1 = /*#__PURE__*/require("@griffel/react");
11
-
12
9
  exports.listboxClassNames = {
13
10
  root: 'fui-Listbox'
14
11
  };
15
12
  /**
16
13
  * Styles for the root slot
17
14
  */
18
-
19
15
  const useStyles = /*#__PURE__*/react_1.__styles({
20
- "root": {
21
- "E5pizo": "f1hg901r",
22
- "B7ck84d": "f1ewtqcl",
23
- "Bbmb7ep": ["f1aa9q02", "f16jpd5f"],
24
- "Beyfa6y": ["f16jpd5f", "f1aa9q02"],
25
- "B7oj6ja": ["f1jar5jt", "fyu767a"],
26
- "Btl43ni": ["fyu767a", "f1jar5jt"],
27
- "De3pzq": "fxugw4r",
28
- "mc9l5x": "f22iagw",
29
- "Beiy3e4": "f1vx9l62",
30
- "Bf4jedk": "f3hsy1e",
31
- "Bmxbyg5": "f5zp4f",
32
- "z8tnut": "f1x4af0m",
33
- "z189sj": ["f7x41pl", "fruq291"],
34
- "Byoj8tv": "fd55psn",
35
- "uwmqm3": ["fruq291", "f7x41pl"],
36
- "Belr9w4": "fiut8dr"
16
+ root: {
17
+ E5pizo: "f1hg901r",
18
+ B7ck84d: "f1ewtqcl",
19
+ Bbmb7ep: ["f1aa9q02", "f16jpd5f"],
20
+ Beyfa6y: ["f16jpd5f", "f1aa9q02"],
21
+ B7oj6ja: ["f1jar5jt", "fyu767a"],
22
+ Btl43ni: ["fyu767a", "f1jar5jt"],
23
+ De3pzq: "fxugw4r",
24
+ mc9l5x: "f22iagw",
25
+ Beiy3e4: "f1vx9l62",
26
+ Bf4jedk: "f3hsy1e",
27
+ Bmxbyg5: "f5zp4f",
28
+ z8tnut: "f1x4af0m",
29
+ z189sj: ["f7x41pl", "fruq291"],
30
+ Byoj8tv: "fd55psn",
31
+ uwmqm3: ["fruq291", "f7x41pl"],
32
+ Belr9w4: "fiut8dr"
37
33
  }
38
34
  }, {
39
- "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;}", ".f5zp4f{overflow-y:auto;}", ".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);}"]
35
+ 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;}", ".f5zp4f{overflow-y:auto;}", ".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);}"]
40
36
  });
41
37
  /**
42
38
  * Apply styling to the Listbox slots based on the state
43
39
  */
44
-
45
-
46
40
  const useListboxStyles_unstable = state => {
47
41
  const styles = useStyles();
48
42
  state.root.className = react_1.mergeClasses(exports.listboxClassNames.root, styles.root, state.root.className);
49
43
  return state;
50
44
  };
51
-
52
45
  exports.useListboxStyles_unstable = useListboxStyles_unstable;
53
46
  //# sourceMappingURL=useListboxStyles.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["packages/react-components/react-combobox/src/components/Listbox/useListboxStyles.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,aAAA,gBAAA,OAAA,CAAA,uBAAA,CAAA;;AAEA,MAAA,OAAA,gBAAA,OAAA,CAAA,gBAAA,CAAA;;AAGa,OAAA,CAAA,iBAAA,GAAkD;EAC7D,IAAI,EAAE;AADuD,CAAlD;AAIb;;AAEG;;AACH,MAAM,SAAS,gBAAG,OAAA,SAAA;EAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;EAAA;AAAA;EAAA;AAAA,EAAlB;AAeA;;AAEG;;;AACI,MAAM,yBAAyB,GAAI,KAAD,IAAsC;EAC7E,MAAM,MAAM,GAAG,SAAS,EAAxB;EACA,KAAK,CAAC,IAAN,CAAW,SAAX,GAAuB,OAAA,CAAA,YAAA,CAAa,OAAA,CAAA,iBAAA,CAAkB,IAA/B,EAAqC,MAAM,CAAC,IAA5C,EAAkD,KAAK,CAAC,IAAN,CAAW,SAA7D,CAAvB;EAEA,OAAO,KAAP;AACD,CALM;;AAAM,OAAA,CAAA,yBAAA,GAAyB,yBAAzB","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 overflowY: 'auto',\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;AAEA;AAGaA,yBAAiB,GAAiC;EAC7DC,IAAI,EAAE;CACP;AAED;;;AAGA,MAAMC,SAAS,gBAAGC,gBAAU;EAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;EAAA;AAAA;EAAA;AAAA,EAa1B;AAEF;;;AAGO,MAAMC,yBAAyB,GAAIC,KAAmB,IAAkB;EAC7E,MAAMC,MAAM,GAAGJ,SAAS,EAAE;EAC1BG,KAAK,CAACJ,IAAI,CAACM,SAAS,GAAGJ,oBAAY,CAACH,yBAAiB,CAACC,IAAI,EAAEK,MAAM,CAACL,IAAI,EAAEI,KAAK,CAACJ,IAAI,CAACM,SAAS,CAAC;EAE9F,OAAOF,KAAK;AACd,CAAC;AALYL,iCAAyB","names":["exports","root","useStyles","react_1","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 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 overflowY: 'auto',\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"]}
@@ -4,19 +4,13 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.Option = void 0;
7
-
8
7
  const React = /*#__PURE__*/require("react");
9
-
10
8
  const useOption_1 = /*#__PURE__*/require("./useOption");
11
-
12
9
  const renderOption_1 = /*#__PURE__*/require("./renderOption");
13
-
14
10
  const useOptionStyles_1 = /*#__PURE__*/require("./useOptionStyles");
15
11
  /**
16
12
  * Option component: a styled child option of a Combobox
17
13
  */
18
-
19
-
20
14
  exports.Option = /*#__PURE__*/React.forwardRef((props, ref) => {
21
15
  const state = useOption_1.useOption_unstable(props, ref);
22
16
  useOptionStyles_1.useOptionStyles_unstable(state);
@@ -1 +1 @@
1
- {"version":3,"sources":["packages/react-components/react-combobox/src/components/Option/Option.tsx"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AACA,MAAA,WAAA,gBAAA,OAAA,CAAA,aAAA,CAAA;;AACA,MAAA,cAAA,gBAAA,OAAA,CAAA,gBAAA,CAAA;;AACA,MAAA,iBAAA,gBAAA,OAAA,CAAA,mBAAA,CAAA;AAIA;;AAEG;;;AACU,OAAA,CAAA,MAAA,gBAA2C,KAAK,CAAC,UAAN,CAAiB,CAAC,KAAD,EAAQ,GAAR,KAAe;EACtF,MAAM,KAAK,GAAG,WAAA,CAAA,kBAAA,CAAmB,KAAnB,EAA0B,GAA1B,CAAd;EAEA,iBAAA,CAAA,wBAAA,CAAyB,KAAzB;EACA,OAAO,cAAA,CAAA,qBAAA,CAAsB,KAAtB,CAAP;AACD,CALuD,CAA3C;AAOb,OAAA,CAAA,MAAA,CAAO,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;AACA;AACA;AACA;AAIA;;;AAGaA,cAAM,gBAAqCC,KAAK,CAACC,UAAU,CAAC,CAACC,KAAK,EAAEC,GAAG,KAAI;EACtF,MAAMC,KAAK,GAAGC,8BAAkB,CAACH,KAAK,EAAEC,GAAG,CAAC;EAE5CG,0CAAwB,CAACF,KAAK,CAAC;EAC/B,OAAOG,oCAAqB,CAACH,KAAK,CAAC;AACrC,CAAC,CAAC;AAEFL,cAAM,CAACS,WAAW,GAAG,QAAQ","names":["exports","React","forwardRef","props","ref","state","useOption_1","useOptionStyles_1","renderOption_1","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,"sources":[],"names":[],"mappings":"","sourceRoot":"../src/"}
1
+ {"version":3,"mappings":"","names":[],"sourceRoot":"../src/","sources":[],"sourcesContent":[]}
@@ -3,16 +3,10 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
-
7
6
  const tslib_1 = /*#__PURE__*/require("tslib");
8
-
9
7
  tslib_1.__exportStar(require("./Option"), exports);
10
-
11
8
  tslib_1.__exportStar(require("./Option.types"), exports);
12
-
13
9
  tslib_1.__exportStar(require("./renderOption"), exports);
14
-
15
10
  tslib_1.__exportStar(require("./useOption"), exports);
16
-
17
11
  tslib_1.__exportStar(require("./useOptionStyles"), exports);
18
12
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["packages/react-components/react-combobox/src/components/Option/index.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,UAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,gBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,gBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,aAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,mBAAA,CAAA,EAAA,OAAA","sourcesContent":["export * from './Option';\nexport * from './Option.types';\nexport * from './renderOption';\nexport * from './useOption';\nexport * from './useOptionStyles';\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"mappings":";;;;;;AAAAA;AACAA;AACAA;AACAA;AACAA","names":["tslib_1"],"sourceRoot":"../src/","sources":["packages/react-components/react-combobox/src/components/Option/index.ts"],"sourcesContent":["export * from './Option';\nexport * from './Option.types';\nexport * from './renderOption';\nexport * from './useOption';\nexport * from './useOptionStyles';\n"]}
@@ -4,24 +4,21 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.renderOption_unstable = void 0;
7
-
8
7
  const React = /*#__PURE__*/require("react");
9
-
10
8
  const react_utilities_1 = /*#__PURE__*/require("@fluentui/react-utilities");
11
9
  /**
12
10
  * Render the final JSX of Option
13
11
  */
14
-
15
-
16
12
  const renderOption_unstable = state => {
17
13
  const {
18
14
  slots,
19
15
  slotProps
20
16
  } = react_utilities_1.getSlots(state);
21
- return React.createElement(slots.root, { ...slotProps.root
22
- }, React.createElement(slots.checkIcon, { ...slotProps.checkIcon
17
+ return React.createElement(slots.root, {
18
+ ...slotProps.root
19
+ }, React.createElement(slots.checkIcon, {
20
+ ...slotProps.checkIcon
23
21
  }), slotProps.root.children);
24
22
  };
25
-
26
23
  exports.renderOption_unstable = renderOption_unstable;
27
24
  //# sourceMappingURL=renderOption.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["packages/react-components/react-combobox/src/components/Option/renderOption.tsx"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AACA,MAAA,iBAAA,gBAAA,OAAA,CAAA,2BAAA,CAAA;AAGA;;AAEG;;;AACI,MAAM,qBAAqB,GAAI,KAAD,IAAuB;EAC1D,MAAM;IAAE,KAAF;IAAS;EAAT,IAAuB,iBAAA,CAAA,QAAA,CAAsB,KAAtB,CAA7B;EAEA,OACE,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;;AAAM,OAAA,CAAA,qBAAA,GAAqB,qBAArB","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;AACA;AAGA;;;AAGO,MAAMA,qBAAqB,GAAIC,KAAkB,IAAI;EAC1D,MAAM;IAAEC,KAAK;IAAEC;EAAS,CAAE,GAAGC,0BAAQ,CAAcH,KAAK,CAAC;EAEzD,OACEI,oBAACH,KAAK,CAACI,IAAI;IAAA,GAAKH,SAAS,CAACG;EAAI,GAC5BD,oBAACH,KAAK,CAACK,SAAS;IAAA,GAAKJ,SAAS,CAACI;EAAS,EAAI,EAC3CJ,SAAS,CAACG,IAAI,CAACE,QAAQ,CACb;AAEjB,CAAC;AATYC,6BAAqB","names":["renderOption_unstable","state","slots","slotProps","react_utilities_1","React","root","checkIcon","children","exports"],"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"]}
@@ -4,24 +4,16 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.useOption_unstable = void 0;
7
-
8
7
  const React = /*#__PURE__*/require("react");
9
-
10
8
  const react_utilities_1 = /*#__PURE__*/require("@fluentui/react-utilities");
11
-
12
9
  const react_context_selector_1 = /*#__PURE__*/require("@fluentui/react-context-selector");
13
-
14
10
  const react_icons_1 = /*#__PURE__*/require("@fluentui/react-icons");
15
-
16
11
  const ComboboxContext_1 = /*#__PURE__*/require("../../contexts/ComboboxContext");
17
-
18
12
  const ListboxContext_1 = /*#__PURE__*/require("../../contexts/ListboxContext");
19
-
20
13
  function getTextString(text, children) {
21
14
  if (text !== undefined) {
22
15
  return text;
23
16
  }
24
-
25
17
  let textString = '';
26
18
  let hasNonStringChild = false;
27
19
  React.Children.forEach(children, child => {
@@ -30,13 +22,12 @@ function getTextString(text, children) {
30
22
  } else {
31
23
  hasNonStringChild = true;
32
24
  }
33
- }); // warn if an Option has non-string children and no text prop
34
-
25
+ });
26
+ // warn if an Option has non-string children and no text prop
35
27
  if (hasNonStringChild) {
36
28
  // eslint-disable-next-line no-console
37
29
  console.warn('Provide a `text` prop to Option components when they contain non-string children.');
38
30
  }
39
-
40
31
  return textString;
41
32
  }
42
33
  /**
@@ -48,8 +39,6 @@ function getTextString(text, children) {
48
39
  * @param props - props from this instance of Option
49
40
  * @param ref - reference to root HTMLElement of Option
50
41
  */
51
-
52
-
53
42
  const useOption_unstable = (props, ref) => {
54
43
  const {
55
44
  children,
@@ -59,17 +48,17 @@ const useOption_unstable = (props, ref) => {
59
48
  } = props;
60
49
  const optionRef = React.useRef(null);
61
50
  const optionText = getTextString(text, children);
62
- const optionValue = value !== null && value !== void 0 ? value : optionText; // use the id if provided, otherwise use a generated id
63
-
64
- const id = react_utilities_1.useId('fluent-option', props.id); // data used for context registration & events
65
-
51
+ const optionValue = value !== null && value !== void 0 ? value : optionText;
52
+ // use the id if provided, otherwise use a generated id
53
+ const id = react_utilities_1.useId('fluent-option', props.id);
54
+ // data used for context registration & events
66
55
  const optionData = React.useMemo(() => ({
67
56
  id,
68
57
  disabled,
69
58
  text: optionText,
70
59
  value: optionValue
71
- }), [id, disabled, optionText, optionValue]); // context values
72
-
60
+ }), [id, disabled, optionText, optionValue]);
61
+ // context values
73
62
  const focusVisible = react_context_selector_1.useContextSelector(ListboxContext_1.ListboxContext, ctx => ctx.focusVisible);
74
63
  const multiselect = react_context_selector_1.useContextSelector(ListboxContext_1.ListboxContext, ctx => ctx.multiselect);
75
64
  const registerOption = react_context_selector_1.useContextSelector(ListboxContext_1.ListboxContext, ctx => ctx.registerOption);
@@ -79,41 +68,34 @@ const useOption_unstable = (props, ref) => {
79
68
  });
80
69
  const selectOption = react_context_selector_1.useContextSelector(ListboxContext_1.ListboxContext, ctx => ctx.selectOption);
81
70
  const setActiveOption = react_context_selector_1.useContextSelector(ListboxContext_1.ListboxContext, ctx => ctx.setActiveOption);
82
- const setOpen = react_context_selector_1.useContextSelector(ComboboxContext_1.ComboboxContext, ctx => ctx.setOpen); // current active option?
83
-
71
+ const setOpen = react_context_selector_1.useContextSelector(ComboboxContext_1.ComboboxContext, ctx => ctx.setOpen);
72
+ // current active option?
84
73
  const active = react_context_selector_1.useContextSelector(ListboxContext_1.ListboxContext, ctx => {
85
74
  var _a, _b;
86
-
87
75
  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;
88
- }); // check icon
89
-
76
+ });
77
+ // check icon
90
78
  let CheckIcon = React.createElement(react_icons_1.CheckmarkFilled, null);
91
-
92
79
  if (multiselect) {
93
80
  CheckIcon = selected ? React.createElement(react_icons_1.CheckboxCheckedFilled, null) : React.createElement(react_icons_1.CheckboxUncheckedFilled, null);
94
81
  }
95
-
96
82
  const onClick = event => {
97
83
  var _a;
98
-
99
84
  if (disabled) {
100
85
  event.preventDefault();
101
86
  return;
102
- } // clicked option should always become active option
103
-
104
-
105
- setActiveOption(optionData); // close on option click for single-select options in a combobox
106
-
87
+ }
88
+ // clicked option should always become active option
89
+ setActiveOption(optionData);
90
+ // close on option click for single-select options in a combobox
107
91
  if (!multiselect) {
108
92
  setOpen === null || setOpen === void 0 ? void 0 : setOpen(event, false);
109
- } // handle selection change
110
-
111
-
93
+ }
94
+ // handle selection change
112
95
  selectOption(event, optionData);
113
96
  (_a = props.onClick) === null || _a === void 0 ? void 0 : _a.call(props, event);
114
- }; // register option data with context
115
-
116
-
97
+ };
98
+ // register option data with context
117
99
  React.useEffect(() => {
118
100
  if (id && optionRef.current) {
119
101
  return registerOption(optionData, optionRef.current);
@@ -153,6 +135,5 @@ const useOption_unstable = (props, ref) => {
153
135
  selected
154
136
  };
155
137
  };
156
-
157
138
  exports.useOption_unstable = useOption_unstable;
158
139
  //# sourceMappingURL=useOption.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["packages/react-components/react-combobox/src/components/Option/useOption.tsx"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA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AAA,IAAA,CAAb,KAAa,EAAG,KAAH,CAAb;EACD,CAlBD,CAzCiG,CA6DjG;;;EACA,KAAK,CAAC,SAAN,CAAgB,MAAK;IACnB,IAAI,EAAE,IAAI,SAAS,CAAC,OAApB,EAA6B;MAC3B,OAAO,cAAc,CAAC,UAAD,EAAa,SAAS,CAAC,OAAvB,CAArB;IACD;EACF,CAJD,EAIG,CAAC,EAAD,EAAK,UAAL,EAAiB,cAAjB,CAJH;EAMA,MAAM,aAAa,GAAG,WAAW,GAC7B;IAAE,IAAI,EAAE,kBAAR;IAA4B,gBAAgB;EAA5C,CAD6B,GAE7B;IAAE,IAAI,EAAE,QAAR;IAAkB,iBAAiB;EAAnC,CAFJ;EAIA,OAAO;IACL,UAAU,EAAE;MACV,IAAI,EAAE,KADI;MAEV,SAAS,EAAE;IAFD,CADP;IAKL,IAAI,EAAE,iBAAA,CAAA,qBAAA,CAAsB,KAAtB,EAA6B;MACjC,GAAG,EAAE,iBAAA,CAAA,aAAA,CAAc,GAAd,EAAmB,SAAnB,CAD4B;MAEjC,iBAAiB,QAAQ,GAAG,MAAH,GAAY,SAFJ;MAGjC,EAHiC;MAIjC,GAAG,aAJ8B;MAKjC,GAAG,KAL8B;MAMjC;IANiC,CAA7B,CALD;IAaL,SAAS,EAAE,iBAAA,CAAA,gBAAA,CAAiB,KAAK,CAAC,SAAvB,EAAkC;MAC3C,QAAQ,EAAE,IADiC;MAE3C,YAAY,EAAE;QACZ,eAAe,MADH;QAEZ,QAAQ,EAAE;MAFE;IAF6B,CAAlC,CAbN;IAoBL,MApBK;IAqBL,QArBK;IAsBL,YAtBK;IAuBL,WAvBK;IAwBL;EAxBK,CAAP;AA0BD,CAlGM;;AAAM,OAAA,CAAA,kBAAA,GAAkB,kBAAlB","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 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 = <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 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"],"sourceRoot":"../src/"}
1
+ {"version":3,"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AAIA,SAASA,aAAa,CAACC,IAAwB,EAAEC,QAAyB;EACxE,IAAID,IAAI,KAAKE,SAAS,EAAE;IACtB,OAAOF,IAAI;;EAGb,IAAIG,UAAU,GAAG,EAAE;EACnB,IAAIC,iBAAiB,GAAG,KAAK;EAC7BC,KAAK,CAACC,QAAQ,CAACC,OAAO,CAACN,QAAQ,EAAEO,KAAK,IAAG;IACvC,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE;MAC7BL,UA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CAAC,MAAK;IACnB,IAAIzB,EAAE,IAAIJ,SAAS,CAAC8B,OAAO,EAAE;MAC3B,OAAOjB,cAAc,CAACP,UAAU,EAAEN,SAAS,CAAC8B,OAAO,CAAC;;EAExD,CAAC,EAAE,CAAC1B,EAAE,EAAEE,UAAU,EAAEO,cAAc,CAAC,CAAC;EAEpC,MAAMkB,aAAa,GAAGnB,WAAW,GAC7B;IAAEoB,IAAI,EAAE,kBAAkB;IAAE,cAAc,EAAElB;EAAQ,CAAE,GACtD;IAAEkB,IAAI,EAAE,QAAQ;IAAE,eAAe,EAAElB;EAAQ,CAAE;EAEjD,OAAO;IACLmB,UAAU,EAAE;MACVC,IAAI,EAAE,KAAK;MACXC,SAAS,EAAE;KACZ;IACDD,IAAI,EAAE7B,uCAAqB,CAAC,KAAK,EAAE;MACjCR,GAAG,EAAEQ,+BAAa,CAACR,GAAG,EAAEG,SAAS,CAAC;MAClC,eAAe,EAAEF,QAAQ,GAAG,MAAM,GAAGZ,SAAS;MAC9CkB,EAAE;MACF,GAAG2B,aAAa;MAChB,GAAGnC,KAAK;MACR8B;KACD,CAAC;IACFS,SAAS,EAAE9B,kCAAgB,CAACT,KAAK,CAACuC,SAAS,EAAE;MAC3CC,QAAQ,EAAE,IAAI;MACdC,YAAY,EAAE;QACZ,aAAa,EAAE,MAAM;QACrBpD,QAAQ,EAAEuC;;KAEb,CAAC;IACFF,MAAM;IACNxB,QAAQ;IACRU,YAAY;IACZI,WAAW;IACXE;GACD;AACH,CAAC;AAlGYwB,0BAAkB","names":["getTextString","text","children","undefined","textString","hasNonStringChild","React","Children","forEach","child","console","warn","useOption_unstable","props","ref","disabled","value","optionRef","useRef","optionText","optionValue","id","react_utilities_1","optionData","useMemo","focusVisible","react_context_selector_1","ListboxContext_1","ctx","multiselect","registerOption","selected","selectedOptions","find","o","selectOption","setActiveOption","setOpen","ComboboxContext_1","active","activeOption","CheckIcon","react_icons_1","onClick","event","preventDefault","useEffect","current","semanticProps","role","components","root","checkIcon","required","defaultProps","exports"],"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, 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 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 = <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 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"]}