@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
@@ -2,7 +2,6 @@ import * as keys from '@fluentui/keyboard-keys';
2
2
  /**
3
3
  * Converts a keyboard interaction into a defined action
4
4
  */
5
-
6
5
  export function getDropdownActionFromKey(e, options = {}) {
7
6
  const {
8
7
  open = true,
@@ -14,92 +13,72 @@ export function getDropdownActionFromKey(e, options = {}) {
14
13
  ctrlKey,
15
14
  key,
16
15
  metaKey
17
- } = e; // typing action occurs whether open or closed
18
-
16
+ } = e;
17
+ // typing action occurs whether open or closed
19
18
  if (key.length === 1 && code !== keys.Space && !altKey && !ctrlKey && !metaKey) {
20
19
  return 'Type';
21
- } // handle opening the dropdown if closed
22
-
23
-
20
+ }
21
+ // handle opening the dropdown if closed
24
22
  if (!open) {
25
23
  if (code === keys.ArrowDown || code === keys.ArrowUp || code === keys.Enter || code === keys.Space) {
26
24
  return 'Open';
27
- } // if the dropdown is closed and an action did not match the above, do nothing
28
-
29
-
25
+ }
26
+ // if the dropdown is closed and an action did not match the above, do nothing
30
27
  return 'None';
31
- } // select or close actions
32
-
33
-
28
+ }
29
+ // select or close actions
34
30
  if (code === keys.ArrowUp && altKey || code === keys.Enter || !multiselect && code === keys.Space) {
35
31
  return 'CloseSelect';
36
32
  }
37
-
38
33
  if (multiselect && code === keys.Space) {
39
34
  return 'Select';
40
35
  }
41
-
42
36
  if (code === keys.Escape) {
43
37
  return 'Close';
44
- } // navigation interactions
45
-
46
-
38
+ }
39
+ // navigation interactions
47
40
  if (code === keys.ArrowDown) {
48
41
  return 'Next';
49
42
  }
50
-
51
43
  if (code === keys.ArrowUp) {
52
44
  return 'Previous';
53
45
  }
54
-
55
46
  if (code === keys.Home) {
56
47
  return 'First';
57
48
  }
58
-
59
49
  if (code === keys.End) {
60
50
  return 'Last';
61
51
  }
62
-
63
52
  if (code === keys.PageUp) {
64
53
  return 'PageUp';
65
54
  }
66
-
67
55
  if (code === keys.PageDown) {
68
56
  return 'PageDown';
69
57
  }
70
-
71
58
  if (code === keys.Tab) {
72
59
  return 'Tab';
73
- } // if nothing matched, return none
74
-
75
-
60
+ }
61
+ // if nothing matched, return none
76
62
  return 'None';
77
63
  }
78
64
  /**
79
65
  * Returns the requested option index from an action
80
66
  */
81
-
82
67
  export function getIndexFromAction(action, currentIndex, maxIndex) {
83
68
  switch (action) {
84
69
  case 'Next':
85
70
  return Math.min(maxIndex, currentIndex + 1);
86
71
  break;
87
-
88
72
  case 'Previous':
89
73
  return Math.max(0, currentIndex - 1);
90
-
91
74
  case 'First':
92
75
  return 0;
93
-
94
76
  case 'Last':
95
77
  return maxIndex;
96
-
97
78
  case 'PageDown':
98
79
  return Math.min(maxIndex, currentIndex + 10);
99
-
100
80
  case 'PageUp':
101
81
  return Math.max(0, currentIndex - 10);
102
-
103
82
  default:
104
83
  return currentIndex;
105
84
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["packages/react-components/react-combobox/src/utils/dropdownKeyActions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAZ,MAAsB,yBAAtB;AA2BA;;AAEG;;AACH,OAAM,SAAU,wBAAV,CACJ,CADI,EAEJ,OAAA,GAAiC,EAF7B,EAE+B;EAEnC,MAAM;IAAE,IAAI,GAAG,IAAT;IAAe,WAAW,GAAG;EAA7B,IAAuC,OAA7C;EACA,MAAM,IAAI,GAAG,CAAC,CAAC,GAAf;EACA,MAAM;IAAE,MAAF;IAAU,OAAV;IAAmB,GAAnB;IAAwB;EAAxB,IAAoC,CAA1C,CAJmC,CAMnC;;EACA,IAAI,GAAG,CAAC,MAAJ,KAAe,CAAf,IAAoB,IAAI,KAAK,IAAI,CAAC,KAAlC,IAA2C,CAAC,MAA5C,IAAsD,CAAC,OAAvD,I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ACA,OAAO,MAAP;AACD;AAED;;AAEG;;AACH,OAAM,SAAU,kBAAV,CAA6B,MAA7B,EAAsD,YAAtD,EAA4E,QAA5E,EAA4F;EAChG,QAAQ,MAAR;IACE,KAAK,MAAL;MACE,OAAO,IAAI,CAAC,GAAL,CAAS,QAAT,EAAmB,YAAY,GAAG,CAAlC,CAAP;MACA;;IACF,KAAK,UAAL;MACE,OAAO,IAAI,CAAC,GAAL,CAAS,CAAT,EAAY,YAAY,GAAG,CAA3B,CAAP;;IACF,KAAK,OAAL;MACE,OAAO,CAAP;;IACF,KAAK,MAAL;MACE,OAAO,QAAP;;IACF,KAAK,UAAL;MACE,OAAO,IAAI,CAAC,GAAL,CAAS,QAAT,EAAmB,YAAY,GAAG,EAAlC,CAAP;;IACF,KAAK,QAAL;MACE,OAAO,IAAI,CAAC,GAAL,CAAS,CAAT,EAAY,YAAY,GAAG,EAA3B,CAAP;;IACF;MACE,OAAO,YAAP;EAfJ;AAiBD","sourcesContent":["import * as keys from '@fluentui/keyboard-keys';\nimport * as React from 'react';\n\n/**\n * enum of actions available in any type of managed dropdown control\n * e.g. combobox, select, datepicker, menu\n */\nexport type DropdownActions =\n | 'Close'\n | 'CloseSelect'\n | 'First'\n | 'Last'\n | 'Next'\n | 'None'\n | 'Open'\n | 'PageDown'\n | 'PageUp'\n | 'Previous'\n | 'Select'\n | 'Tab'\n | 'Type';\n\nexport interface DropdownActionOptions {\n open?: boolean;\n multiselect?: boolean;\n}\n\n/**\n * Converts a keyboard interaction into a defined action\n */\nexport function getDropdownActionFromKey(\n e: KeyboardEvent | React.KeyboardEvent,\n options: DropdownActionOptions = {},\n): DropdownActions {\n const { open = true, multiselect = false } = options;\n const code = e.key;\n const { altKey, ctrlKey, key, metaKey } = e;\n\n // typing action occurs whether open or closed\n if (key.length === 1 && code !== keys.Space && !altKey && !ctrlKey && !metaKey) {\n return 'Type';\n }\n\n // handle opening the dropdown if closed\n if (!open) {\n if (code === keys.ArrowDown || code === keys.ArrowUp || code === keys.Enter || code === keys.Space) {\n return 'Open';\n }\n\n // if the dropdown is closed and an action did not match the above, do nothing\n return 'None';\n }\n\n // select or close actions\n if ((code === keys.ArrowUp && altKey) || code === keys.Enter || (!multiselect && code === keys.Space)) {\n return 'CloseSelect';\n }\n if (multiselect && code === keys.Space) {\n return 'Select';\n }\n if (code === keys.Escape) {\n return 'Close';\n }\n\n // navigation interactions\n if (code === keys.ArrowDown) {\n return 'Next';\n }\n if (code === keys.ArrowUp) {\n return 'Previous';\n }\n if (code === keys.Home) {\n return 'First';\n }\n if (code === keys.End) {\n return 'Last';\n }\n if (code === keys.PageUp) {\n return 'PageUp';\n }\n if (code === keys.PageDown) {\n return 'PageDown';\n }\n if (code === keys.Tab) {\n return 'Tab';\n }\n\n // if nothing matched, return none\n return 'None';\n}\n\n/**\n * Returns the requested option index from an action\n */\nexport function getIndexFromAction(action: DropdownActions, currentIndex: number, maxIndex: number): number {\n switch (action) {\n case 'Next':\n return Math.min(maxIndex, currentIndex + 1);\n break;\n case 'Previous':\n return Math.max(0, currentIndex - 1);\n case 'First':\n return 0;\n case 'Last':\n return maxIndex;\n case 'PageDown':\n return Math.min(maxIndex, currentIndex + 10);\n case 'PageUp':\n return Math.max(0, currentIndex - 10);\n default:\n return currentIndex;\n }\n}\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"mappings":"AAAA,OAAO,KAAKA,IAAI,MAAM,yBAAyB;AA2B/C;;;AAGA,OAAM,SAAUC,wBAAwB,CACtCC,CAAsC,EACtCC,UAAiC,EAAE;EAEnC,MAAM;IAAEC,IAAI,GAAG,IAAI;IAAEC,WAAW,GAAG;EAAK,CAAE,GAAGF,OAAO;EACpD,MAAMG,IAAI,GAAGJ,CAAC,CAACK,GAAG;EAClB,MAAM;IAAEC,MAAM;IAAEC,OAAO;IAAEF,GAAG;IAAEG;EAAO,CAAE,GAAGR,CAAC;EAE3C;EACA,IAAIK,GAAG,CAACI,MAAM,KAAK,CAAC,IAAIL,IAAI,KAAKN,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GA,OAAM,SAAUC,kBAAkB,CAACC,MAAuB,EAAEC,YAAoB,EAAEC,QAAgB;EAChG,QAAQF,MAAM;IACZ,KAAK,MAAM;MACT,OAAOG,IAAI,CAACC,GAAG,CAACF,QAAQ,EAAED,YAAY,GAAG,CAAC,CAAC;MAC3C;IACF,KAAK,UAAU;MACb,OAAOE,IAAI,CAACE,GAAG,CAAC,CAAC,EAAEJ,YAAY,GAAG,CAAC,CAAC;IACtC,KAAK,OAAO;MACV,OAAO,CAAC;IACV,KAAK,MAAM;MACT,OAAOC,QAAQ;IACjB,KAAK,UAAU;MACb,OAAOC,IAAI,CAACC,GAAG,CAACF,QAAQ,EAAED,YAAY,GAAG,EAAE,CAAC;IAC9C,KAAK,QAAQ;MACX,OAAOE,IAAI,CAACE,GAAG,CAAC,CAAC,EAAEJ,YAAY,GAAG,EAAE,CAAC;IACvC;MACE,OAAOA,YAAY;EAAC;AAE1B","names":["keys","getDropdownActionFromKey","e","options","open","multiselect","code","key","altKey","ctrlKey","metaKey","length","Space","ArrowDown","ArrowUp","Enter","Escape","Home","End","PageUp","PageDown","Tab","getIndexFromAction","action","currentIndex","maxIndex","Math","min","max"],"sourceRoot":"../src/","sources":["packages/react-components/react-combobox/src/utils/dropdownKeyActions.ts"],"sourcesContent":["import * as keys from '@fluentui/keyboard-keys';\nimport * as React from 'react';\n\n/**\n * enum of actions available in any type of managed dropdown control\n * e.g. combobox, select, datepicker, menu\n */\nexport type DropdownActions =\n | 'Close'\n | 'CloseSelect'\n | 'First'\n | 'Last'\n | 'Next'\n | 'None'\n | 'Open'\n | 'PageDown'\n | 'PageUp'\n | 'Previous'\n | 'Select'\n | 'Tab'\n | 'Type';\n\nexport interface DropdownActionOptions {\n open?: boolean;\n multiselect?: boolean;\n}\n\n/**\n * Converts a keyboard interaction into a defined action\n */\nexport function getDropdownActionFromKey(\n e: KeyboardEvent | React.KeyboardEvent,\n options: DropdownActionOptions = {},\n): DropdownActions {\n const { open = true, multiselect = false } = options;\n const code = e.key;\n const { altKey, ctrlKey, key, metaKey } = e;\n\n // typing action occurs whether open or closed\n if (key.length === 1 && code !== keys.Space && !altKey && !ctrlKey && !metaKey) {\n return 'Type';\n }\n\n // handle opening the dropdown if closed\n if (!open) {\n if (code === keys.ArrowDown || code === keys.ArrowUp || code === keys.Enter || code === keys.Space) {\n return 'Open';\n }\n\n // if the dropdown is closed and an action did not match the above, do nothing\n return 'None';\n }\n\n // select or close actions\n if ((code === keys.ArrowUp && altKey) || code === keys.Enter || (!multiselect && code === keys.Space)) {\n return 'CloseSelect';\n }\n if (multiselect && code === keys.Space) {\n return 'Select';\n }\n if (code === keys.Escape) {\n return 'Close';\n }\n\n // navigation interactions\n if (code === keys.ArrowDown) {\n return 'Next';\n }\n if (code === keys.ArrowUp) {\n return 'Previous';\n }\n if (code === keys.Home) {\n return 'First';\n }\n if (code === keys.End) {\n return 'Last';\n }\n if (code === keys.PageUp) {\n return 'PageUp';\n }\n if (code === keys.PageDown) {\n return 'PageDown';\n }\n if (code === keys.Tab) {\n return 'Tab';\n }\n\n // if nothing matched, return none\n return 'None';\n}\n\n/**\n * Returns the requested option index from an action\n */\nexport function getIndexFromAction(action: DropdownActions, currentIndex: number, maxIndex: number): number {\n switch (action) {\n case 'Next':\n return Math.min(maxIndex, currentIndex + 1);\n break;\n case 'Previous':\n return Math.max(0, currentIndex - 1);\n case 'First':\n return 0;\n case 'Last':\n return maxIndex;\n case 'PageDown':\n return Math.min(maxIndex, currentIndex + 10);\n case 'PageUp':\n return Math.max(0, currentIndex - 10);\n default:\n return currentIndex;\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["packages/react-components/react-combobox/src/utils/internalTokens.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,SAAS,GAAG;EACvB,KAAK,EAAE,MADgB;EAEvB,MAAM,EAAE,MAFe;EAGvB,KAAK,EAAE;AAHgB,CAAlB","sourcesContent":["export const iconSizes = {\n small: '16px',\n medium: '20px',\n large: '24px',\n};\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"mappings":"AAAA,OAAO,MAAMA,SAAS,GAAG;EACvBC,KAAK,EAAE,MAAM;EACbC,MAAM,EAAE,MAAM;EACdC,KAAK,EAAE;CACR","names":["iconSizes","small","medium","large"],"sourceRoot":"../src/","sources":["packages/react-components/react-combobox/src/utils/internalTokens.ts"],"sourcesContent":["export const iconSizes = {\n small: '16px',\n medium: '20px',\n large: '24px',\n};\n"]}
@@ -5,7 +5,6 @@ import { useSelection } from '../utils/useSelection';
5
5
  /**
6
6
  * State shared between Combobox and Dropdown components
7
7
  */
8
-
9
8
  export const useComboboxBaseState = props => {
10
9
  const {
11
10
  appearance = 'outline',
@@ -20,18 +19,18 @@ export const useComboboxBaseState = props => {
20
19
  getOptionAtIndex,
21
20
  getOptionsMatchingText
22
21
  } = optionCollection;
23
- const [activeOption, setActiveOption] = React.useState(); // track whether keyboard focus outline should be shown
22
+ const [activeOption, setActiveOption] = React.useState();
23
+ // track whether keyboard focus outline should be shown
24
24
  // tabster/keyborg doesn't work here, since the actual keyboard focus target doesn't move
25
-
26
- const [focusVisible, setFocusVisible] = React.useState(false); // track focused state to conditionally render collapsed listbox
27
-
25
+ const [focusVisible, setFocusVisible] = React.useState(false);
26
+ // track focused state to conditionally render collapsed listbox
28
27
  const [hasFocus, setHasFocus] = React.useState(false);
29
28
  const ignoreNextBlur = React.useRef(false);
30
29
  const selectionState = useSelection(props);
31
30
  const {
32
31
  selectedOptions
33
- } = selectionState; // calculate value based on props, internal value changes, and selected options
34
-
32
+ } = selectionState;
33
+ // calculate value based on props, internal value changes, and selected options
35
34
  const isFirstMount = useFirstMount();
36
35
  const [controllableValue, setValue] = useControllableState({
37
36
  state: props.value,
@@ -41,53 +40,50 @@ export const useComboboxBaseState = props => {
41
40
  // don't compute the value if it is defined through props or setValue,
42
41
  if (controllableValue !== undefined) {
43
42
  return controllableValue;
44
- } // handle defaultValue here, so it is overridden by selection
45
-
46
-
43
+ }
44
+ // handle defaultValue here, so it is overridden by selection
47
45
  if (isFirstMount && props.defaultValue !== undefined) {
48
46
  return props.defaultValue;
49
47
  }
50
-
51
48
  if (multiselect) {
52
49
  // editable inputs should not display multiple selected options in the input as text
53
50
  return editable ? '' : selectedOptions.join(', ');
54
51
  }
55
-
56
52
  return selectedOptions[0];
57
- }, [controllableValue, editable, isFirstMount, multiselect, props.defaultValue, selectedOptions]); // Handle open state, which is shared with options in context
58
-
53
+ }, [controllableValue, editable, isFirstMount, multiselect, props.defaultValue, selectedOptions]);
54
+ // Handle open state, which is shared with options in context
59
55
  const [open, setOpenState] = useControllableState({
60
56
  state: props.open,
61
57
  defaultState: props.defaultOpen,
62
58
  initialState: false
63
59
  });
64
-
65
- const setOpen = (event, newState) => {
60
+ const setOpen = React.useCallback((event, newState) => {
66
61
  onOpenChange === null || onOpenChange === void 0 ? void 0 : onOpenChange(event, {
67
62
  open: newState
68
63
  });
69
64
  setOpenState(newState);
70
- }; // update active option based on change in open state
71
-
72
-
65
+ }, [onOpenChange, setOpenState]);
66
+ // update active option based on change in open state
73
67
  React.useEffect(() => {
74
68
  if (open && !activeOption) {
75
- // if there is a selection, start at the most recently selected item
76
- if (selectedOptions.length > 0) {
77
- const lastSelectedOption = getOptionsMatchingText(v => v === selectedOptions[selectedOptions.length - 1]).pop();
78
- lastSelectedOption && setActiveOption(lastSelectedOption);
79
- } // default to starting at the first option
69
+ // if it is single-select and there is a selected option, start at the selected option
70
+ if (!multiselect && selectedOptions.length > 0) {
71
+ const selectedOption = getOptionsMatchingText(v => v === selectedOptions[0]).pop();
72
+ selectedOption && setActiveOption(selectedOption);
73
+ }
74
+ // default to starting at the first option
80
75
  else {
81
76
  setActiveOption(getOptionAtIndex(0));
82
77
  }
83
78
  } else if (!open) {
84
79
  // reset the active option when closing
85
80
  setActiveOption(undefined);
86
- } // this should only be run in response to changes in the open state
81
+ }
82
+ // this should only be run in response to changes in the open state
87
83
  // eslint-disable-next-line react-hooks/exhaustive-deps
88
-
89
84
  }, [open]);
90
- return { ...optionCollection,
85
+ return {
86
+ ...optionCollection,
91
87
  ...selectionState,
92
88
  activeOption,
93
89
  appearance,
@@ -1 +1 @@
1
- {"version":3,"sources":["packages/react-components/react-combobox/src/utils/useComboboxBaseState.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,oBAAT,EAA+B,aAA/B,QAAoD,2BAApD;AACA,SAAS,mBAAT,QAAoC,8BAApC;AAEA,SAAS,YAAT,QAA6B,uBAA7B;AAGA;;AAEG;;AACH,OAAO,MAAM,oBAAoB,GAAI,KAAD,IAAyE;EAC3G,MAAM;IACJ,UAAU,GAAG,SADT;IAEJ,QAAQ,GAAG,KAFP;IAGJ,WAAW,GAAG,KAHV;IAIJ,WAJI;IAKJ,YALI;IAMJ,IAAI,GAAG;EANH,IAOF,KAPJ;EASA,MAAM,gBAAgB,GAAG,mBAAmB,EAA5C;EACA,MAAM;IAAE,gBAAF;IAAoB;EAApB,IAA+C,gBAArD;EAEA,MAAM,CAAC,YAAD,EAAe,eAAf,IAAkC,KAAK,CAAC,QAAN,EAAxC,CAb2G,CAe3G;EACA;;EACA,MAAM,CAAC,YAAD,EAAe,eAAf,IAAkC,KAAK,CAAC,QAAN,CAAe,KAAf,CAAxC,CAjB2G,CAmB3G;;EACA,MAAM,CAAC,QAAD,EAAW,WAAX,IAA0B,KAAK,CAAC,QAAN,CAAe,KAAf,CAAhC;EAEA,MAAM,cAAc,GAAG,KAAK,CAAC,MAAN,CAAa,KAAb,CAAvB;EAEA,MAAM,cAAc,GAAG,YAAY,CAAC,KAAD,CAAnC;EACA,MAAM;IAAE;EAAF,IAAsB,cAA5B,CAzB2G,CA2B3G;;EACA,MAAM,YAAY,GAAG,aAAa,EAAlC;EACA,MAAM,CAAC,iBAAD,EAAoB,QAApB,IAAgC,oBAAoB,CAAC;IACzD,KAAK,EAAE,KAAK,CAAC,KAD4C;IAEzD,YAAY,EAAE;EAF2C,CAAD,CAA1D;EAKA,M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E,GAA/E,EAA3B;QACA,kBAAkB,IAAI,eAAe,CAAC,kBAAD,CAArC;MACD,CAHD,CAIA;MAJA,KAKK;QACH,eAAe,CAAC,gBAAgB,CAAC,CAAD,CAAjB,CAAf;MACD;IACF,CAVD,MAUO,IAAI,CAAC,IAAL,EAAW;MAChB;MACA,eAAe,CAAC,SAAD,CAAf;IACD,CAdkB,CAenB;IACA;;EACD,CAjBD,EAiBG,CAAC,IAAD,CAjBH;EAmBA,OAAO,EACL,GAAG,gBADE;IAEL,GAAG,cAFE;IAGL,YAHK;IAIL,UAJK;IAKL,YALK;IAML,QANK;IAOL,cAPK;IAQL,WARK;IASL,IATK;IAUL,eAVK;IAWL,eAXK;IAYL,WAZK;IAaL,OAbK;IAcL,QAdK;IAeL,IAfK;IAgBL;EAhBK,CAAP;AAkBD,CAvGM","sourcesContent":["import * as React from 'react';\nimport { useControllableState, useFirstMount } from '@fluentui/react-utilities';\nimport { useOptionCollection } from '../utils/useOptionCollection';\nimport { OptionValue } from '../utils/OptionCollection.types';\nimport { useSelection } from '../utils/useSelection';\nimport type { ComboboxBaseProps, ComboboxBaseOpenEvents, ComboboxBaseState } from './ComboboxBase.types';\n\n/**\n * State shared between Combobox and Dropdown components\n */\nexport const useComboboxBaseState = (props: ComboboxBaseProps & { editable?: boolean }): ComboboxBaseState => {\n const {\n appearance = 'outline',\n editable = false,\n inlinePopup = false,\n multiselect,\n onOpenChange,\n size = 'medium',\n } = props;\n\n const optionCollection = useOptionCollection();\n const { getOptionAtIndex, getOptionsMatchingText } = optionCollection;\n\n const [activeOption, setActiveOption] = React.useState<OptionValue | undefined>();\n\n // track whether keyboard focus outline should be shown\n // tabster/keyborg doesn't work here, since the actual keyboard focus target doesn't move\n const [focusVisible, setFocusVisible] = React.useState(false);\n\n // track focused state to conditionally render collapsed listbox\n const [hasFocus, setHasFocus] = React.useState(false);\n\n const ignoreNextBlur = React.useRef(false);\n\n const selectionState = useSelection(props);\n const { selectedOptions } = selectionState;\n\n // calculate value based on props, internal value changes, and selected options\n const isFirstMount = useFirstMount();\n const [controllableValue, setValue] = useControllableState({\n state: props.value,\n initialState: undefined,\n });\n\n const value = React.useMemo(() => {\n // don't compute the value if it is defined through props or setValue,\n if (controllableValue !== undefined) {\n return controllableValue;\n }\n\n // handle defaultValue here, so it is overridden by selection\n if (isFirstMount && props.defaultValue !== undefined) {\n return props.defaultValue;\n }\n\n if (multiselect) {\n // editable inputs should not display multiple selected options in the input as text\n return editable ? '' : selectedOptions.join(', ');\n }\n\n return selectedOptions[0];\n }, [controllableValue, editable, isFirstMount, multiselect, props.defaultValue, selectedOptions]);\n\n // Handle open state, which is shared with options in context\n const [open, setOpenState] = useControllableState({\n state: props.open,\n defaultState: props.defaultOpen,\n initialState: false,\n });\n\n const setOpen = (event: ComboboxBaseOpenEvents, newState: boolean) => {\n onOpenChange?.(event, { open: newState });\n setOpenState(newState);\n };\n\n // update active option based on change in open state\n React.useEffect(() => {\n if (open && !activeOption) {\n // if there is a selection, start at the most recently selected item\n if (selectedOptions.length > 0) {\n const lastSelectedOption = getOptionsMatchingText(v => v === selectedOptions[selectedOptions.length - 1]).pop();\n lastSelectedOption && setActiveOption(lastSelectedOption);\n }\n // default to starting at the first option\n else {\n setActiveOption(getOptionAtIndex(0));\n }\n } else if (!open) {\n // reset the active option when closing\n setActiveOption(undefined);\n }\n // this should only be run in response to changes in the open state\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [open]);\n\n return {\n ...optionCollection,\n ...selectionState,\n activeOption,\n appearance,\n focusVisible,\n hasFocus,\n ignoreNextBlur,\n inlinePopup,\n open,\n setActiveOption,\n setFocusVisible,\n setHasFocus,\n setOpen,\n setValue,\n size,\n value,\n };\n};\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SAASC,oBAAoB,EAAEC,aAAa,QAAQ,2BAA2B;AAC/E,SAASC,mBAAmB,QAAQ,8BAA8B;AAElE,SA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,CAAC,EAAE,CAACI,IAAI,CAAC,CAAC;EAEV,OAAO;IACL,GAAGxB,gBAAgB;IACnB,GAAGY,cAAc;IACjBT,YAAY;IACZT,UAAU;IACVY,YAAY;IACZE,QAAQ;IACRE,cAAc;IACdd,WAAW;IACX4B,IAAI;IACJpB,eAAe;IACfG,eAAe;IACfE,WAAW;IACXmB,OAAO;IACPZ,QAAQ;IACRjB,IAAI;IACJmB;GACD;AACH,CAAC","names":["React","useControllableState","useFirstMount","useOptionCollection","useSelection","useComboboxBaseState","props","appearance","editable","inlinePopup","multiselect","onOpenChange","size","optionCollection","getOptionAtIndex","getOptionsMatchingText","activeOption","setActiveOption","useState","focusVisible","setFocusVisible","hasFocus","setHasFocus","ignoreNextBlur","useRef","selectionState","selectedOptions","isFirstMount","controllableValue","setValue","state","value","initialState","undefined","useMemo","defaultValue","join","open","setOpenState","defaultState","defaultOpen","setOpen","useCallback","event","newState","useEffect","length","selectedOption","v","pop"],"sourceRoot":"../src/","sources":["packages/react-components/react-combobox/src/utils/useComboboxBaseState.ts"],"sourcesContent":["import * as React from 'react';\nimport { useControllableState, useFirstMount } from '@fluentui/react-utilities';\nimport { useOptionCollection } from '../utils/useOptionCollection';\nimport { OptionValue } from '../utils/OptionCollection.types';\nimport { useSelection } from '../utils/useSelection';\nimport type { ComboboxBaseProps, ComboboxBaseOpenEvents, ComboboxBaseState } from './ComboboxBase.types';\n\n/**\n * State shared between Combobox and Dropdown components\n */\nexport const useComboboxBaseState = (props: ComboboxBaseProps & { editable?: boolean }): ComboboxBaseState => {\n const {\n appearance = 'outline',\n editable = false,\n inlinePopup = false,\n multiselect,\n onOpenChange,\n size = 'medium',\n } = props;\n\n const optionCollection = useOptionCollection();\n const { getOptionAtIndex, getOptionsMatchingText } = optionCollection;\n\n const [activeOption, setActiveOption] = React.useState<OptionValue | undefined>();\n\n // track whether keyboard focus outline should be shown\n // tabster/keyborg doesn't work here, since the actual keyboard focus target doesn't move\n const [focusVisible, setFocusVisible] = React.useState(false);\n\n // track focused state to conditionally render collapsed listbox\n const [hasFocus, setHasFocus] = React.useState(false);\n\n const ignoreNextBlur = React.useRef(false);\n\n const selectionState = useSelection(props);\n const { selectedOptions } = selectionState;\n\n // calculate value based on props, internal value changes, and selected options\n const isFirstMount = useFirstMount();\n const [controllableValue, setValue] = useControllableState({\n state: props.value,\n initialState: undefined,\n });\n\n const value = React.useMemo(() => {\n // don't compute the value if it is defined through props or setValue,\n if (controllableValue !== undefined) {\n return controllableValue;\n }\n\n // handle defaultValue here, so it is overridden by selection\n if (isFirstMount && props.defaultValue !== undefined) {\n return props.defaultValue;\n }\n\n if (multiselect) {\n // editable inputs should not display multiple selected options in the input as text\n return editable ? '' : selectedOptions.join(', ');\n }\n\n return selectedOptions[0];\n }, [controllableValue, editable, isFirstMount, multiselect, props.defaultValue, selectedOptions]);\n\n // Handle open state, which is shared with options in context\n const [open, setOpenState] = useControllableState({\n state: props.open,\n defaultState: props.defaultOpen,\n initialState: false,\n });\n\n const setOpen = React.useCallback(\n (event: ComboboxBaseOpenEvents, newState: boolean) => {\n onOpenChange?.(event, { open: newState });\n setOpenState(newState);\n },\n [onOpenChange, setOpenState],\n );\n\n // update active option based on change in open state\n React.useEffect(() => {\n if (open && !activeOption) {\n // if it is single-select and there is a selected option, start at the selected option\n if (!multiselect && selectedOptions.length > 0) {\n const selectedOption = getOptionsMatchingText(v => v === selectedOptions[0]).pop();\n selectedOption && setActiveOption(selectedOption);\n }\n // default to starting at the first option\n else {\n setActiveOption(getOptionAtIndex(0));\n }\n } else if (!open) {\n // reset the active option when closing\n setActiveOption(undefined);\n }\n // this should only be run in response to changes in the open state\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [open]);\n\n return {\n ...optionCollection,\n ...selectionState,\n activeOption,\n appearance,\n focusVisible,\n hasFocus,\n ignoreNextBlur,\n inlinePopup,\n open,\n setActiveOption,\n setFocusVisible,\n setHasFocus,\n setOpen,\n setValue,\n size,\n value,\n };\n};\n"]}
@@ -3,8 +3,8 @@ import { useMergedRefs } from '@fluentui/react-utilities';
3
3
  export function useComboboxPopup(props, triggerShorthand, listboxShorthand) {
4
4
  const {
5
5
  positioning
6
- } = props; // popper options
7
-
6
+ } = props;
7
+ // popper options
8
8
  const popperOptions = {
9
9
  position: 'below',
10
10
  align: 'start',
@@ -19,10 +19,12 @@ export function useComboboxPopup(props, triggerShorthand, listboxShorthand) {
19
19
  containerRef
20
20
  } = usePositioning(popperOptions);
21
21
  const listboxRef = useMergedRefs(listboxShorthand === null || listboxShorthand === void 0 ? void 0 : listboxShorthand.ref, containerRef);
22
- const listbox = listboxShorthand && { ...listboxShorthand,
22
+ const listbox = listboxShorthand && {
23
+ ...listboxShorthand,
23
24
  ref: listboxRef
24
25
  };
25
- return [{ ...triggerShorthand,
26
+ return [{
27
+ ...triggerShorthand,
26
28
  ref: useMergedRefs(triggerShorthand === null || triggerShorthand === void 0 ? void 0 : triggerShorthand.ref, targetRef)
27
29
  }, listbox];
28
30
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["packages/react-components/react-combobox/src/utils/useComboboxPopup.ts"],"names":[],"mappings":"AAAA,SAAS,2BAAT,EAAsC,cAAtC,QAA4D,6BAA5D;AACA,SAAiC,aAAjC,QAAsD,2BAAtD;AAeA,OAAM,SAAU,gBAAV,CACJ,KADI,EAEJ,gBAFI,EAGJ,gBAHI,EAGqD;EAKzD,MAAM;IAAE;EAAF,IAAkB,KAAxB,CALyD,CAOzD;;EACA,MAAM,aAAa,GAAG;IACpB,QAAQ,EAAE,OADU;IAEpB,KAAK,EAAE,OAFa;IAGpB,MAAM,EAAE;MAAE,SAAS,EAAE,CAAb;MAAgB,QAAQ,EAAE;IAA1B,CAHY;IAIpB,GAAG,2BAA2B,CAAC,WAAD;EAJV,CAAtB;EAOA,MAAM;IAAE,SAAF;IAAa;EAAb,IAA8B,cAAc,CAAC,aAAD,CAAlD;EAEA,MAAM,UAAU,GAAG,aAAa,CAAC,gBAAgB,KAAA,IAAhB,IAAA,gBAAgB,KAAA,KAAA,CAAhB,GAAgB,KAAA,CAAhB,GAAA,gBAAgB,CAAE,GAAnB,EAAwB,YAAxB,CAAhC;EACA,MAAM,OAAO,GAAG,gBAAgB,IAAI,EAAE,GAAG,gBAAL;IAAuB,GAAG,EAAE;EAA5B,CAApC;EAEA,OAAO,CAAC,EAAE,GAAG,gBAAL;IAAuB,GAAG,EAAE,aAAa,CAAC,gBAAgB,KAAA,IAAhB,IAAA,gBAAgB,KAAA,KAAA,CAAhB,GAAgB,KAAA,CAAhB,GAAA,gBAAgB,CAAE,GAAnB,EAAwB,SAAxB;EAAzC,CAAD,EAAgF,OAAhF,CAAP;AACD","sourcesContent":["import { resolvePositioningShorthand, usePositioning } from '@fluentui/react-positioning';\nimport { ExtractSlotProps, Slot, useMergedRefs } from '@fluentui/react-utilities';\nimport type { ComboboxBaseProps } from './ComboboxBase.types';\nimport { Listbox } from '../components/Listbox/Listbox';\n\nexport function useComboboxPopup(\n props: ComboboxBaseProps,\n triggerShorthand?: ExtractSlotProps<Slot<'button'>>,\n listboxShorthand?: ExtractSlotProps<Slot<typeof Listbox>>,\n): [trigger: ExtractSlotProps<Slot<'button'>>, listbox?: ExtractSlotProps<Slot<typeof Listbox>>];\nexport function useComboboxPopup(\n props: ComboboxBaseProps,\n triggerShorthand?: ExtractSlotProps<Slot<'input'>>,\n listboxShorthand?: ExtractSlotProps<Slot<typeof Listbox>>,\n): [trigger: ExtractSlotProps<Slot<'input'>>, listbox?: ExtractSlotProps<Slot<typeof Listbox>>];\n\nexport function useComboboxPopup(\n props: ComboboxBaseProps,\n triggerShorthand?: ExtractSlotProps<Slot<'input'>> | ExtractSlotProps<Slot<'button'>>,\n listboxShorthand?: ExtractSlotProps<Slot<typeof Listbox>>,\n): [\n trigger: ExtractSlotProps<Slot<'input'>> | ExtractSlotProps<Slot<'button'>>,\n listbox?: ExtractSlotProps<Slot<typeof Listbox>>,\n] {\n const { positioning } = props;\n\n // popper options\n const popperOptions = {\n position: 'below' as const,\n align: 'start' as const,\n offset: { crossAxis: 0, mainAxis: 2 },\n ...resolvePositioningShorthand(positioning),\n };\n\n const { targetRef, containerRef } = usePositioning(popperOptions);\n\n const listboxRef = useMergedRefs(listboxShorthand?.ref, containerRef);\n const listbox = listboxShorthand && { ...listboxShorthand, ref: listboxRef };\n\n return [{ ...triggerShorthand, ref: useMergedRefs(triggerShorthand?.ref, targetRef) }, listbox];\n}\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"mappings":"AAAA,SAASA,2BAA2B,EAAEC,cAAc,QAAQ,6BAA6B;AACzF,SAAiCC,aAAa,QAAQ,2BAA2B;AAejF,OAAM,SAAUC,gBAAgB,CAC9BC,KAAwB,EACxBC,gBAAqF,EACrFC,gBAAyD;EAKzD,MAAM;IAAEC;EAAW,CAAE,GAAGH,KAAK;EAE7B;EACA,MAAMI,aAAa,GAAG;IACpBC,QAAQ,EAAE,OAAgB;IAC1BC,KAAK,EAAE,OAAgB;IACvBC,MAAM,EAAE;MAAEC,SAAS,EAAE,CAAC;MAAEC,QAAQ,EAAE;IAAC,CAAE;IACrC,GAAGb,2BAA2B,CAACO,WAAW;GAC3C;EAED,MAAM;IAAEO,SAAS;IAAEC;EAAY,CAAE,GAAGd,cAAc,CAACO,aAAa,CAAC;EAEjE,MAAMQ,UAAU,GAAGd,aAAa,CAACI,gBAAgB,aAAhBA,gBAAgB,uBAAhBA,gBAAgB,CAAEW,GAAG,EAAEF,YAAY,CAAC;EACrE,MAAMG,OAAO,GAAGZ,gBAAgB,IAAI;IAAE,GAAGA,gBAAgB;IAAEW,GAAG,EAAED;EAAU,CAAE;EAE5E,OAAO,CAAC;IAAE,GAAGX,gBAAgB;IAAEY,GAAG,EAAEf,aAAa,CAACG,gBAAgB,aAAhBA,gBAAgB,uBAAhBA,gBAAgB,CAAEY,GAAG,EAAEH,SAAS;EAAC,CAAE,EAAEI,OAAO,CAAC;AACjG","names":["resolvePositioningShorthand","usePositioning","useMergedRefs","useComboboxPopup","props","triggerShorthand","listboxShorthand","positioning","popperOptions","position","align","offset","crossAxis","mainAxis","targetRef","containerRef","listboxRef","ref","listbox"],"sourceRoot":"../src/","sources":["packages/react-components/react-combobox/src/utils/useComboboxPopup.ts"],"sourcesContent":["import { resolvePositioningShorthand, usePositioning } from '@fluentui/react-positioning';\nimport { ExtractSlotProps, Slot, useMergedRefs } from '@fluentui/react-utilities';\nimport type { ComboboxBaseProps } from './ComboboxBase.types';\nimport { Listbox } from '../components/Listbox/Listbox';\n\nexport function useComboboxPopup(\n props: ComboboxBaseProps,\n triggerShorthand?: ExtractSlotProps<Slot<'button'>>,\n listboxShorthand?: ExtractSlotProps<Slot<typeof Listbox>>,\n): [trigger: ExtractSlotProps<Slot<'button'>>, listbox?: ExtractSlotProps<Slot<typeof Listbox>>];\nexport function useComboboxPopup(\n props: ComboboxBaseProps,\n triggerShorthand?: ExtractSlotProps<Slot<'input'>>,\n listboxShorthand?: ExtractSlotProps<Slot<typeof Listbox>>,\n): [trigger: ExtractSlotProps<Slot<'input'>>, listbox?: ExtractSlotProps<Slot<typeof Listbox>>];\n\nexport function useComboboxPopup(\n props: ComboboxBaseProps,\n triggerShorthand?: ExtractSlotProps<Slot<'input'>> | ExtractSlotProps<Slot<'button'>>,\n listboxShorthand?: ExtractSlotProps<Slot<typeof Listbox>>,\n): [\n trigger: ExtractSlotProps<Slot<'input'>> | ExtractSlotProps<Slot<'button'>>,\n listbox?: ExtractSlotProps<Slot<typeof Listbox>>,\n] {\n const { positioning } = props;\n\n // popper options\n const popperOptions = {\n position: 'below' as const,\n align: 'start' as const,\n offset: { crossAxis: 0, mainAxis: 2 },\n ...resolvePositioningShorthand(positioning),\n };\n\n const { targetRef, containerRef } = usePositioning(popperOptions);\n\n const listboxRef = useMergedRefs(listboxShorthand?.ref, containerRef);\n const listbox = listboxShorthand && { ...listboxShorthand, ref: listboxRef };\n\n return [{ ...triggerShorthand, ref: useMergedRefs(triggerShorthand?.ref, targetRef) }, listbox];\n}\n"]}
@@ -2,29 +2,22 @@ import * as React from 'react';
2
2
  /**
3
3
  * A hook for managing a collection of child Options
4
4
  */
5
-
6
5
  export const useOptionCollection = () => {
7
6
  const nodes = React.useRef([]);
8
7
  const collectionAPI = React.useMemo(() => {
9
8
  const getCount = () => nodes.current.length;
10
-
11
9
  const getOptionAtIndex = index => {
12
10
  var _a;
13
-
14
11
  return (_a = nodes.current[index]) === null || _a === void 0 ? void 0 : _a.option;
15
12
  };
16
-
17
13
  const getIndexOfId = id => nodes.current.findIndex(node => node.option.id === id);
18
-
19
14
  const getOptionById = id => {
20
15
  const item = nodes.current.find(node => node.option.id === id);
21
16
  return item === null || item === void 0 ? void 0 : item.option;
22
17
  };
23
-
24
18
  const getOptionsMatchingText = matcher => {
25
19
  return nodes.current.filter(node => matcher(node.option.text)).map(node => node.option);
26
20
  };
27
-
28
21
  return {
29
22
  getCount,
30
23
  getOptionAtIndex,
@@ -35,40 +28,37 @@ export const useOptionCollection = () => {
35
28
  }, []);
36
29
  const registerOption = React.useCallback((option, element) => {
37
30
  var _a;
38
-
39
31
  const index = nodes.current.findIndex(node => {
40
32
  if (!node.element || !element) {
41
33
  return false;
42
34
  }
43
-
44
35
  if (node.option.id === option.id) {
45
36
  return true;
46
- } // use the DOM method compareDocumentPosition to order the current node against registered nodes
37
+ }
38
+ // use the DOM method compareDocumentPosition to order the current node against registered nodes
47
39
  // eslint-disable-next-line no-bitwise
48
-
49
-
50
40
  return node.element.compareDocumentPosition(element) & Node.DOCUMENT_POSITION_PRECEDING;
51
- }); // do not register the option if it already exists
52
-
41
+ });
42
+ // do not register the option if it already exists
53
43
  if (((_a = nodes.current[index]) === null || _a === void 0 ? void 0 : _a.option.id) !== option.id) {
54
44
  const newItem = {
55
45
  element,
56
46
  option
57
- }; // If an index is not found we will push the element to the end.
58
-
47
+ };
48
+ // If an index is not found we will push the element to the end.
59
49
  if (index === -1) {
60
50
  nodes.current = [...nodes.current, newItem];
61
51
  } else {
62
52
  nodes.current.splice(index, 0, newItem);
63
53
  }
64
- } // return the unregister function
65
-
66
-
54
+ }
55
+ // return the unregister function
67
56
  return () => {
68
57
  nodes.current = nodes.current.filter(node => node.option.id !== option.id);
69
58
  };
70
59
  }, []);
71
- return { ...collectionAPI,
60
+ return {
61
+ ...collectionAPI,
72
62
  options: nodes.current.map(node => node.option),
73
63
  registerOption
74
64
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["packages/react-components/react-combobox/src/utils/useOptionCollection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AAGA;;AAEG;;AACH,OAAO,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,KAAK,CAAC,OAAN,CAAc,SAAd,CAAwB,IAAI,IAAI,IAAI,CAAC,MAAL,CAAY,EAAZ,KAAmB,EAAnD,CAArC;;IACA,MAAM,aAAa,GAAI,EAAD,IAAe;MACnC,MAAM,IAAI,GAAG,KAAK,CAAC,OAAN,CAAc,IAAd,CAAmB,IAAI,IAAI,IAAI,CAAC,MAAL,CAAY,EAAZ,KAAmB,EAA9C,CAAb;MACA,OAAO,IAAI,KAAA,IAAJ,IAAA,IAAI,KAAA,KAAA,CAAJ,GAAI,KAAA,CAAJ,GAAA,IAAI,CAAE,MAAb;IACD,CAHD;;IAIA,MAAM,sB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AAC,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","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,OAAO,KAAKA,KAAK,MAAM,OAAO;AAG9B;;;AAGA,OAAO,MAAMC,mBAAmB,GAAG,MAA4B;EAC7D,MAAMC,KAAK,GAAGF,KAAK,CAACG,MAAM,CAAkD,EAAE,CAAC;EAE/E,MAAMC,aAAa,GAAGJ,KAAK,CAACK,OAAO,CAAC,MAAK;IACvC,MAAMC,QAAQ,GAAG,MAAMJ,KAAK,CAACK,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,IAAKX,KAAK,CAACK,OAAO,CAACO,SAAS,CAACC,IAAI,IAAIA,IAAI,CAACJ,MAAM,CAACE,EAAE,KAAKA,EAAE,CAAC;IAC3F,MAAMG,aAAa,GAAIH,EAAU,IAAI;MACnC,MAAMI,IAAI,GAAGf,KAAK,CAACK,OAAO,CAACW,IAAI,CAACH,IAAI,IAAIA,IAAI,CAACJ,MAAM,CAACE,EAAE,KAAKA,EAAE,CAAC;MAC9D,OAAOI,IAAI,aAAJA,IAAI,uBAAJA,IAAI,CAAEN,MAAM;IACrB,CAAC;IACD,MAAMQ,sBAAsB,GAAIC,OAAmC,IAAI;MACrE,OAAOlB,KAAK,CAACK,OAAO,CAACc,MAAM,CAACN,IAAI,IAAIK,OAAO,CAACL,IAAI,CAACJ,MAAM,CAACW,IAAI,CAAC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E,CAAC;EAEN,OAAO;IACL,GAAGT,aAAa;IAChB4B,OAAO,EAAE9B,KAAK,CAACK,OAAO,CAACgB,GAAG,CAACR,IAAI,IAAIA,IAAI,CAACJ,MAAM,CAAC;IAC/Ca;GACD;AACH,CAAC","names":["React","useOptionCollection","nodes","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"],"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"]}
@@ -8,11 +8,9 @@ export function useScrollOptionsIntoView(state) {
8
8
  React.useEffect(() => {
9
9
  if (scrollContainerRef.current && activeOption && canUseDOM()) {
10
10
  const activeOptionElement = scrollContainerRef.current.querySelector(`#${activeOption.id}`);
11
-
12
11
  if (!activeOptionElement) {
13
12
  return;
14
13
  }
15
-
16
14
  const {
17
15
  offsetHeight,
18
16
  offsetTop
@@ -22,11 +20,10 @@ export function useScrollOptionsIntoView(state) {
22
20
  scrollTop
23
21
  } = scrollContainerRef.current;
24
22
  const isAbove = offsetTop < scrollTop;
25
- const isBelow = offsetTop + offsetHeight > scrollTop + parentOffsetHeight; // add a small buffer for general visual nicety
23
+ const isBelow = offsetTop + offsetHeight > scrollTop + parentOffsetHeight;
24
+ // add a small buffer for general visual nicety
26
25
  // it looks slightly better if the option has some space from the top/bottom while arrowing
27
-
28
26
  const buffer = 2;
29
-
30
27
  if (isAbove) {
31
28
  scrollContainerRef.current.scrollTo(0, offsetTop - buffer);
32
29
  } else if (isBelow) {
@@ -1 +1 @@
1
- {"version":3,"sources":["packages/react-components/react-combobox/src/utils/useScrollOptionsIntoView.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,SAAT,QAA0B,2BAA1B;AAGA,OAAM,SAAU,wBAAV,CAAmC,KAAnC,EAAsD;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,SAAS,EAA3D,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","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,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SAASC,SAAS,QAAQ,2BAA2B;AAGrD,OAAM,SAAUC,wBAAwB,CAACC,KAAmB;EAC1D,MAAM;IAAEC;EAAY,CAAE,GAAGD,KAAK;EAC9B,MAAME,kBAAkB,GAAGL,KAAK,CAACM,MAAM,CAAiB,IAAI,CAAC;EAE7DN,KAAK,CAACO,SAAS,CAAC,MAAK;IACnB,IAAIF,kBAAkB,CAACG,OAAO,IAAIJ,YAAY,IAAIH,SAAS,EAAE,EAAE;MAC7D,MAAMQ,mBAAmB,GAAGJ,kBAAkB,CAACG,OAAO,CAACE,aAAa,CAAC,IAAIN,YAAY,CAACO,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,GAAGV,kBAAkB,CAACG,OAAO;MAElF,MAAMQ,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;QACXX,kBAAkB,CAACG,OAAO,CAACW,QAAQ,CAAC,CAAC,EAAEN,SAAS,GAAGK,MAAM,CAAC;OAC3D,MAAM,IAAID,OAAO,EAAE;QAClBZ,kBAAkB,CAACG,OAAO,CAACW,QAAQ,CAAC,CAAC,EAAEN,SAAS,GAAGC,kBAAkB,GAAGF,YAAY,GAAGM,MAAM,CAAC;;;EAGpG,CAAC,EAAE,CAACd,YAAY,CAAC,CAAC;EAElB,OAAOC,kBAAkB;AAC3B","names":["React","canUseDOM","useScrollOptionsIntoView","state","activeOption","scrollContainerRef","useRef","useEffect","current","activeOptionElement","querySelector","id","offsetHeight","offsetTop","parentOffsetHeight","scrollTop","isAbove","isBelow","buffer","scrollTo"],"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"]}
@@ -1,3 +1,4 @@
1
+ import { useCallback } from 'react';
1
2
  import { useControllableState } from '@fluentui/react-utilities';
2
3
  export const useSelection = props => {
3
4
  const {
@@ -10,19 +11,16 @@ export const useSelection = props => {
10
11
  defaultState: defaultSelectedOptions,
11
12
  initialState: []
12
13
  });
13
-
14
- const selectOption = (event, option) => {
14
+ const selectOption = useCallback((event, option) => {
15
15
  // if the option is disabled, do nothing
16
16
  if (option.disabled) {
17
17
  return;
18
- } // for single-select, always return the selected option
19
-
20
-
21
- let newSelection = [option.value]; // toggle selected state of the option for multiselect
22
-
18
+ }
19
+ // for single-select, always return the selected option
20
+ let newSelection = [option.value];
21
+ // toggle selected state of the option for multiselect
23
22
  if (multiselect) {
24
23
  const selectedIndex = selectedOptions.findIndex(o => o === option.value);
25
-
26
24
  if (selectedIndex > -1) {
27
25
  // deselect option
28
26
  newSelection = [...selectedOptions.slice(0, selectedIndex), ...selectedOptions.slice(selectedIndex + 1)];
@@ -31,15 +29,13 @@ export const useSelection = props => {
31
29
  newSelection = [...selectedOptions, option.value];
32
30
  }
33
31
  }
34
-
35
32
  setSelectedOptions(newSelection);
36
33
  onOptionSelect === null || onOptionSelect === void 0 ? void 0 : onOptionSelect(event, {
37
34
  optionValue: option.value,
38
35
  optionText: option.text,
39
36
  selectedOptions: newSelection
40
37
  });
41
- };
42
-
38
+ }, [onOptionSelect, multiselect, selectedOptions, setSelectedOptions]);
43
39
  const clearSelection = event => {
44
40
  setSelectedOptions([]);
45
41
  onOptionSelect === null || onOptionSelect === void 0 ? void 0 : onOptionSelect(event, {
@@ -48,7 +44,6 @@ export const useSelection = props => {
48
44
  selectedOptions: []
49
45
  });
50
46
  };
51
-
52
47
  return {
53
48
  clearSelection,
54
49
  selectOption,
@@ -1 +1 @@
1
- {"version":3,"sources":["packages/react-components/react-combobox/src/utils/useSelection.ts"],"names":[],"mappings":"AAAA,SAAS,oBAAT,QAAqC,2BAArC;AAIA,OAAO,MAAM,YAAY,GAAI,KAAD,IAA0C;EACpE,MAAM;IAAE,sBAAF;IAA0B,WAA1B;IAAuC;EAAvC,IAA0D,KAAhE;EAEA,MAAM,CAAC,eA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MAA0B,UAAU,EAAE,SAAtC;MAAiD,eAAe,EAAE;IAAlE,CAAV,CAAd;EACD,CAHD;;EAKA,OAAO;IAAE,cAAF;IAAkB,YAAlB;IAAgC;EAAhC,CAAP;AACD,CAxCM","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,SAASA,WAAW,QAAQ,OAAO;AACnC,SAASC,oBAAoB,QAAQ,2BAA2B;AAIhE,OAAO,MAAMC,YAAY,GAAIC,KAAqB,IAAoB;EACpE,MAAM;IAAEC,sBAAsB;IAAEC,WAAW;IAAEC;EAAc,CAAE,GAAGH,KAAK;EAErE,MAAM,CAACI,eAAe,EAAEC,kBAAkB,CAAC,GAAGP,oBAAoB,CAAC;I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ED,OAAO;IAAEkB,cAAc;IAAEb,YAAY;IAAEL;EAAe,CAAE;AAC1D,CAAC","names":["useCallback","useControllableState","useSelection","props","defaultSelectedOptions","multiselect","onOptionSelect","selectedOptions","setSelectedOptions","state","defaultState","initialState","selectOption","event","option","disabled","newSelection","value","selectedIndex","findIndex","o","slice","optionValue","optionText","text","clearSelection","undefined"],"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"]}