@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
@@ -4,35 +4,26 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.useOptionCollection = void 0;
7
-
8
7
  const React = /*#__PURE__*/require("react");
9
8
  /**
10
9
  * A hook for managing a collection of child Options
11
10
  */
12
-
13
-
14
11
  const useOptionCollection = () => {
15
12
  const nodes = React.useRef([]);
16
13
  const collectionAPI = React.useMemo(() => {
17
14
  const getCount = () => nodes.current.length;
18
-
19
15
  const getOptionAtIndex = index => {
20
16
  var _a;
21
-
22
17
  return (_a = nodes.current[index]) === null || _a === void 0 ? void 0 : _a.option;
23
18
  };
24
-
25
19
  const getIndexOfId = id => nodes.current.findIndex(node => node.option.id === id);
26
-
27
20
  const getOptionById = id => {
28
21
  const item = nodes.current.find(node => node.option.id === id);
29
22
  return item === null || item === void 0 ? void 0 : item.option;
30
23
  };
31
-
32
24
  const getOptionsMatchingText = matcher => {
33
25
  return nodes.current.filter(node => matcher(node.option.text)).map(node => node.option);
34
26
  };
35
-
36
27
  return {
37
28
  getCount,
38
29
  getOptionAtIndex,
@@ -43,44 +34,40 @@ const useOptionCollection = () => {
43
34
  }, []);
44
35
  const registerOption = React.useCallback((option, element) => {
45
36
  var _a;
46
-
47
37
  const index = nodes.current.findIndex(node => {
48
38
  if (!node.element || !element) {
49
39
  return false;
50
40
  }
51
-
52
41
  if (node.option.id === option.id) {
53
42
  return true;
54
- } // use the DOM method compareDocumentPosition to order the current node against registered nodes
43
+ }
44
+ // use the DOM method compareDocumentPosition to order the current node against registered nodes
55
45
  // eslint-disable-next-line no-bitwise
56
-
57
-
58
46
  return node.element.compareDocumentPosition(element) & Node.DOCUMENT_POSITION_PRECEDING;
59
- }); // do not register the option if it already exists
60
-
47
+ });
48
+ // do not register the option if it already exists
61
49
  if (((_a = nodes.current[index]) === null || _a === void 0 ? void 0 : _a.option.id) !== option.id) {
62
50
  const newItem = {
63
51
  element,
64
52
  option
65
- }; // If an index is not found we will push the element to the end.
66
-
53
+ };
54
+ // If an index is not found we will push the element to the end.
67
55
  if (index === -1) {
68
56
  nodes.current = [...nodes.current, newItem];
69
57
  } else {
70
58
  nodes.current.splice(index, 0, newItem);
71
59
  }
72
- } // return the unregister function
73
-
74
-
60
+ }
61
+ // return the unregister function
75
62
  return () => {
76
63
  nodes.current = nodes.current.filter(node => node.option.id !== option.id);
77
64
  };
78
65
  }, []);
79
- return { ...collectionAPI,
66
+ return {
67
+ ...collectionAPI,
80
68
  options: nodes.current.map(node => node.option),
81
69
  registerOption
82
70
  };
83
71
  };
84
-
85
72
  exports.useOptionCollection = useOptionCollection;
86
73
  //# sourceMappingURL=useOptionCollection.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["packages/react-components/react-combobox/src/utils/useOptionCollection.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;AAGA;;AAEG;;;AACI,MAAM,mBAAmB,GAAG,MAA4B;EAC7D,MAAM,KAAK,GAAG,KAAK,CAAC,MAAN,CAA8D,EAA9D,CAAd;EAEA,MAAM,aAAa,GAAG,KAAK,CAAC,OAAN,CAAc,MAAK;IACvC,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,OAAN,CAAc,MAArC;;IACA,MAAM,gBAAgB,GAAI,KAAD,IAAkB;MAAA,IAAA,EAAA;;MAAC,OAAA,CAAA,EAAA,GAAA,KAAK,CAAC,OAAN,CAAc,KAAd,CAAA,MAAoB,IAApB,IAAoB,EAAA,KAAA,KAAA,CAApB,GAAoB,KAAA,CAApB,GAAoB,EAAA,CAAE,MAAtB;IAA4B,CAAxE;;IACA,MAAM,YAAY,GAAI,EAAD,IAAgB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,KAAK,CAAC,OAAN,CAAc,KAAd,CAAA,MAAoB,IAApB,IAAoB,EAAA,KAAA,KAAA,CAApB,GAAoB,KAAA,CAApB,GAAoB,EAAA,CAAE,MAAF,CAAS,EAA7B,MAAoC,MAAM,CAAC,EAA/C,EAAmD;MACjD,MAAM,OAAO,GAAG;QACd,OADc;QAEd;MAFc,CAAhB,CADiD,CAMjD;;MACA,IAAI,KAAK,KAAK,CAAC,CAAf,EAAkB;QAChB,KAAK,CAAC,OAAN,GAAgB,CAAC,GAAG,KAAK,CAAC,OAAV,EAAmB,OAAnB,CAAhB;MACD,CAFD,MAEO;QACL,KAAK,CAAC,OAAN,CAAc,MAAd,CAAqB,KAArB,EAA4B,CAA5B,EAA+B,OAA/B;MACD;IACF,CA5BoF,CA8BrF;;;IACA,OAAO,MAAK;MACV,KAAK,CAAC,OAAN,GAAgB,KAAK,CAAC,OAAN,CAAc,MAAd,CAAqB,IAAI,IAAI,IAAI,CAAC,MAAL,CAAY,EAAZ,KAAmB,MAAM,CAAC,EAAvD,CAAhB;IACD,CAFD;EAGD,CAlCsB,EAkCpB,EAlCoB,CAAvB;EAoCA,OAAO,EACL,GAAG,aADE;IAEL,OAAO,EAAE,KAAK,CAAC,OAAN,CAAc,GAAd,CAAkB,IAAI,IAAI,IAAI,CAAC,MAA/B,CAFJ;IAGL;EAHK,CAAP;AAKD,CAjEM;;AAAM,OAAA,CAAA,mBAAA,GAAmB,mBAAnB","sourcesContent":["import * as React from 'react';\nimport type { OptionCollectionState, OptionValue } from './OptionCollection.types';\n\n/**\n * A hook for managing a collection of child Options\n */\nexport const useOptionCollection = (): OptionCollectionState => {\n const nodes = React.useRef<{ option: OptionValue; element: HTMLElement }[]>([]);\n\n const collectionAPI = React.useMemo(() => {\n const getCount = () => nodes.current.length;\n const getOptionAtIndex = (index: number) => nodes.current[index]?.option;\n const getIndexOfId = (id: string) => nodes.current.findIndex(node => node.option.id === id);\n const getOptionById = (id: string) => {\n const item = nodes.current.find(node => node.option.id === id);\n return item?.option;\n };\n const getOptionsMatchingText = (matcher: (value: string) => boolean) => {\n return nodes.current.filter(node => matcher(node.option.text)).map(node => node.option);\n };\n\n return {\n getCount,\n getOptionAtIndex,\n getIndexOfId,\n getOptionById,\n getOptionsMatchingText,\n };\n }, []);\n\n const registerOption = React.useCallback((option: OptionValue, element: HTMLElement) => {\n const index = nodes.current.findIndex(node => {\n if (!node.element || !element) {\n return false;\n }\n\n if (node.option.id === option.id) {\n return true;\n }\n\n // use the DOM method compareDocumentPosition to order the current node against registered nodes\n // eslint-disable-next-line no-bitwise\n return node.element.compareDocumentPosition(element) & Node.DOCUMENT_POSITION_PRECEDING;\n });\n\n // do not register the option if it already exists\n if (nodes.current[index]?.option.id !== option.id) {\n const newItem = {\n element,\n option,\n };\n\n // If an index is not found we will push the element to the end.\n if (index === -1) {\n nodes.current = [...nodes.current, newItem];\n } else {\n nodes.current.splice(index, 0, newItem);\n }\n }\n\n // return the unregister function\n return () => {\n nodes.current = nodes.current.filter(node => node.option.id !== option.id);\n };\n }, []);\n\n return {\n ...collectionAPI,\n options: nodes.current.map(node => node.option),\n registerOption,\n };\n};\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"mappings":";;;;;;AAAA;AAGA;;;AAGO,MAAMA,mBAAmB,GAAG,MAA4B;EAC7D,MAAMC,KAAK,GAAGC,KAAK,CAACC,MAAM,CAAkD,EAAE,CAAC;EAE/E,MAAMC,aAAa,GAAGF,KAAK,CAACG,OAAO,CAAC,MAAK;IACvC,MAAMC,QAAQ,GAAG,MAAML,KAAK,CAACM,OAAO,CAACC,MAAM;IAC3C,MAAMC,gBAAgB,GAAIC,KAAa,IAAI;MAAA;MAAC,kBAAK,CAACH,OAAO,CAACG,KAAK,CAAC,0CAAEC,MAAM;IAAA;IACxE,MAAMC,YAAY,GAAIC,EAAU,IAAKZ,KAAK,CAACM,OAAO,CAACO,SAAS,CAACC,IAAI,IAAIA,IAAI,CAACJ,MAAM,CAACE,EAAE,KAAKA,EAA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CAAC,CAAC,EAAE;QAChBT,KAAK,CAACM,OAAO,GAAG,CAAC,GAAGN,KAAK,CAACM,OAAO,EAAEuB,OAAO,CAAC;OAC5C,MAAM;QACL7B,KAAK,CAACM,OAAO,CAACwB,MAAM,CAACrB,KAAK,EAAE,CAAC,EAAEoB,OAAO,CAAC;;;IAI3C;IACA,OAAO,MAAK;MACV7B,KAAK,CAACM,OAAO,GAAGN,KAAK,CAACM,OAAO,CAACc,MAAM,CAACN,IAAI,IAAIA,IAAI,CAACJ,MAAM,CAACE,EAAE,KAAKF,MAAM,CAACE,EAAE,CAAC;IAC5E,CAAC;EACH,CAAC,EAAE,EAAE,CAAC;EAEN,OAAO;IACL,GAAGT,aAAa;IAChB4B,OAAO,EAAE/B,KAAK,CAACM,OAAO,CAACgB,GAAG,CAACR,IAAI,IAAIA,IAAI,CAACJ,MAAM,CAAC;IAC/Ca;GACD;AACH,CAAC;AAjEYS,2BAAmB","names":["useOptionCollection","nodes","React","useRef","collectionAPI","useMemo","getCount","current","length","getOptionAtIndex","index","option","getIndexOfId","id","findIndex","node","getOptionById","item","find","getOptionsMatchingText","matcher","filter","text","map","registerOption","useCallback","element","compareDocumentPosition","Node","DOCUMENT_POSITION_PRECEDING","newItem","splice","options","exports"],"sourceRoot":"../src/","sources":["packages/react-components/react-combobox/src/utils/useOptionCollection.ts"],"sourcesContent":["import * as React from 'react';\nimport type { OptionCollectionState, OptionValue } from './OptionCollection.types';\n\n/**\n * A hook for managing a collection of child Options\n */\nexport const useOptionCollection = (): OptionCollectionState => {\n const nodes = React.useRef<{ option: OptionValue; element: HTMLElement }[]>([]);\n\n const collectionAPI = React.useMemo(() => {\n const getCount = () => nodes.current.length;\n const getOptionAtIndex = (index: number) => nodes.current[index]?.option;\n const getIndexOfId = (id: string) => nodes.current.findIndex(node => node.option.id === id);\n const getOptionById = (id: string) => {\n const item = nodes.current.find(node => node.option.id === id);\n return item?.option;\n };\n const getOptionsMatchingText = (matcher: (value: string) => boolean) => {\n return nodes.current.filter(node => matcher(node.option.text)).map(node => node.option);\n };\n\n return {\n getCount,\n getOptionAtIndex,\n getIndexOfId,\n getOptionById,\n getOptionsMatchingText,\n };\n }, []);\n\n const registerOption = React.useCallback((option: OptionValue, element: HTMLElement) => {\n const index = nodes.current.findIndex(node => {\n if (!node.element || !element) {\n return false;\n }\n\n if (node.option.id === option.id) {\n return true;\n }\n\n // use the DOM method compareDocumentPosition to order the current node against registered nodes\n // eslint-disable-next-line no-bitwise\n return node.element.compareDocumentPosition(element) & Node.DOCUMENT_POSITION_PRECEDING;\n });\n\n // do not register the option if it already exists\n if (nodes.current[index]?.option.id !== option.id) {\n const newItem = {\n element,\n option,\n };\n\n // If an index is not found we will push the element to the end.\n if (index === -1) {\n nodes.current = [...nodes.current, newItem];\n } else {\n nodes.current.splice(index, 0, newItem);\n }\n }\n\n // return the unregister function\n return () => {\n nodes.current = nodes.current.filter(node => node.option.id !== option.id);\n };\n }, []);\n\n return {\n ...collectionAPI,\n options: nodes.current.map(node => node.option),\n registerOption,\n };\n};\n"]}
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.useScrollOptionsIntoView = 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
  function useScrollOptionsIntoView(state) {
13
10
  const {
14
11
  activeOption
@@ -17,11 +14,9 @@ function useScrollOptionsIntoView(state) {
17
14
  React.useEffect(() => {
18
15
  if (scrollContainerRef.current && activeOption && react_utilities_1.canUseDOM()) {
19
16
  const activeOptionElement = scrollContainerRef.current.querySelector(`#${activeOption.id}`);
20
-
21
17
  if (!activeOptionElement) {
22
18
  return;
23
19
  }
24
-
25
20
  const {
26
21
  offsetHeight,
27
22
  offsetTop
@@ -31,11 +26,10 @@ function useScrollOptionsIntoView(state) {
31
26
  scrollTop
32
27
  } = scrollContainerRef.current;
33
28
  const isAbove = offsetTop < scrollTop;
34
- const isBelow = offsetTop + offsetHeight > scrollTop + parentOffsetHeight; // add a small buffer for general visual nicety
29
+ const isBelow = offsetTop + offsetHeight > scrollTop + parentOffsetHeight;
30
+ // add a small buffer for general visual nicety
35
31
  // it looks slightly better if the option has some space from the top/bottom while arrowing
36
-
37
32
  const buffer = 2;
38
-
39
33
  if (isAbove) {
40
34
  scrollContainerRef.current.scrollTo(0, offsetTop - buffer);
41
35
  } else if (isBelow) {
@@ -45,6 +39,5 @@ function useScrollOptionsIntoView(state) {
45
39
  }, [activeOption]);
46
40
  return scrollContainerRef;
47
41
  }
48
-
49
42
  exports.useScrollOptionsIntoView = useScrollOptionsIntoView;
50
43
  //# sourceMappingURL=useScrollOptionsIntoView.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["packages/react-components/react-combobox/src/utils/useScrollOptionsIntoView.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AACA,MAAA,iBAAA,gBAAA,OAAA,CAAA,2BAAA,CAAA;;AAGA,SAAgB,wBAAhB,CAAyC,KAAzC,EAA4D;EAC1D,MAAM;IAAE;EAAF,IAAmB,KAAzB;EACA,MAAM,kBAAkB,GAAG,KAAK,CAAC,MAAN,CAA6B,IAA7B,CAA3B;EAEA,KAAK,CAAC,SAAN,CAAgB,MAAK;IACnB,IAAI,kBAAkB,CAAC,OAAnB,IAA8B,YAA9B,IAA8C,iBAAA,CAAA,SAAA,EAAlD,EAA+D;MAC7D,MAAM,mBAAmB,GAAG,kBAAkB,CAAC,OAAnB,CAA2B,aAA3B,CAAyC,IAAI,YAAY,CAAC,EAAE,EAA5D,CAA5B;;MAEA,IAAI,CAAC,mBAAL,EAA0B;QACxB;MACD;;MAED,MAAM;QAAE,YAAF;QAAgB;MAAhB,IAA8B,mBAApC;MACA,MAAM;QAAE,YAAY,EAAE,kBAAhB;QAAoC;MAApC,IAAkD,kBAAkB,CAAC,OAA3E;MAEA,MAAM,OAAO,GAAG,SAAS,GAAG,SAA5B;MACA,MAAM,OAAO,GAAG,SAAS,GAAG,YAAZ,GAA2B,SAAS,GAAG,kBAAvD,CAX6D,CAa7D;MACA;;MACA,MAAM,MAAM,GAAG,CAAf;;MAEA,IAAI,OAAJ,EAAa;QACX,kBAAkB,CAAC,OAAnB,CAA2B,QAA3B,CAAoC,CAApC,EAAuC,SAAS,GAAG,MAAnD;MACD,CAFD,MAEO,IAAI,OAAJ,EAAa;QAClB,kBAAkB,CAAC,OAAnB,CAA2B,QAA3B,CAAoC,CAApC,EAAuC,SAAS,GAAG,kBAAZ,GAAiC,YAAjC,GAAgD,MAAvF;MACD;IACF;EACF,CAxBD,EAwBG,CAAC,YAAD,CAxBH;EA0BA,OAAO,kBAAP;AACD;;AA/BD,OAAA,CAAA,wBAAA,GAAA,wBAAA","sourcesContent":["import * as React from 'react';\nimport { canUseDOM } from '@fluentui/react-utilities';\nimport { ListboxState } from '../Listbox';\n\nexport function useScrollOptionsIntoView(state: ListboxState): React.Ref<HTMLDivElement> {\n const { activeOption } = state;\n const scrollContainerRef = React.useRef<HTMLDivElement>(null);\n\n React.useEffect(() => {\n if (scrollContainerRef.current && activeOption && canUseDOM()) {\n const activeOptionElement = scrollContainerRef.current.querySelector(`#${activeOption.id}`) as HTMLElement;\n\n if (!activeOptionElement) {\n return;\n }\n\n const { offsetHeight, offsetTop } = activeOptionElement;\n const { offsetHeight: parentOffsetHeight, scrollTop } = scrollContainerRef.current;\n\n const isAbove = offsetTop < scrollTop;\n const isBelow = offsetTop + offsetHeight > scrollTop + parentOffsetHeight;\n\n // add a small buffer for general visual nicety\n // it looks slightly better if the option has some space from the top/bottom while arrowing\n const buffer = 2;\n\n if (isAbove) {\n scrollContainerRef.current.scrollTo(0, offsetTop - buffer);\n } else if (isBelow) {\n scrollContainerRef.current.scrollTo(0, offsetTop - parentOffsetHeight + offsetHeight + buffer);\n }\n }\n }, [activeOption]);\n\n return scrollContainerRef;\n}\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"mappings":";;;;;;AAAA;AACA;AAGA,SAAgBA,wBAAwB,CAACC,KAAmB;EAC1D,MAAM;IAAEC;EAAY,CAAE,GAAGD,KAAK;EAC9B,MAAME,kBAAkB,GAAGC,KAAK,CAACC,MAAM,CAAiB,IAAI,CAAC;EAE7DD,KAAK,CAACE,SAAS,CAAC,MAAK;IACnB,IAAIH,kBAAkB,CAACI,OAAO,IAAIL,YAAY,IAAIM,2BAAS,EAAE,EAAE;MAC7D,MAAMC,mBAAmB,GAAGN,kBAAkB,CAACI,OAAO,CAACG,aAAa,CAAC,IAAIR,YAAY,CAACS,EAAE,EAAE,CAAgB;MAE1G,IAAI,CAACF,mBAAmB,EAAE;QACxB;;MAGF,MAAM;QAAEG,YAAY;QAAEC;MAAS,CAAE,GAAGJ,mBAAmB;MACvD,MAAM;QAAEG,YAAY,EAAEE,kBAAkB;QAAEC;MAAS,CAAE,GAAGZ,kBAAkB,CAACI,OAAO;MAElF,MAAMS,OAAO,GAAGH,SAAS,GAAGE,SAAS;MACrC,MAAME,OAAO,GAAGJ,SAAS,GAAGD,YAAY,GAAGG,SAAS,GAAGD,kBAAkB;MAEzE;MACA;MACA,MAAMI,MAAM,GAAG,CAAC;MAEhB,IAAIF,OAAO,EAAE;QACXb,kBAAkB,CAACI,OAAO,CAACY,QAAQ,CAAC,CAAC,EAAEN,SAAS,GAAGK,MAAM,CAAC;OAC3D,MAAM,IAAID,OAAO,EAAE;QAClBd,kBAAkB,CAACI,OAAO,CAACY,QAAQ,CAAC,CAAC,EAAEN,SAAS,GAAGC,kBAAkB,GAAGF,YAAY,GAAGM,MAAM,CAAC;;;EAGpG,CAAC,EAAE,CAAChB,YAAY,CAAC,CAAC;EAElB,OAAOC,kBAAkB;AAC3B;AA/BAiB","names":["useScrollOptionsIntoView","state","activeOption","scrollContainerRef","React","useRef","useEffect","current","react_utilities_1","activeOptionElement","querySelector","id","offsetHeight","offsetTop","parentOffsetHeight","scrollTop","isAbove","isBelow","buffer","scrollTo","exports"],"sourceRoot":"../src/","sources":["packages/react-components/react-combobox/src/utils/useScrollOptionsIntoView.ts"],"sourcesContent":["import * as React from 'react';\nimport { canUseDOM } from '@fluentui/react-utilities';\nimport { ListboxState } from '../Listbox';\n\nexport function useScrollOptionsIntoView(state: ListboxState): React.Ref<HTMLDivElement> {\n const { activeOption } = state;\n const scrollContainerRef = React.useRef<HTMLDivElement>(null);\n\n React.useEffect(() => {\n if (scrollContainerRef.current && activeOption && canUseDOM()) {\n const activeOptionElement = scrollContainerRef.current.querySelector(`#${activeOption.id}`) as HTMLElement;\n\n if (!activeOptionElement) {\n return;\n }\n\n const { offsetHeight, offsetTop } = activeOptionElement;\n const { offsetHeight: parentOffsetHeight, scrollTop } = scrollContainerRef.current;\n\n const isAbove = offsetTop < scrollTop;\n const isBelow = offsetTop + offsetHeight > scrollTop + parentOffsetHeight;\n\n // add a small buffer for general visual nicety\n // it looks slightly better if the option has some space from the top/bottom while arrowing\n const buffer = 2;\n\n if (isAbove) {\n scrollContainerRef.current.scrollTo(0, offsetTop - buffer);\n } else if (isBelow) {\n scrollContainerRef.current.scrollTo(0, offsetTop - parentOffsetHeight + offsetHeight + buffer);\n }\n }\n }, [activeOption]);\n\n return scrollContainerRef;\n}\n"]}
@@ -4,9 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.useSelection = void 0;
7
-
7
+ const react_1 = /*#__PURE__*/require("react");
8
8
  const react_utilities_1 = /*#__PURE__*/require("@fluentui/react-utilities");
9
-
10
9
  const useSelection = props => {
11
10
  const {
12
11
  defaultSelectedOptions,
@@ -18,19 +17,16 @@ const useSelection = props => {
18
17
  defaultState: defaultSelectedOptions,
19
18
  initialState: []
20
19
  });
21
-
22
- const selectOption = (event, option) => {
20
+ const selectOption = react_1.useCallback((event, option) => {
23
21
  // if the option is disabled, do nothing
24
22
  if (option.disabled) {
25
23
  return;
26
- } // for single-select, always return the selected option
27
-
28
-
29
- let newSelection = [option.value]; // toggle selected state of the option for multiselect
30
-
24
+ }
25
+ // for single-select, always return the selected option
26
+ let newSelection = [option.value];
27
+ // toggle selected state of the option for multiselect
31
28
  if (multiselect) {
32
29
  const selectedIndex = selectedOptions.findIndex(o => o === option.value);
33
-
34
30
  if (selectedIndex > -1) {
35
31
  // deselect option
36
32
  newSelection = [...selectedOptions.slice(0, selectedIndex), ...selectedOptions.slice(selectedIndex + 1)];
@@ -39,15 +35,13 @@ const useSelection = props => {
39
35
  newSelection = [...selectedOptions, option.value];
40
36
  }
41
37
  }
42
-
43
38
  setSelectedOptions(newSelection);
44
39
  onOptionSelect === null || onOptionSelect === void 0 ? void 0 : onOptionSelect(event, {
45
40
  optionValue: option.value,
46
41
  optionText: option.text,
47
42
  selectedOptions: newSelection
48
43
  });
49
- };
50
-
44
+ }, [onOptionSelect, multiselect, selectedOptions, setSelectedOptions]);
51
45
  const clearSelection = event => {
52
46
  setSelectedOptions([]);
53
47
  onOptionSelect === null || onOptionSelect === void 0 ? void 0 : onOptionSelect(event, {
@@ -56,13 +50,11 @@ const useSelection = props => {
56
50
  selectedOptions: []
57
51
  });
58
52
  };
59
-
60
53
  return {
61
54
  clearSelection,
62
55
  selectOption,
63
56
  selectedOptions
64
57
  };
65
58
  };
66
-
67
59
  exports.useSelection = useSelection;
68
60
  //# sourceMappingURL=useSelection.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["packages/react-components/react-combobox/src/utils/useSelection.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,iBAAA,gBAAA,OAAA,CAAA,2BAAA,CAAA;;AAIO,MAAM,YAAY,GAAI,KAAD,IAA0C;EACpE,MAAM;IAAE,sBAAF;IAA0B,WAA1B;IAAuC;EAAvC,IAA0D,KAAhE;EAEA,MAAM,CAAC,eAAD,EAAkB,kBAAlB,IAAwC,iBAAA,CAAA,oBAAA,CAAqB;IACjE,KAAK,EAAE,KAAK,CAAC,eADoD;IAEjE,YAAY,EAAE,sBAFmD;IAGjE,YA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;IAAgC;EAAhC,CAAP;AACD,CAxCM;;AAAM,OAAA,CAAA,YAAA,GAAY,YAAZ","sourcesContent":["import { useControllableState } from '@fluentui/react-utilities';\nimport { OptionValue } from './OptionCollection.types';\nimport { SelectionEvents, SelectionProps, SelectionState } from './Selection.types';\n\nexport const useSelection = (props: SelectionProps): SelectionState => {\n const { defaultSelectedOptions, multiselect, onOptionSelect } = props;\n\n const [selectedOptions, setSelectedOptions] = useControllableState({\n state: props.selectedOptions,\n defaultState: defaultSelectedOptions,\n initialState: [],\n });\n\n const selectOption = (event: SelectionEvents, option: OptionValue) => {\n // if the option is disabled, do nothing\n if (option.disabled) {\n return;\n }\n\n // for single-select, always return the selected option\n let newSelection = [option.value];\n\n // toggle selected state of the option for multiselect\n if (multiselect) {\n const selectedIndex = selectedOptions.findIndex(o => o === option.value);\n if (selectedIndex > -1) {\n // deselect option\n newSelection = [...selectedOptions.slice(0, selectedIndex), ...selectedOptions.slice(selectedIndex + 1)];\n } else {\n // select option\n newSelection = [...selectedOptions, option.value];\n }\n }\n\n setSelectedOptions(newSelection);\n onOptionSelect?.(event, { optionValue: option.value, optionText: option.text, selectedOptions: newSelection });\n };\n\n const clearSelection = (event: SelectionEvents) => {\n setSelectedOptions([]);\n onOptionSelect?.(event, { optionValue: undefined, optionText: undefined, selectedOptions: [] });\n };\n\n return { clearSelection, selectOption, selectedOptions };\n};\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"mappings":";;;;;;AAAA;AACA;AAIO,MAAMA,YAAY,GAAIC,KAAqB,IAAoB;EACpE,MAAM;IAAEC,sBAAsB;IAAEC,WAAW;IAAEC;EAAc,CAAE,GAAGH,KAAK;EAErE,MAAM,CAACI,eAAe,EAAEC,kBAAkB,CAAC,GAAGC,sCAAoB,CAAC;IACjEC,KAAK,EAAEP,KAAK,CAACI,eAAe;IAC5BI,YAAY,EAAEP,sBAAsB;IACpCQ,YAAY,EAAE;GACf,CAAC;EAEF,MAAMC,YAAY,GAAGC,mBAAW,CAC9B,CAACC,KAAsB,EAAEC,MAAmB,KAAI;IAC9C;IACA,IAAIA,MAAM,CAACC,QAAQ,EAAE;MACnB;;IAGF;IACA,IAAIC,YAAY,GAAG,CAACF,MAAM,CAACG,KAAK,CAAC;IAEjC;IACA,IAAId,WAAW,EAAE;MACf,MAAMe,aAAa,GAAGb,eAAe,CAACc,SAAS,CAACC,CAAC,IAAIA,CAAC,KAAKN,MAAM,CAACG,KAAK,CAAC;MACxE,IAAIC,aAAa,GAAG,CAAC,CAAC,EAAE;QACtB;QACAF,YAAY,GAAG,CAAC,GAAGX,eAAe,CAACgB,KAAK,CAAC,CAAC,EAAEH,aAAa,CAAC,EAAE,GAAGb,eAAe,CAACgB,KAAK,CAACH,aAAa,GAAG,CAAC,CAAC,CAAC;OACzG,MAAM;QACL;QACAF,YAAY,GAAG,CAAC,GAAGX,eAAe,EAAES,MAAM,CAACG,KAAK,CAAC;;;IAIrDX,kBAAkB,CAACU,YAAY,CAAC;IAChCZ,cAAc,aAAdA,cAAc,uBAAdA,cAAc,CAAGS,KAAK,EAAE;MAAES,WAAW,EAAER,MAAM,CAACG,KAAK;MAAEM,UAAU,EAAET,MAAM,CAACU,IAAI;MAAEnB,eAAe,EAAEW;IAAY,CAAE,CAAC;EAChH,CAAC,EACD,CAACZ,cAAc,EAAED,WAAW,EAAEE,eAAe,EAAEC,kBAAkB,CAAC,CACnE;EAED,MAAMmB,cAAc,GAAIZ,KAAsB,IAAI;IAChDP,kBAAkB,CAAC,EAAE,CAAC;IACtBF,cAAc,aAAdA,cAAc,uBAAdA,cAAc,CAAGS,KAAK,EAAE;MAAES,WAAW,EAAEI,SAAS;MAAEH,UAAU,EAAEG,SAAS;MAAErB,eAAe,EAAE;IAAE,CAAE,CAAC;EACjG,CAAC;EAED,OAAO;IAAEoB,cAAc;IAAEd,YAAY;IAAEN;EAAe,CAAE;AAC1D,CAAC;AA3CYsB,oBAAY","names":["useSelection","props","defaultSelectedOptions","multiselect","onOptionSelect","selectedOptions","setSelectedOptions","react_utilities_1","state","defaultState","initialState","selectOption","react_1","event","option","disabled","newSelection","value","selectedIndex","findIndex","o","slice","optionValue","optionText","text","clearSelection","undefined","exports"],"sourceRoot":"../src/","sources":["packages/react-components/react-combobox/src/utils/useSelection.ts"],"sourcesContent":["import { useCallback } from 'react';\nimport { useControllableState } from '@fluentui/react-utilities';\nimport { OptionValue } from './OptionCollection.types';\nimport { SelectionEvents, SelectionProps, SelectionState } from './Selection.types';\n\nexport const useSelection = (props: SelectionProps): SelectionState => {\n const { defaultSelectedOptions, multiselect, onOptionSelect } = props;\n\n const [selectedOptions, setSelectedOptions] = useControllableState({\n state: props.selectedOptions,\n defaultState: defaultSelectedOptions,\n initialState: [],\n });\n\n const selectOption = useCallback(\n (event: SelectionEvents, option: OptionValue) => {\n // if the option is disabled, do nothing\n if (option.disabled) {\n return;\n }\n\n // for single-select, always return the selected option\n let newSelection = [option.value];\n\n // toggle selected state of the option for multiselect\n if (multiselect) {\n const selectedIndex = selectedOptions.findIndex(o => o === option.value);\n if (selectedIndex > -1) {\n // deselect option\n newSelection = [...selectedOptions.slice(0, selectedIndex), ...selectedOptions.slice(selectedIndex + 1)];\n } else {\n // select option\n newSelection = [...selectedOptions, option.value];\n }\n }\n\n setSelectedOptions(newSelection);\n onOptionSelect?.(event, { optionValue: option.value, optionText: option.text, selectedOptions: newSelection });\n },\n [onOptionSelect, multiselect, selectedOptions, setSelectedOptions],\n );\n\n const clearSelection = (event: SelectionEvents) => {\n setSelectedOptions([]);\n onOptionSelect?.(event, { optionValue: undefined, optionText: undefined, selectedOptions: [] });\n };\n\n return { clearSelection, selectOption, selectedOptions };\n};\n"]}
@@ -4,19 +4,14 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.useTriggerListboxSlots = 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 dropdownKeyActions_1 = /*#__PURE__*/require("../utils/dropdownKeyActions");
13
10
  /*
14
11
  * useTriggerListboxSlots returns a tuple of trigger/listbox shorthand,
15
12
  * with the semantics and event handlers needed for the Combobox and Dropdown components.
16
13
  * The element type of the ref should always match the element type used in the trigger shorthand.
17
14
  */
18
-
19
-
20
15
  function useTriggerListboxSlots(props, state, ref, triggerSlot, listboxSlot) {
21
16
  const {
22
17
  multiselect
@@ -33,16 +28,16 @@ function useTriggerListboxSlots(props, state, ref, triggerSlot, listboxSlot) {
33
28
  setFocusVisible,
34
29
  setHasFocus,
35
30
  setOpen
36
- } = state; // handle trigger focus/blur
37
-
38
- const triggerRef = React.useRef(null); // resolve listbox shorthand props
39
-
31
+ } = state;
32
+ // handle trigger focus/blur
33
+ const triggerRef = React.useRef(null);
34
+ // resolve listbox shorthand props
40
35
  const listbox = listboxSlot && {
41
36
  multiselect,
42
37
  tabIndex: undefined,
43
38
  ...listboxSlot
44
- }; // resolve trigger shorthand props
45
-
39
+ };
40
+ // resolve trigger shorthand props
46
41
  const trigger = {
47
42
  'aria-expanded': open,
48
43
  'aria-activedescendant': open ? activeOption === null || activeOption === void 0 ? void 0 : activeOption.id : undefined,
@@ -52,33 +47,33 @@ function useTriggerListboxSlots(props, state, ref, triggerSlot, listboxSlot) {
52
47
  // since the `children` prop has mutually incompatible types between input/button
53
48
  // functionally both ref and triggerRef will always be the same element type
54
49
  ref: react_utilities_1.useMergedRefs(ref, triggerSlot === null || triggerSlot === void 0 ? void 0 : triggerSlot.ref, triggerRef)
55
- }; // listbox is nullable, only add event handlers if it exists
56
-
50
+ };
51
+ /*
52
+ * Handle focus when clicking the listbox popup:
53
+ * 1. Move focus back to the button/input when the listbox is clicked (otherwise it goes to body)
54
+ * 2. Do not close the listbox on button/input blur when clicking into the listbox
55
+ */
56
+ const listboxOnClick = react_utilities_1.useEventCallback(react_utilities_1.mergeCallbacks(event => {
57
+ var _a;
58
+ (_a = triggerRef.current) === null || _a === void 0 ? void 0 : _a.focus();
59
+ }, listbox === null || listbox === void 0 ? void 0 : listbox.onClick));
60
+ const listboxOnMouseOver = react_utilities_1.useEventCallback(react_utilities_1.mergeCallbacks(event => {
61
+ setFocusVisible(false);
62
+ }, listbox === null || listbox === void 0 ? void 0 : listbox.onMouseOver));
63
+ const listboxOnMouseDown = react_utilities_1.useEventCallback(react_utilities_1.mergeCallbacks(event => {
64
+ ignoreNextBlur.current = true;
65
+ }, listbox === null || listbox === void 0 ? void 0 : listbox.onMouseDown));
66
+ // listbox is nullable, only add event handlers if it exists
57
67
  if (listbox) {
58
- /*
59
- * Handle focus when clicking the listbox popup:
60
- * 1. Move focus back to the button/input when the listbox is clicked (otherwise it goes to body)
61
- * 2. Do not close the listbox on button/input blur when clicking into the listbox
62
- */
63
- listbox.onClick = react_utilities_1.mergeCallbacks(event => {
64
- var _a;
65
-
66
- (_a = triggerRef.current) === null || _a === void 0 ? void 0 : _a.focus();
67
- }, listbox.onClick);
68
- listbox.onMouseOver = react_utilities_1.mergeCallbacks(event => {
69
- setFocusVisible(false);
70
- }, listbox.onMouseOver);
71
- listbox.onMouseDown = react_utilities_1.mergeCallbacks(event => {
72
- ignoreNextBlur.current = true;
73
- }, listbox.onMouseDown);
74
- } // the trigger should open/close the popup on click or blur
75
-
76
-
68
+ listbox.onClick = listboxOnClick;
69
+ listbox.onMouseOver = listboxOnMouseOver;
70
+ listbox.onMouseDown = listboxOnMouseDown;
71
+ }
72
+ // the trigger should open/close the popup on click or blur
77
73
  trigger.onBlur = react_utilities_1.mergeCallbacks(event => {
78
74
  if (!ignoreNextBlur.current) {
79
75
  setOpen(event, false);
80
76
  }
81
-
82
77
  ignoreNextBlur.current = false;
83
78
  setHasFocus(false);
84
79
  }, trigger.onBlur);
@@ -87,8 +82,8 @@ function useTriggerListboxSlots(props, state, ref, triggerSlot, listboxSlot) {
87
82
  }, trigger.onClick);
88
83
  trigger.onFocus = react_utilities_1.mergeCallbacks(event => {
89
84
  setHasFocus(true);
90
- }, trigger.onFocus); // handle combobox keyboard interaction
91
-
85
+ }, trigger.onFocus);
86
+ // handle combobox keyboard interaction
92
87
  trigger.onKeyDown = react_utilities_1.mergeCallbacks(event => {
93
88
  const action = dropdownKeyActions_1.getDropdownActionFromKey(event, {
94
89
  open,
@@ -97,38 +92,31 @@ function useTriggerListboxSlots(props, state, ref, triggerSlot, listboxSlot) {
97
92
  const maxIndex = getCount() - 1;
98
93
  const activeIndex = activeOption ? getIndexOfId(activeOption.id) : -1;
99
94
  let newIndex = activeIndex;
100
-
101
95
  switch (action) {
102
96
  case 'Open':
103
97
  event.preventDefault();
104
98
  setFocusVisible(true);
105
99
  setOpen(event, true);
106
100
  break;
107
-
108
101
  case 'Close':
109
102
  // stop propagation for escape key to avoid dismissing any parent popups
110
103
  event.stopPropagation();
111
104
  event.preventDefault();
112
105
  setOpen(event, false);
113
106
  break;
114
-
115
107
  case 'CloseSelect':
116
108
  !multiselect && !(activeOption === null || activeOption === void 0 ? void 0 : activeOption.disabled) && setOpen(event, false);
117
109
  // fallthrough
118
-
119
110
  case 'Select':
120
111
  activeOption && selectOption(event, activeOption);
121
112
  event.preventDefault();
122
113
  break;
123
-
124
114
  case 'Tab':
125
115
  !multiselect && activeOption && selectOption(event, activeOption);
126
116
  break;
127
-
128
117
  default:
129
118
  newIndex = dropdownKeyActions_1.getIndexFromAction(action, activeIndex, maxIndex);
130
119
  }
131
-
132
120
  if (newIndex !== activeIndex) {
133
121
  // prevent default page scroll/keyboard action if the index changed
134
122
  event.preventDefault();
@@ -141,6 +129,5 @@ function useTriggerListboxSlots(props, state, ref, triggerSlot, listboxSlot) {
141
129
  }, trigger.onMouseOver);
142
130
  return [trigger, listbox];
143
131
  }
144
-
145
132
  exports.useTriggerListboxSlots = useTriggerListboxSlots;
146
133
  //# sourceMappingURL=useTriggerListboxSlots.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["packages/react-components/react-combobox/src/utils/useTriggerListboxSlots.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA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,KAAD,CAAf;EACD,CAHmB,EAIpB,OAAO,CAAC,WAJY,CAAtB;EAOA,OAAO,CAAC,OAAD,EAAU,OAAV,CAAP;AACD;;AA/ID,OAAA,CAAA,sBAAA,GAAA,sBAAA","sourcesContent":["import * as React from 'react';\nimport { mergeCallbacks, useMergedRefs } from '@fluentui/react-utilities';\nimport type { ExtractSlotProps, Slot } from '@fluentui/react-utilities';\nimport { getDropdownActionFromKey, getIndexFromAction } from '../utils/dropdownKeyActions';\nimport { Listbox } from '../components/Listbox/Listbox';\nimport type { ComboboxBaseProps, ComboboxBaseState } from './ComboboxBase.types';\n\nexport function useTriggerListboxSlots(\n props: ComboboxBaseProps,\n state: ComboboxBaseState,\n ref: React.Ref<HTMLButtonElement>,\n triggerSlot?: ExtractSlotProps<Slot<'button'>>,\n listboxSlot?: ExtractSlotProps<Slot<typeof Listbox>>,\n): [trigger: ExtractSlotProps<Slot<'button'>>, listbox?: ExtractSlotProps<Slot<typeof Listbox>>];\nexport function useTriggerListboxSlots(\n props: ComboboxBaseProps,\n state: ComboboxBaseState,\n ref: React.Ref<HTMLInputElement>,\n triggerSlot?: ExtractSlotProps<Slot<'input'>>,\n listboxSlot?: ExtractSlotProps<Slot<typeof Listbox>>,\n): [trigger: ExtractSlotProps<Slot<'input'>>, listbox?: ExtractSlotProps<Slot<typeof Listbox>>];\n\n/*\n * useTriggerListboxSlots returns a tuple of trigger/listbox shorthand,\n * with the semantics and event handlers needed for the Combobox and Dropdown components.\n * The element type of the ref should always match the element type used in the trigger shorthand.\n */\nexport function useTriggerListboxSlots(\n props: ComboboxBaseProps,\n state: ComboboxBaseState,\n ref: React.Ref<HTMLButtonElement | HTMLInputElement>,\n triggerSlot?: ExtractSlotProps<Slot<'input'>> | ExtractSlotProps<Slot<'button'>>,\n listboxSlot?: ExtractSlotProps<Slot<typeof Listbox>>,\n): [\n trigger: ExtractSlotProps<Slot<'input'>> | ExtractSlotProps<Slot<'button'>>,\n listbox?: ExtractSlotProps<Slot<typeof Listbox>>,\n] {\n const { multiselect } = props;\n const {\n activeOption,\n getCount,\n getIndexOfId,\n getOptionAtIndex,\n ignoreNextBlur,\n open,\n selectOption,\n setActiveOption,\n setFocusVisible,\n setHasFocus,\n setOpen,\n } = state;\n\n // handle trigger focus/blur\n const triggerRef: typeof ref = React.useRef(null);\n\n // resolve listbox shorthand props\n const listbox: typeof listboxSlot = listboxSlot && {\n multiselect,\n tabIndex: undefined,\n ...listboxSlot,\n };\n\n // resolve trigger shorthand props\n const trigger: typeof triggerSlot = {\n 'aria-expanded': open,\n 'aria-activedescendant': open ? activeOption?.id : undefined,\n role: 'combobox',\n ...triggerSlot,\n // explicitly type the ref as an intersection here to prevent type errors\n // since the `children` prop has mutually incompatible types between input/button\n // functionally both ref and triggerRef will always be the same element type\n ref: useMergedRefs(ref, triggerSlot?.ref, triggerRef) as React.Ref<HTMLButtonElement & HTMLInputElement>,\n };\n\n // listbox is nullable, only add event handlers if it exists\n if (listbox) {\n /*\n * Handle focus when clicking the listbox popup:\n * 1. Move focus back to the button/input when the listbox is clicked (otherwise it goes to body)\n * 2. Do not close the listbox on button/input blur when clicking into the listbox\n */\n listbox.onClick = mergeCallbacks((event: React.MouseEvent<HTMLDivElement>) => {\n triggerRef.current?.focus();\n }, listbox.onClick);\n\n listbox.onMouseOver = mergeCallbacks((event: React.MouseEvent<HTMLDivElement>) => {\n setFocusVisible(false);\n }, listbox.onMouseOver);\n\n listbox.onMouseDown = mergeCallbacks((event: React.MouseEvent<HTMLDivElement>) => {\n ignoreNextBlur.current = true;\n }, listbox.onMouseDown);\n }\n\n // the trigger should open/close the popup on click or blur\n trigger.onBlur = mergeCallbacks((event: React.FocusEvent<HTMLButtonElement> & React.FocusEvent<HTMLInputElement>) => {\n if (!ignoreNextBlur.current) {\n setOpen(event, false);\n }\n\n ignoreNextBlur.current = false;\n\n setHasFocus(false);\n }, trigger.onBlur);\n\n trigger.onClick = mergeCallbacks(\n (event: React.MouseEvent<HTMLButtonElement> & React.MouseEvent<HTMLInputElement>) => {\n setOpen(event, !open);\n },\n trigger.onClick,\n );\n\n trigger.onFocus = mergeCallbacks(\n (event: React.FocusEvent<HTMLButtonElement> & React.FocusEvent<HTMLInputElement>) => {\n setHasFocus(true);\n },\n trigger.onFocus,\n );\n\n // handle combobox keyboard interaction\n trigger.onKeyDown = mergeCallbacks(\n (event: React.KeyboardEvent<HTMLButtonElement> & React.KeyboardEvent<HTMLInputElement>) => {\n const action = getDropdownActionFromKey(event, { open, multiselect });\n const maxIndex = getCount() - 1;\n const activeIndex = activeOption ? getIndexOfId(activeOption.id) : -1;\n let newIndex = activeIndex;\n\n switch (action) {\n case 'Open':\n event.preventDefault();\n setFocusVisible(true);\n setOpen(event, true);\n break;\n case 'Close':\n // stop propagation for escape key to avoid dismissing any parent popups\n event.stopPropagation();\n event.preventDefault();\n setOpen(event, false);\n break;\n case 'CloseSelect':\n !multiselect && !activeOption?.disabled && setOpen(event, false);\n // fallthrough\n case 'Select':\n activeOption && selectOption(event, activeOption);\n event.preventDefault();\n break;\n case 'Tab':\n !multiselect && activeOption && selectOption(event, activeOption);\n break;\n default:\n newIndex = getIndexFromAction(action, activeIndex, maxIndex);\n }\n if (newIndex !== activeIndex) {\n // prevent default page scroll/keyboard action if the index changed\n event.preventDefault();\n setActiveOption(getOptionAtIndex(newIndex));\n setFocusVisible(true);\n }\n },\n trigger.onKeyDown,\n );\n\n trigger.onMouseOver = mergeCallbacks(\n (event: React.MouseEvent<HTMLButtonElement> & React.MouseEvent<HTMLInputElement>) => {\n setFocusVisible(false);\n },\n trigger.onMouseOver,\n );\n\n return [trigger, listbox];\n}\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"mappings":";;;;;;AAAA;AACA;AAEA;AAmBA;;;;;AAKA,SAAgBA,sBAAsB,CACpCC,KAAwB,EACxBC,KAAwB,EACxBC,GAAoD,EACpDC,WAAgF,EAChFC,WAAoD;EAKpD,MAAM;IAAEC;EAAW,CAAE,GAAGL,KAAK;EAC7B,MA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KAAK,OAAO;QACV;QACAA,KAAK,CAACiB,eAAe,EAAE;QACvBjB,KAAK,CAACgB,cAAc,EAAE;QACtB5B,OAAO,CAACY,KAAK,EAAE,KAAK,CAAC;QACrB;MACF,KAAK,aAAa;QAChB,CAACvB,WAAW,IAAI,EAACC,YAAY,aAAZA,YAAY,uBAAZA,YAAY,CAAEwC,QAAQ,KAAI9B,OAAO,CAACY,KAAK,EAAE,KAAK,CAAC;MAClE;MACA,KAAK,QAAQ;QACXtB,YAAY,IAAIM,YAAY,CAACgB,KAAK,EAAEtB,YAAY,CAAC;QACjDsB,KAAK,CAACgB,cAAc,EAAE;QACtB;MACF,KAAK,KAAK;QACR,CAACvC,WAAW,IAAIC,YAAY,IAAIM,YAAY,CAACgB,KAAK,EAAEtB,YAAY,CAAC;QACjE;MACF;QACEqC,QAAQ,GAAGH,uCAAkB,CAACD,MAAM,EAAEG,WAAW,EAAED,QAAQ,CAAC;IAAC;IAEjE,IAAIE,QAAQ,KAAKD,WAAW,EAAE;MAC5B;MACAd,KAAK,CAACgB,cAAc,EAAE;MACtB/B,eAAe,CAACJ,gBAAgB,CAACkC,QAAQ,CAAC,CAAC;MAC3C7B,eAAe,CAAC,IAAI,CAAC;;EAEzB,CAAC,EACDS,OAAO,CAACe,SAAS,CAClB;EAEDf,OAAO,CAACU,WAAW,GAAGP,gCAAc,CACjCE,KAA+E,IAAI;IAClFd,eAAe,CAAC,KAAK,CAAC;EACxB,CAAC,EACDS,OAAO,CAACU,WAAW,CACpB;EAED,OAAO,CAACV,OAAO,EAAEH,OAAO,CAAC;AAC3B;AAzJA2B","names":["useTriggerListboxSlots","props","state","ref","triggerSlot","listboxSlot","multiselect","activeOption","getCount","getIndexOfId","getOptionAtIndex","ignoreNextBlur","open","selectOption","setActiveOption","setFocusVisible","setHasFocus","setOpen","triggerRef","React","useRef","listbox","tabIndex","undefined","trigger","id","role","react_utilities_1","listboxOnClick","event","current","focus","onClick","listboxOnMouseOver","onMouseOver","listboxOnMouseDown","onMouseDown","onBlur","onFocus","onKeyDown","action","dropdownKeyActions_1","maxIndex","activeIndex","newIndex","preventDefault","stopPropagation","disabled","exports"],"sourceRoot":"../src/","sources":["packages/react-components/react-combobox/src/utils/useTriggerListboxSlots.ts"],"sourcesContent":["import * as React from 'react';\nimport { mergeCallbacks, useEventCallback, useMergedRefs } from '@fluentui/react-utilities';\nimport type { ExtractSlotProps, Slot } from '@fluentui/react-utilities';\nimport { getDropdownActionFromKey, getIndexFromAction } from '../utils/dropdownKeyActions';\nimport { Listbox } from '../components/Listbox/Listbox';\nimport type { ComboboxBaseProps, ComboboxBaseState } from './ComboboxBase.types';\n\nexport function useTriggerListboxSlots(\n props: ComboboxBaseProps,\n state: ComboboxBaseState,\n ref: React.Ref<HTMLButtonElement>,\n triggerSlot?: ExtractSlotProps<Slot<'button'>>,\n listboxSlot?: ExtractSlotProps<Slot<typeof Listbox>>,\n): [trigger: ExtractSlotProps<Slot<'button'>>, listbox?: ExtractSlotProps<Slot<typeof Listbox>>];\nexport function useTriggerListboxSlots(\n props: ComboboxBaseProps,\n state: ComboboxBaseState,\n ref: React.Ref<HTMLInputElement>,\n triggerSlot?: ExtractSlotProps<Slot<'input'>>,\n listboxSlot?: ExtractSlotProps<Slot<typeof Listbox>>,\n): [trigger: ExtractSlotProps<Slot<'input'>>, listbox?: ExtractSlotProps<Slot<typeof Listbox>>];\n\n/*\n * useTriggerListboxSlots returns a tuple of trigger/listbox shorthand,\n * with the semantics and event handlers needed for the Combobox and Dropdown components.\n * The element type of the ref should always match the element type used in the trigger shorthand.\n */\nexport function useTriggerListboxSlots(\n props: ComboboxBaseProps,\n state: ComboboxBaseState,\n ref: React.Ref<HTMLButtonElement | HTMLInputElement>,\n triggerSlot?: ExtractSlotProps<Slot<'input'>> | ExtractSlotProps<Slot<'button'>>,\n listboxSlot?: ExtractSlotProps<Slot<typeof Listbox>>,\n): [\n trigger: ExtractSlotProps<Slot<'input'>> | ExtractSlotProps<Slot<'button'>>,\n listbox?: ExtractSlotProps<Slot<typeof Listbox>>,\n] {\n const { multiselect } = props;\n const {\n activeOption,\n getCount,\n getIndexOfId,\n getOptionAtIndex,\n ignoreNextBlur,\n open,\n selectOption,\n setActiveOption,\n setFocusVisible,\n setHasFocus,\n setOpen,\n } = state;\n\n // handle trigger focus/blur\n const triggerRef: typeof ref = React.useRef(null);\n\n // resolve listbox shorthand props\n const listbox: typeof listboxSlot = listboxSlot && {\n multiselect,\n tabIndex: undefined,\n ...listboxSlot,\n };\n\n // resolve trigger shorthand props\n const trigger: typeof triggerSlot = {\n 'aria-expanded': open,\n 'aria-activedescendant': open ? activeOption?.id : undefined,\n role: 'combobox',\n ...triggerSlot,\n // explicitly type the ref as an intersection here to prevent type errors\n // since the `children` prop has mutually incompatible types between input/button\n // functionally both ref and triggerRef will always be the same element type\n ref: useMergedRefs(ref, triggerSlot?.ref, triggerRef) as React.Ref<HTMLButtonElement & HTMLInputElement>,\n };\n\n /*\n * Handle focus when clicking the listbox popup:\n * 1. Move focus back to the button/input when the listbox is clicked (otherwise it goes to body)\n * 2. Do not close the listbox on button/input blur when clicking into the listbox\n */\n const listboxOnClick = useEventCallback(\n mergeCallbacks((event: React.MouseEvent<HTMLDivElement>) => {\n triggerRef.current?.focus();\n }, listbox?.onClick),\n );\n\n const listboxOnMouseOver = useEventCallback(\n mergeCallbacks((event: React.MouseEvent<HTMLDivElement>) => {\n setFocusVisible(false);\n }, listbox?.onMouseOver),\n );\n\n const listboxOnMouseDown = useEventCallback(\n mergeCallbacks((event: React.MouseEvent<HTMLDivElement>) => {\n ignoreNextBlur.current = true;\n }, listbox?.onMouseDown),\n );\n\n // listbox is nullable, only add event handlers if it exists\n if (listbox) {\n listbox.onClick = listboxOnClick;\n listbox.onMouseOver = listboxOnMouseOver;\n listbox.onMouseDown = listboxOnMouseDown;\n }\n\n // the trigger should open/close the popup on click or blur\n trigger.onBlur = mergeCallbacks((event: React.FocusEvent<HTMLButtonElement> & React.FocusEvent<HTMLInputElement>) => {\n if (!ignoreNextBlur.current) {\n setOpen(event, false);\n }\n\n ignoreNextBlur.current = false;\n\n setHasFocus(false);\n }, trigger.onBlur);\n\n trigger.onClick = mergeCallbacks(\n (event: React.MouseEvent<HTMLButtonElement> & React.MouseEvent<HTMLInputElement>) => {\n setOpen(event, !open);\n },\n trigger.onClick,\n );\n\n trigger.onFocus = mergeCallbacks(\n (event: React.FocusEvent<HTMLButtonElement> & React.FocusEvent<HTMLInputElement>) => {\n setHasFocus(true);\n },\n trigger.onFocus,\n );\n\n // handle combobox keyboard interaction\n trigger.onKeyDown = mergeCallbacks(\n (event: React.KeyboardEvent<HTMLButtonElement> & React.KeyboardEvent<HTMLInputElement>) => {\n const action = getDropdownActionFromKey(event, { open, multiselect });\n const maxIndex = getCount() - 1;\n const activeIndex = activeOption ? getIndexOfId(activeOption.id) : -1;\n let newIndex = activeIndex;\n\n switch (action) {\n case 'Open':\n event.preventDefault();\n setFocusVisible(true);\n setOpen(event, true);\n break;\n case 'Close':\n // stop propagation for escape key to avoid dismissing any parent popups\n event.stopPropagation();\n event.preventDefault();\n setOpen(event, false);\n break;\n case 'CloseSelect':\n !multiselect && !activeOption?.disabled && setOpen(event, false);\n // fallthrough\n case 'Select':\n activeOption && selectOption(event, activeOption);\n event.preventDefault();\n break;\n case 'Tab':\n !multiselect && activeOption && selectOption(event, activeOption);\n break;\n default:\n newIndex = getIndexFromAction(action, activeIndex, maxIndex);\n }\n if (newIndex !== activeIndex) {\n // prevent default page scroll/keyboard action if the index changed\n event.preventDefault();\n setActiveOption(getOptionAtIndex(newIndex));\n setFocusVisible(true);\n }\n },\n trigger.onKeyDown,\n );\n\n trigger.onMouseOver = mergeCallbacks(\n (event: React.MouseEvent<HTMLButtonElement> & React.MouseEvent<HTMLInputElement>) => {\n setFocusVisible(false);\n },\n trigger.onMouseOver,\n );\n\n return [trigger, listbox];\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluentui/react-combobox",
3
- "version": "9.0.0-beta.19",
3
+ "version": "9.0.0-beta.21",
4
4
  "description": "Fluent UI React Combobox component",
5
5
  "main": "lib-commonjs/index.js",
6
6
  "module": "lib/index.js",
@@ -27,19 +27,19 @@
27
27
  "devDependencies": {
28
28
  "@fluentui/eslint-plugin": "*",
29
29
  "@fluentui/react-conformance": "*",
30
- "@fluentui/react-conformance-griffel": "9.0.0-beta.18",
31
- "@fluentui/scripts": "^1.0.0"
30
+ "@fluentui/react-conformance-griffel": "9.0.0-beta.19",
31
+ "@fluentui/scripts": "*"
32
32
  },
33
33
  "dependencies": {
34
34
  "@fluentui/keyboard-keys": "^9.0.1",
35
- "@fluentui/react-context-selector": "^9.1.3",
36
- "@fluentui/react-field": "9.0.0-alpha.12",
35
+ "@fluentui/react-context-selector": "^9.1.5",
36
+ "@fluentui/react-field": "9.0.0-alpha.14",
37
37
  "@fluentui/react-icons": "^2.0.175",
38
- "@fluentui/react-portal": "^9.0.14",
39
- "@fluentui/react-positioning": "^9.3.5",
38
+ "@fluentui/react-portal": "^9.1.0",
39
+ "@fluentui/react-positioning": "^9.3.7",
40
40
  "@fluentui/react-theme": "^9.1.5",
41
- "@fluentui/react-utilities": "^9.3.0",
42
- "@griffel/react": "^1.4.2",
41
+ "@fluentui/react-utilities": "^9.4.0",
42
+ "@griffel/react": "^1.5.2",
43
43
  "tslib": "^2.1.0"
44
44
  },
45
45
  "peerDependencies": {