@fluentui/react-combobox 9.3.4 → 9.4.1

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 (208) hide show
  1. package/CHANGELOG.json +141 -1
  2. package/CHANGELOG.md +41 -2
  3. package/dist/index.d.ts +2 -2
  4. package/lib/Combobox.js +0 -1
  5. package/lib/Combobox.js.map +1 -1
  6. package/lib/Dropdown.js +0 -1
  7. package/lib/Dropdown.js.map +1 -1
  8. package/lib/Listbox.js +0 -1
  9. package/lib/Listbox.js.map +1 -1
  10. package/lib/Option.js +0 -1
  11. package/lib/Option.js.map +1 -1
  12. package/lib/OptionGroup.js +0 -1
  13. package/lib/OptionGroup.js.map +1 -1
  14. package/lib/Selection.js +1 -0
  15. package/lib/Selection.js.map +1 -0
  16. package/lib/components/Combobox/Combobox.js +6 -8
  17. package/lib/components/Combobox/Combobox.js.map +1 -1
  18. package/lib/components/Combobox/Combobox.types.js +0 -1
  19. package/lib/components/Combobox/Combobox.types.js.map +1 -1
  20. package/lib/components/Combobox/index.js +0 -1
  21. package/lib/components/Combobox/index.js.map +1 -1
  22. package/lib/components/Combobox/renderCombobox.js +6 -11
  23. package/lib/components/Combobox/renderCombobox.js.map +1 -1
  24. package/lib/components/Combobox/useCombobox.js +228 -251
  25. package/lib/components/Combobox/useCombobox.js.map +1 -1
  26. package/lib/components/Combobox/useComboboxStyles.styles.js.map +1 -1
  27. package/lib/components/Dropdown/Dropdown.js +6 -8
  28. package/lib/components/Dropdown/Dropdown.js.map +1 -1
  29. package/lib/components/Dropdown/Dropdown.types.js +1 -2
  30. package/lib/components/Dropdown/Dropdown.types.js.map +1 -1
  31. package/lib/components/Dropdown/index.js +0 -1
  32. package/lib/components/Dropdown/index.js.map +1 -1
  33. package/lib/components/Dropdown/renderDropdown.js +6 -11
  34. package/lib/components/Dropdown/renderDropdown.js.map +1 -1
  35. package/lib/components/Dropdown/useDropdown.js +127 -136
  36. package/lib/components/Dropdown/useDropdown.js.map +1 -1
  37. package/lib/components/Dropdown/useDropdownStyles.styles.js.map +1 -1
  38. package/lib/components/Listbox/Listbox.js +6 -8
  39. package/lib/components/Listbox/Listbox.js.map +1 -1
  40. package/lib/components/Listbox/Listbox.types.js +1 -2
  41. package/lib/components/Listbox/Listbox.types.js.map +1 -1
  42. package/lib/components/Listbox/index.js +0 -1
  43. package/lib/components/Listbox/index.js.map +1 -1
  44. package/lib/components/Listbox/renderListbox.js +6 -11
  45. package/lib/components/Listbox/renderListbox.js.map +1 -1
  46. package/lib/components/Listbox/useListbox.js +77 -89
  47. package/lib/components/Listbox/useListbox.js.map +1 -1
  48. package/lib/components/Listbox/useListboxStyles.styles.js.map +1 -1
  49. package/lib/components/Option/Option.js +5 -7
  50. package/lib/components/Option/Option.js.map +1 -1
  51. package/lib/components/Option/Option.types.js +0 -1
  52. package/lib/components/Option/Option.types.js.map +1 -1
  53. package/lib/components/Option/index.js +0 -1
  54. package/lib/components/Option/index.js.map +1 -1
  55. package/lib/components/Option/renderOption.js +4 -9
  56. package/lib/components/Option/renderOption.js.map +1 -1
  57. package/lib/components/Option/useOption.js +115 -113
  58. package/lib/components/Option/useOption.js.map +1 -1
  59. package/lib/components/Option/useOptionStyles.styles.js +1 -1
  60. package/lib/components/Option/useOptionStyles.styles.js.map +1 -1
  61. package/lib/components/OptionGroup/OptionGroup.js +5 -7
  62. package/lib/components/OptionGroup/OptionGroup.js.map +1 -1
  63. package/lib/components/OptionGroup/OptionGroup.types.js +1 -2
  64. package/lib/components/OptionGroup/OptionGroup.types.js.map +1 -1
  65. package/lib/components/OptionGroup/index.js +0 -1
  66. package/lib/components/OptionGroup/index.js.map +1 -1
  67. package/lib/components/OptionGroup/renderOptionGroup.js +4 -9
  68. package/lib/components/OptionGroup/renderOptionGroup.js.map +1 -1
  69. package/lib/components/OptionGroup/useOptionGroup.js +21 -25
  70. package/lib/components/OptionGroup/useOptionGroup.js.map +1 -1
  71. package/lib/components/OptionGroup/useOptionGroupStyles.styles.js.map +1 -1
  72. package/lib/contexts/ComboboxContext.js +16 -17
  73. package/lib/contexts/ComboboxContext.js.map +1 -1
  74. package/lib/contexts/ListboxContext.js +12 -13
  75. package/lib/contexts/ListboxContext.js.map +1 -1
  76. package/lib/contexts/useComboboxContextValues.js +16 -28
  77. package/lib/contexts/useComboboxContextValues.js.map +1 -1
  78. package/lib/contexts/useListboxContextValues.js +17 -26
  79. package/lib/contexts/useListboxContextValues.js.map +1 -1
  80. package/lib/index.js +0 -1
  81. package/lib/index.js.map +1 -1
  82. package/lib/utils/ComboboxBase.types.js +0 -1
  83. package/lib/utils/ComboboxBase.types.js.map +1 -1
  84. package/lib/utils/OptionCollection.types.js +1 -2
  85. package/lib/utils/OptionCollection.types.js.map +1 -1
  86. package/lib/utils/Selection.types.js +0 -1
  87. package/lib/utils/Selection.types.js.map +1 -1
  88. package/lib/utils/dropdownKeyActions.js +66 -77
  89. package/lib/utils/dropdownKeyActions.js.map +1 -1
  90. package/lib/utils/internalTokens.js +3 -4
  91. package/lib/utils/internalTokens.js.map +1 -1
  92. package/lib/utils/useComboboxBaseState.js +94 -96
  93. package/lib/utils/useComboboxBaseState.js.map +1 -1
  94. package/lib/utils/useComboboxPopup.js +33 -30
  95. package/lib/utils/useComboboxPopup.js.map +1 -1
  96. package/lib/utils/useOptionCollection.js +65 -64
  97. package/lib/utils/useOptionCollection.js.map +1 -1
  98. package/lib/utils/useScrollOptionsIntoView.js +25 -32
  99. package/lib/utils/useScrollOptionsIntoView.js.map +1 -1
  100. package/lib/utils/useSelection.js +57 -49
  101. package/lib/utils/useSelection.js.map +1 -1
  102. package/lib/utils/useTriggerListboxSlots.js +105 -119
  103. package/lib/utils/useTriggerListboxSlots.js.map +1 -1
  104. package/lib-commonjs/Combobox.js +0 -3
  105. package/lib-commonjs/Combobox.js.map +1 -1
  106. package/lib-commonjs/Dropdown.js +0 -3
  107. package/lib-commonjs/Dropdown.js.map +1 -1
  108. package/lib-commonjs/Listbox.js +0 -3
  109. package/lib-commonjs/Listbox.js.map +1 -1
  110. package/lib-commonjs/Option.js +0 -3
  111. package/lib-commonjs/Option.js.map +1 -1
  112. package/lib-commonjs/OptionGroup.js +0 -3
  113. package/lib-commonjs/OptionGroup.js.map +1 -1
  114. package/lib-commonjs/Selection.js +6 -0
  115. package/lib-commonjs/Selection.js.map +1 -0
  116. package/lib-commonjs/components/Combobox/Combobox.js +1 -3
  117. package/lib-commonjs/components/Combobox/Combobox.js.map +1 -1
  118. package/lib-commonjs/components/Combobox/Combobox.types.js +0 -3
  119. package/lib-commonjs/components/Combobox/Combobox.types.js.map +1 -1
  120. package/lib-commonjs/components/Combobox/index.js +0 -3
  121. package/lib-commonjs/components/Combobox/index.js.map +1 -1
  122. package/lib-commonjs/components/Combobox/renderCombobox.js +1 -3
  123. package/lib-commonjs/components/Combobox/renderCombobox.js.map +1 -1
  124. package/lib-commonjs/components/Combobox/useCombobox.js +1 -3
  125. package/lib-commonjs/components/Combobox/useCombobox.js.map +1 -1
  126. package/lib-commonjs/components/Combobox/useComboboxStyles.styles.js +0 -2
  127. package/lib-commonjs/components/Combobox/useComboboxStyles.styles.js.map +1 -1
  128. package/lib-commonjs/components/Dropdown/Dropdown.js +1 -3
  129. package/lib-commonjs/components/Dropdown/Dropdown.js.map +1 -1
  130. package/lib-commonjs/components/Dropdown/Dropdown.types.js +0 -3
  131. package/lib-commonjs/components/Dropdown/Dropdown.types.js.map +1 -1
  132. package/lib-commonjs/components/Dropdown/index.js +0 -3
  133. package/lib-commonjs/components/Dropdown/index.js.map +1 -1
  134. package/lib-commonjs/components/Dropdown/renderDropdown.js +1 -3
  135. package/lib-commonjs/components/Dropdown/renderDropdown.js.map +1 -1
  136. package/lib-commonjs/components/Dropdown/useDropdown.js +1 -3
  137. package/lib-commonjs/components/Dropdown/useDropdown.js.map +1 -1
  138. package/lib-commonjs/components/Dropdown/useDropdownStyles.styles.js +0 -2
  139. package/lib-commonjs/components/Dropdown/useDropdownStyles.styles.js.map +1 -1
  140. package/lib-commonjs/components/Listbox/Listbox.js +1 -3
  141. package/lib-commonjs/components/Listbox/Listbox.js.map +1 -1
  142. package/lib-commonjs/components/Listbox/Listbox.types.js +0 -3
  143. package/lib-commonjs/components/Listbox/Listbox.types.js.map +1 -1
  144. package/lib-commonjs/components/Listbox/index.js +0 -3
  145. package/lib-commonjs/components/Listbox/index.js.map +1 -1
  146. package/lib-commonjs/components/Listbox/renderListbox.js +1 -3
  147. package/lib-commonjs/components/Listbox/renderListbox.js.map +1 -1
  148. package/lib-commonjs/components/Listbox/useListbox.js +1 -3
  149. package/lib-commonjs/components/Listbox/useListbox.js.map +1 -1
  150. package/lib-commonjs/components/Listbox/useListboxStyles.styles.js +0 -2
  151. package/lib-commonjs/components/Listbox/useListboxStyles.styles.js.map +1 -1
  152. package/lib-commonjs/components/Option/Option.js +1 -3
  153. package/lib-commonjs/components/Option/Option.js.map +1 -1
  154. package/lib-commonjs/components/Option/Option.types.js +0 -3
  155. package/lib-commonjs/components/Option/Option.types.js.map +1 -1
  156. package/lib-commonjs/components/Option/index.js +0 -3
  157. package/lib-commonjs/components/Option/index.js.map +1 -1
  158. package/lib-commonjs/components/Option/renderOption.js +1 -3
  159. package/lib-commonjs/components/Option/renderOption.js.map +1 -1
  160. package/lib-commonjs/components/Option/useOption.js +1 -3
  161. package/lib-commonjs/components/Option/useOption.js.map +1 -1
  162. package/lib-commonjs/components/Option/useOptionStyles.styles.js +1 -3
  163. package/lib-commonjs/components/Option/useOptionStyles.styles.js.map +1 -1
  164. package/lib-commonjs/components/OptionGroup/OptionGroup.js +1 -3
  165. package/lib-commonjs/components/OptionGroup/OptionGroup.js.map +1 -1
  166. package/lib-commonjs/components/OptionGroup/OptionGroup.types.js +0 -3
  167. package/lib-commonjs/components/OptionGroup/OptionGroup.types.js.map +1 -1
  168. package/lib-commonjs/components/OptionGroup/index.js +0 -3
  169. package/lib-commonjs/components/OptionGroup/index.js.map +1 -1
  170. package/lib-commonjs/components/OptionGroup/renderOptionGroup.js +1 -3
  171. package/lib-commonjs/components/OptionGroup/renderOptionGroup.js.map +1 -1
  172. package/lib-commonjs/components/OptionGroup/useOptionGroup.js +1 -3
  173. package/lib-commonjs/components/OptionGroup/useOptionGroup.js.map +1 -1
  174. package/lib-commonjs/components/OptionGroup/useOptionGroupStyles.styles.js +0 -2
  175. package/lib-commonjs/components/OptionGroup/useOptionGroupStyles.styles.js.map +1 -1
  176. package/lib-commonjs/contexts/ComboboxContext.js +2 -4
  177. package/lib-commonjs/contexts/ComboboxContext.js.map +1 -1
  178. package/lib-commonjs/contexts/ListboxContext.js +2 -4
  179. package/lib-commonjs/contexts/ListboxContext.js.map +1 -1
  180. package/lib-commonjs/contexts/useComboboxContextValues.js +1 -3
  181. package/lib-commonjs/contexts/useComboboxContextValues.js.map +1 -1
  182. package/lib-commonjs/contexts/useListboxContextValues.js +1 -3
  183. package/lib-commonjs/contexts/useListboxContextValues.js.map +1 -1
  184. package/lib-commonjs/index.js +0 -3
  185. package/lib-commonjs/index.js.map +1 -1
  186. package/lib-commonjs/utils/ComboboxBase.types.js +0 -3
  187. package/lib-commonjs/utils/ComboboxBase.types.js.map +1 -1
  188. package/lib-commonjs/utils/OptionCollection.types.js +0 -3
  189. package/lib-commonjs/utils/OptionCollection.types.js.map +1 -1
  190. package/lib-commonjs/utils/Selection.types.js +0 -3
  191. package/lib-commonjs/utils/Selection.types.js.map +1 -1
  192. package/lib-commonjs/utils/dropdownKeyActions.js +1 -3
  193. package/lib-commonjs/utils/dropdownKeyActions.js.map +1 -1
  194. package/lib-commonjs/utils/internalTokens.js +1 -3
  195. package/lib-commonjs/utils/internalTokens.js.map +1 -1
  196. package/lib-commonjs/utils/useComboboxBaseState.js +1 -3
  197. package/lib-commonjs/utils/useComboboxBaseState.js.map +1 -1
  198. package/lib-commonjs/utils/useComboboxPopup.js +1 -3
  199. package/lib-commonjs/utils/useComboboxPopup.js.map +1 -1
  200. package/lib-commonjs/utils/useOptionCollection.js +1 -3
  201. package/lib-commonjs/utils/useOptionCollection.js.map +1 -1
  202. package/lib-commonjs/utils/useScrollOptionsIntoView.js +1 -3
  203. package/lib-commonjs/utils/useScrollOptionsIntoView.js.map +1 -1
  204. package/lib-commonjs/utils/useSelection.js +1 -3
  205. package/lib-commonjs/utils/useSelection.js.map +1 -1
  206. package/lib-commonjs/utils/useTriggerListboxSlots.js +5 -7
  207. package/lib-commonjs/utils/useTriggerListboxSlots.js.map +1 -1
  208. package/package.json +12 -12
@@ -4,107 +4,105 @@ import { useOptionCollection } from '../utils/useOptionCollection';
4
4
  import { useSelection } from '../utils/useSelection';
5
5
  /**
6
6
  * State shared between Combobox and Dropdown components
7
- */
8
- export const useComboboxBaseState = props => {
9
- const {
10
- appearance = 'outline',
11
- children,
12
- editable = false,
13
- inlinePopup = false,
14
- multiselect,
15
- onOpenChange,
16
- size = 'medium'
17
- } = props;
18
- const optionCollection = useOptionCollection();
19
- const {
20
- getOptionAtIndex,
21
- getOptionsMatchingValue
22
- } = optionCollection;
23
- const [activeOption, setActiveOption] = React.useState();
24
- // track whether keyboard focus outline should be shown
25
- // tabster/keyborg doesn't work here, since the actual keyboard focus target doesn't move
26
- const [focusVisible, setFocusVisible] = React.useState(false);
27
- // track focused state to conditionally render collapsed listbox
28
- const [hasFocus, setHasFocus] = React.useState(false);
29
- const ignoreNextBlur = React.useRef(false);
30
- const selectionState = useSelection(props);
31
- const {
32
- selectedOptions
33
- } = selectionState;
34
- // calculate value based on props, internal value changes, and selected options
35
- const isFirstMount = useFirstMount();
36
- const [controllableValue, setValue] = useControllableState({
37
- state: props.value,
38
- initialState: undefined
39
- });
40
- const value = React.useMemo(() => {
41
- // don't compute the value if it is defined through props or setValue,
42
- if (controllableValue !== undefined) {
43
- return controllableValue;
44
- }
45
- // handle defaultValue here, so it is overridden by selection
46
- if (isFirstMount && props.defaultValue !== undefined) {
47
- return props.defaultValue;
48
- }
49
- const selectedOptionsText = getOptionsMatchingValue(optionValue => {
50
- return selectedOptions.includes(optionValue);
51
- }).map(option => option.text);
52
- if (multiselect) {
53
- // editable inputs should not display multiple selected options in the input as text
54
- return editable ? '' : selectedOptionsText.join(', ');
55
- }
56
- return selectedOptionsText[0];
7
+ */ export const useComboboxBaseState = (props)=>{
8
+ const { appearance ='outline' , children , editable =false , inlinePopup =false , multiselect , onOpenChange , size ='medium' } = props;
9
+ const optionCollection = useOptionCollection();
10
+ const { getOptionAtIndex , getOptionsMatchingValue } = optionCollection;
11
+ const [activeOption, setActiveOption] = React.useState();
12
+ // track whether keyboard focus outline should be shown
13
+ // tabster/keyborg doesn't work here, since the actual keyboard focus target doesn't move
14
+ const [focusVisible, setFocusVisible] = React.useState(false);
15
+ // track focused state to conditionally render collapsed listbox
16
+ const [hasFocus, setHasFocus] = React.useState(false);
17
+ const ignoreNextBlur = React.useRef(false);
18
+ const selectionState = useSelection(props);
19
+ const { selectedOptions } = selectionState;
20
+ // calculate value based on props, internal value changes, and selected options
21
+ const isFirstMount = useFirstMount();
22
+ const [controllableValue, setValue] = useControllableState({
23
+ state: props.value,
24
+ initialState: undefined
25
+ });
26
+ const value = React.useMemo(()=>{
27
+ // don't compute the value if it is defined through props or setValue,
28
+ if (controllableValue !== undefined) {
29
+ return controllableValue;
30
+ }
31
+ // handle defaultValue here, so it is overridden by selection
32
+ if (isFirstMount && props.defaultValue !== undefined) {
33
+ return props.defaultValue;
34
+ }
35
+ const selectedOptionsText = getOptionsMatchingValue((optionValue)=>{
36
+ return selectedOptions.includes(optionValue);
37
+ }).map((option)=>option.text);
38
+ if (multiselect) {
39
+ // editable inputs should not display multiple selected options in the input as text
40
+ return editable ? '' : selectedOptionsText.join(', ');
41
+ }
42
+ return selectedOptionsText[0];
57
43
  // do not change value after isFirstMount changes,
58
44
  // we do not want to accidentally override defaultValue on a second render
59
45
  // unless another value is intentionally set
60
46
  // eslint-disable-next-line react-hooks/exhaustive-deps
61
- }, [controllableValue, editable, getOptionsMatchingValue, multiselect, props.defaultValue, selectedOptions]);
62
- // Handle open state, which is shared with options in context
63
- const [open, setOpenState] = useControllableState({
64
- state: props.open,
65
- defaultState: props.defaultOpen,
66
- initialState: false
67
- });
68
- const setOpen = React.useCallback((event, newState) => {
69
- onOpenChange === null || onOpenChange === void 0 ? void 0 : onOpenChange(event, {
70
- open: newState
47
+ }, [
48
+ controllableValue,
49
+ editable,
50
+ getOptionsMatchingValue,
51
+ multiselect,
52
+ props.defaultValue,
53
+ selectedOptions
54
+ ]);
55
+ // Handle open state, which is shared with options in context
56
+ const [open, setOpenState] = useControllableState({
57
+ state: props.open,
58
+ defaultState: props.defaultOpen,
59
+ initialState: false
71
60
  });
72
- setOpenState(newState);
73
- }, [onOpenChange, setOpenState]);
74
- // update active option based on change in open state or children
75
- React.useEffect(() => {
76
- if (open && !activeOption) {
77
- // if it is single-select and there is a selected option, start at the selected option
78
- if (!multiselect && selectedOptions.length > 0) {
79
- const selectedOption = getOptionsMatchingValue(v => v === selectedOptions[0]).pop();
80
- selectedOption && setActiveOption(selectedOption);
81
- } else {
82
- setActiveOption(getOptionAtIndex(0));
83
- }
84
- } else if (!open) {
85
- // reset the active option when closing
86
- setActiveOption(undefined);
87
- }
61
+ const setOpen = React.useCallback((event, newState)=>{
62
+ onOpenChange === null || onOpenChange === void 0 ? void 0 : onOpenChange(event, {
63
+ open: newState
64
+ });
65
+ setOpenState(newState);
66
+ }, [
67
+ onOpenChange,
68
+ setOpenState
69
+ ]);
70
+ // update active option based on change in open state or children
71
+ React.useEffect(()=>{
72
+ if (open && !activeOption) {
73
+ // if it is single-select and there is a selected option, start at the selected option
74
+ if (!multiselect && selectedOptions.length > 0) {
75
+ const selectedOption = getOptionsMatchingValue((v)=>v === selectedOptions[0]).pop();
76
+ selectedOption && setActiveOption(selectedOption);
77
+ } else {
78
+ setActiveOption(getOptionAtIndex(0));
79
+ }
80
+ } else if (!open) {
81
+ // reset the active option when closing
82
+ setActiveOption(undefined);
83
+ }
88
84
  // this should only be run in response to changes in the open state or children
89
85
  // eslint-disable-next-line react-hooks/exhaustive-deps
90
- }, [open, children]);
91
- return {
92
- ...optionCollection,
93
- ...selectionState,
94
- activeOption,
95
- appearance,
96
- focusVisible,
97
- hasFocus,
98
- ignoreNextBlur,
99
- inlinePopup,
100
- open,
101
- setActiveOption,
102
- setFocusVisible,
103
- setHasFocus,
104
- setOpen,
105
- setValue,
106
- size,
107
- value
108
- };
86
+ }, [
87
+ open,
88
+ children
89
+ ]);
90
+ return {
91
+ ...optionCollection,
92
+ ...selectionState,
93
+ activeOption,
94
+ appearance,
95
+ focusVisible,
96
+ hasFocus,
97
+ ignoreNextBlur,
98
+ inlinePopup,
99
+ open,
100
+ setActiveOption,
101
+ setFocusVisible,
102
+ setHasFocus,
103
+ setOpen,
104
+ setValue,
105
+ size,
106
+ value
107
+ };
109
108
  };
110
- //# sourceMappingURL=useComboboxBaseState.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["React","useControllableState","useFirstMount","useOptionCollection","useSelection","useComboboxBaseState","props","appearance","children","editable","inlinePopup","multiselect","onOpenChange","size","optionCollection","getOptionAtIndex","getOptionsMatchingValue","activeOption","setActiveOption","useState","focusVisible","setFocusVisible","hasFocus","setHasFocus","ignoreNextBlur","useRef","selectionState","selectedOptions","isFirstMount","controllableValue","setValue","state","value","initialState","undefined","useMemo","defaultValue","selectedOptionsText","optionValue","includes","map","option","text","join","open","setOpenState","defaultState","defaultOpen","setOpen","useCallback","event","newState","useEffect","length","selectedOption","v","pop"],"sources":["../../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 = (\n props: ComboboxBaseProps & { children?: React.ReactNode; editable?: boolean },\n): ComboboxBaseState => {\n const {\n appearance = 'outline',\n children,\n editable = false,\n inlinePopup = false,\n multiselect,\n onOpenChange,\n size = 'medium',\n } = props;\n\n const optionCollection = useOptionCollection();\n const { getOptionAtIndex, getOptionsMatchingValue } = 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 const selectedOptionsText = getOptionsMatchingValue(optionValue => {\n return selectedOptions.includes(optionValue);\n }).map(option => option.text);\n\n if (multiselect) {\n // editable inputs should not display multiple selected options in the input as text\n return editable ? '' : selectedOptionsText.join(', ');\n }\n\n return selectedOptionsText[0];\n\n // do not change value after isFirstMount changes,\n // we do not want to accidentally override defaultValue on a second render\n // unless another value is intentionally set\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [controllableValue, editable, getOptionsMatchingValue, 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 or children\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 = getOptionsMatchingValue(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 or children\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [open, children]);\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"],"mappings":"AAAA,YAAYA,KAAA,MAAW;AACvB,SAASC,oBAAoB,EAAEC,aAAa,QAAQ;AACpD,SAASC,mBAAmB,QAAQ;AAEpC,SAASC,YAAY,QAAQ;AAG7B;;;AAGA,OAAO,MAAMC,oBAAA,GACXC,KAAA,IACsB;EACtB,MAAM;IACJC,UAAA,GAAa;IACbC,QAAA;IACAC,QAAA,GAAW,KAAK;IAChBC,WAAA,GAAc,KAAK;IACnBC,WAAA;IACAC,YAAA;IACAC,IAAA,GAAO;EAAQ,CAChB,GAAGP,KAAA;EAEJ,MAAMQ,gBAAA,GAAmBX,mBAAA;EACzB,MAAM;IAAEY,gBAAA;IAAkBC;EAAuB,CAAE,GAAGF,gBAAA;EAEtD,MAAM,CAACG,YAAA,EAAcC,eAAA,CAAgB,GAAGlB,KAAA,CAAMmB,QAAQ;EAEtD;EACA;EACA,MAAM,CAACC,YAAA,EAAcC,eAAA,CAAgB,GAAGrB,KAAA,CAAMmB,QAAQ,CAAC,KAAK;EAE5D;EACA,MAAM,CAACG,QAAA,EAAUC,WAAA,CAAY,GAAGvB,KAAA,CAAMmB,QAAQ,CAAC,KAAK;EAEpD,MAAMK,cAAA,GAAiBxB,KAAA,CAAMyB,MAAM,CA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AA,KAAsB;IACpDvC,YAAA,aAAAA,YAAA,uBAAAA,YAAA,CAAesC,KAAA,EAAO;MAAEN,IAAA,EAAMO;IAAS;IACvCN,YAAA,CAAaM,QAAA;EACf,GACA,CAACvC,YAAA,EAAciC,YAAA,CAAa;EAG9B;EACA7C,KAAA,CAAMoD,SAAS,CAAC,MAAM;IACpB,IAAIR,IAAA,IAAQ,CAAC3B,YAAA,EAAc;MACzB;MACA,IAAI,CAACN,WAAA,IAAegB,eAAA,CAAgB0B,MAAM,GAAG,GAAG;QAC9C,MAAMC,cAAA,GAAiBtC,uBAAA,CAAwBuC,CAAA,IAAKA,CAAA,KAAM5B,eAAe,CAAC,EAAE,EAAE6B,GAAG;QACjFF,cAAA,IAAkBpC,eAAA,CAAgBoC,cAAA;MACpC,OAEK;QACHpC,eAAA,CAAgBH,gBAAA,CAAiB;MACnC;IACF,OAAO,IAAI,CAAC6B,IAAA,EAAM;MAChB;MACA1B,eAAA,CAAgBgB,SAAA;IAClB;IACA;IACA;EACF,GAAG,CAACU,IAAA,EAAMpC,QAAA,CAAS;EAEnB,OAAO;IACL,GAAGM,gBAAgB;IACnB,GAAGY,cAAc;IACjBT,YAAA;IACAV,UAAA;IACAa,YAAA;IACAE,QAAA;IACAE,cAAA;IACAd,WAAA;IACAkC,IAAA;IACA1B,eAAA;IACAG,eAAA;IACAE,WAAA;IACAyB,OAAA;IACAlB,QAAA;IACAjB,IAAA;IACAmB;EACF;AACF"}
1
+ {"version":3,"sources":["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 = (\n props: ComboboxBaseProps & { children?: React.ReactNode; editable?: boolean },\n): ComboboxBaseState => {\n const {\n appearance = 'outline',\n children,\n editable = false,\n inlinePopup = false,\n multiselect,\n onOpenChange,\n size = 'medium',\n } = props;\n\n const optionCollection = useOptionCollection();\n const { getOptionAtIndex, getOptionsMatchingValue } = 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 const selectedOptionsText = getOptionsMatchingValue(optionValue => {\n return selectedOptions.includes(optionValue);\n }).map(option => option.text);\n\n if (multiselect) {\n // editable inputs should not display multiple selected options in the input as text\n return editable ? '' : selectedOptionsText.join(', ');\n }\n\n return selectedOptionsText[0];\n\n // do not change value after isFirstMount changes,\n // we do not want to accidentally override defaultValue on a second render\n // unless another value is intentionally set\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [controllableValue, editable, getOptionsMatchingValue, 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 or children\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 = getOptionsMatchingValue(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 or children\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [open, children]);\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"],"names":["React","useControllableState","useFirstMount","useOptionCollection","useSelection","useComboboxBaseState","props","appearance","children","editable","inlinePopup","multiselect","onOpenChange","size","optionCollection","getOptionAtIndex","getOptionsMatchingValue","activeOption","setActiveOption","useState","focusVisible","setFocusVisible","hasFocus","setHasFocus","ignoreNextBlur","useRef","selectionState","selectedOptions","isFirstMount","controllableValue","setValue","state","value","initialState","undefined","useMemo","defaultValue","selectedOptionsText","optionValue","includes","map","option","text","join","open","setOpenState","defaultState","defaultOpen","setOpen","useCallback","event","newState","useEffect","length","selectedOption","v","pop"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,oBAAoB,EAAEC,aAAa,QAAQ,4BAA4B;AAChF,SAASC,mBAAmB,QAAQ,+BAA+B;AAEnE,SAASC,YAAY,QAAQ,wBAAwB;AAGrD;;CAEC,GACD,OAAO,MAAMC,uBAAuB,CAClCC,QACsB;IACtB,MAAM,EACJC,YAAa,UAAS,EACtBC,SAAQ,EACRC,UAAW,KAAK,CAAA,EAChBC,aAAc,KAAK,CAAA,EACnBC,YAAW,EACXC,aAAY,EACZC,MAAO,SAAQ,EAChB,GAAGP;IAEJ,MAAMQ,mBAAmBX;IACzB,M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,aAAa,GAAG5C,qBAAqB;QAChD8B,OAAOzB,MAAMsC,IAAI;QACjBE,cAAcxC,MAAMyC,WAAW;QAC/Bd,cAAc,KAAK;IACrB;IAEA,MAAMe,UAAUhD,MAAMiD,WAAW,CAC/B,CAACC,OAA+BC,WAAsB;QACpDvC,yBAAAA,0BAAAA,KAAAA,IAAAA,aAAesC,OAAO;YAAEN,MAAMO;QAAS;QACvCN,aAAaM;IACf,GACA;QAACvC;QAAciC;KAAa;IAG9B,iEAAiE;IACjE7C,MAAMoD,SAAS,CAAC,IAAM;QACpB,IAAIR,QAAQ,CAAC3B,cAAc;YACzB,sFAAsF;YACtF,IAAI,CAACN,eAAegB,gBAAgB0B,MAAM,GAAG,GAAG;gBAC9C,MAAMC,iBAAiBtC,wBAAwBuC,CAAAA,IAAKA,MAAM5B,eAAe,CAAC,EAAE,EAAE6B,GAAG;gBACjFF,kBAAkBpC,gBAAgBoC;YACpC,OAEK;gBACHpC,gBAAgBH,iBAAiB;YACnC,CAAC;QACH,OAAO,IAAI,CAAC6B,MAAM;YAChB,uCAAuC;YACvC1B,gBAAgBgB;QAClB,CAAC;IACD,+EAA+E;IAC/E,uDAAuD;IACzD,GAAG;QAACU;QAAMpC;KAAS;IAEnB,OAAO;QACL,GAAGM,gBAAgB;QACnB,GAAGY,cAAc;QACjBT;QACAV;QACAa;QACAE;QACAE;QACAd;QACAkC;QACA1B;QACAG;QACAE;QACAyB;QACAlB;QACAjB;QACAmB;IACF;AACF,EAAE"}
@@ -1,34 +1,37 @@
1
1
  import { resolvePositioningShorthand, usePositioning } from '@fluentui/react-positioning';
2
2
  import { useMergedRefs } from '@fluentui/react-utilities';
3
3
  export function useComboboxPopup(props, triggerShorthand, listboxShorthand) {
4
- const {
5
- positioning
6
- } = props;
7
- // Set a default set of fallback positions to try if the dropdown does not fit on screen
8
- const fallbackPositions = ['above', 'after', 'after-top', 'before', 'before-top'];
9
- // popper options
10
- const popperOptions = {
11
- position: 'below',
12
- align: 'start',
13
- offset: {
14
- crossAxis: 0,
15
- mainAxis: 2
16
- },
17
- fallbackPositions,
18
- ...resolvePositioningShorthand(positioning)
19
- };
20
- const {
21
- targetRef,
22
- containerRef
23
- } = usePositioning(popperOptions);
24
- const listboxRef = useMergedRefs(listboxShorthand === null || listboxShorthand === void 0 ? void 0 : listboxShorthand.ref, containerRef);
25
- const listbox = listboxShorthand && {
26
- ...listboxShorthand,
27
- ref: listboxRef
28
- };
29
- return [{
30
- ...triggerShorthand,
31
- ref: useMergedRefs(triggerShorthand === null || triggerShorthand === void 0 ? void 0 : triggerShorthand.ref, targetRef)
32
- }, listbox];
4
+ const { positioning } = props;
5
+ // Set a default set of fallback positions to try if the dropdown does not fit on screen
6
+ const fallbackPositions = [
7
+ 'above',
8
+ 'after',
9
+ 'after-top',
10
+ 'before',
11
+ 'before-top'
12
+ ];
13
+ // popper options
14
+ const popperOptions = {
15
+ position: 'below',
16
+ align: 'start',
17
+ offset: {
18
+ crossAxis: 0,
19
+ mainAxis: 2
20
+ },
21
+ fallbackPositions,
22
+ ...resolvePositioningShorthand(positioning)
23
+ };
24
+ const { targetRef , containerRef } = usePositioning(popperOptions);
25
+ const listboxRef = useMergedRefs(listboxShorthand === null || listboxShorthand === void 0 ? void 0 : listboxShorthand.ref, containerRef);
26
+ const listbox = listboxShorthand && {
27
+ ...listboxShorthand,
28
+ ref: listboxRef
29
+ };
30
+ return [
31
+ {
32
+ ...triggerShorthand,
33
+ ref: useMergedRefs(triggerShorthand === null || triggerShorthand === void 0 ? void 0 : triggerShorthand.ref, targetRef)
34
+ },
35
+ listbox
36
+ ];
33
37
  }
34
- //# sourceMappingURL=useComboboxPopup.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["resolvePositioningShorthand","usePositioning","useMergedRefs","useComboboxPopup","props","triggerShorthand","listboxShorthand","positioning","fallbackPositions","popperOptions","position","align","offset","crossAxis","mainAxis","targetRef","containerRef","listboxRef","ref","listbox"],"sources":["../../src/utils/useComboboxPopup.ts"],"sourcesContent":["import { PositioningShorthandValue, 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 // Set a default set of fallback positions to try if the dropdown does not fit on screen\n const fallbackPositions: PositioningShorthandValue[] = ['above', 'after', 'after-top', 'before', 'before-top'];\n\n // popper options\n const popperOptions = {\n position: 'below' as const,\n align: 'start' as const,\n offset: { crossAxis: 0, mainAxis: 2 },\n fallbackPositions,\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"],"mappings":"AAAA,SAAoCA,2BAA2B,EAAEC,cAAc,QAAQ;AACvF,SAAiCC,aAAa,QAAQ;AAetD,OAAO,SAASC,iBACdC,KAAwB,EACxBC,gBAAqF,EACrFC,gBAAyD,EAIzD;EACA,MAAM;IAAEC;EAAW,CAAE,GAAGH,KAAA;EAExB;EACA,MAAMI,iBAAA,GAAiD,CAAC,SAAS,SAAS,aAAa,UAAU,aAAa;EAE9G;EACA,MAAMC,aAAA,GAAgB;IACpBC,QAAA,EAAU;IACVC,KAAA,EAAO;IACPC,MAAA,EAAQ;MAAEC,SAAA,EAAW;MAAGC,QAAA,EAAU;IAAE;IACpCN,iBAAA;IACA,GAAGR,2BAAA,CAA4BO,WAAA;EACjC;EAEA,MAAM;IAAEQ,SAAA;IAAWC;EAAY,CAAE,GAAGf,cAAA,CAAeQ,aAAA;EAEnD,MAAMQ,UAAA,GAAaf,aAAA,CAAcI,gBAAA,aAAAA,gBAAA,uBAAAA,gBAAA,CAAkBY,GAAG,EAAEF,YAAA;EACxD,MAAMG,OAAA,GAAUb,gBAAA,IAAoB;IAAE,GAAGA,gBAAgB;IAAEY,GAAA,EAAKD;EAAW;EAE3E,OAAO,CAAC;IAAE,GAAGZ,gBAAgB;IAAEa,GAAA,EAAKhB,aAAA,CAAcG,gBAAA,aAAAA,gBAAA,uBAAAA,gBAAA,CAAkBa,GAAG,EAAEH,SAAA;EAAW,GAAGI,OAAA,CAAQ;AACjG"}
1
+ {"version":3,"sources":["useComboboxPopup.ts"],"sourcesContent":["import { PositioningShorthandValue, 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 // Set a default set of fallback positions to try if the dropdown does not fit on screen\n const fallbackPositions: PositioningShorthandValue[] = ['above', 'after', 'after-top', 'before', 'before-top'];\n\n // popper options\n const popperOptions = {\n position: 'below' as const,\n align: 'start' as const,\n offset: { crossAxis: 0, mainAxis: 2 },\n fallbackPositions,\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"],"names":["resolvePositioningShorthand","usePositioning","useMergedRefs","useComboboxPopup","props","triggerShorthand","listboxShorthand","positioning","fallbackPositions","popperOptions","position","align","offset","crossAxis","mainAxis","targetRef","containerRef","listboxRef","ref","listbox"],"mappings":"AAAA,SAAoCA,2BAA2B,EAAEC,cAAc,QAAQ,8BAA8B;AACrH,SAAiCC,aAAa,QAAQ,4BAA4B;AAelF,OAAO,SAASC,iBACdC,KAAwB,EACxBC,gBAAqF,EACrFC,gBAAyD,EAIzD;IACA,MAAM,EAAEC,YAAW,EAAE,GAAGH;IAExB,wFAAwF;IACxF,MAAMI,oBAAiD;QAAC;QAAS;QAAS;QAAa;QAAU;KAAa;IAE9G,iBAAiB;IACjB,MAAMC,gBAAgB;QACpBC,UAAU;QACVC,OAAO;QACPC,QAAQ;YAAEC,WAAW;YAAGC,UAAU;QAAE;QACpCN;QACA,GAAGR,4BAA4BO,YAAY;IAC7C;IAEA,MAAM,EAAEQ,UAAS,EAAEC,aAAY,EAAE,GAAGf,eAAeQ;IAEnD,MAAMQ,aAAaf,cAAcI,6BAAAA,8BAAAA,KAAAA,IAAAA,iBAAkBY,GAAG,EAAEF;IACxD,MAAMG,UAAUb,oBAAoB;QAAE,GAAGA,gBAAgB;QAAEY,KAAKD;IAAW;IAE3E,OAAO;QAAC;YAAE,GAAGZ,gBAAgB;YAAEa,KAAKhB,cAAcG,6BAAAA,8BAAAA,KAAAA,IAAAA,iBAAkBa,GAAG,EAAEH;QAAW;QAAGI;KAAQ;AACjG,CAAC"}
@@ -1,70 +1,71 @@
1
1
  import * as React from 'react';
2
2
  /**
3
3
  * A hook for managing a collection of child Options
4
- */
5
- export const useOptionCollection = () => {
6
- const nodes = React.useRef([]);
7
- const collectionAPI = React.useMemo(() => {
8
- const getCount = () => nodes.current.length;
9
- const getOptionAtIndex = index => {
10
- var _nodes_current_index;
11
- return (_nodes_current_index = nodes.current[index]) === null || _nodes_current_index === void 0 ? void 0 : _nodes_current_index.option;
12
- };
13
- const getIndexOfId = id => nodes.current.findIndex(node => node.option.id === id);
14
- const getOptionById = id => {
15
- const item = nodes.current.find(node => node.option.id === id);
16
- return item === null || item === void 0 ? void 0 : item.option;
17
- };
18
- const getOptionsMatchingText = matcher => {
19
- return nodes.current.filter(node => matcher(node.option.text)).map(node => node.option);
20
- };
21
- const getOptionsMatchingValue = matcher => {
22
- return nodes.current.filter(node => matcher(node.option.value)).map(node => node.option);
23
- };
4
+ */ export const useOptionCollection = ()=>{
5
+ const nodes = React.useRef([]);
6
+ const collectionAPI = React.useMemo(()=>{
7
+ const getCount = ()=>nodes.current.length;
8
+ const getOptionAtIndex = (index)=>{
9
+ var _nodes_current_index;
10
+ return (_nodes_current_index = nodes.current[index]) === null || _nodes_current_index === void 0 ? void 0 : _nodes_current_index.option;
11
+ };
12
+ const getIndexOfId = (id)=>nodes.current.findIndex((node)=>node.option.id === id);
13
+ const getOptionById = (id)=>{
14
+ const item = nodes.current.find((node)=>node.option.id === id);
15
+ return item === null || item === void 0 ? void 0 : item.option;
16
+ };
17
+ const getOptionsMatchingText = (matcher)=>{
18
+ return nodes.current.filter((node)=>matcher(node.option.text)).map((node)=>node.option);
19
+ };
20
+ const getOptionsMatchingValue = (matcher)=>{
21
+ return nodes.current.filter((node)=>matcher(node.option.value)).map((node)=>node.option);
22
+ };
23
+ return {
24
+ getCount,
25
+ getOptionAtIndex,
26
+ getIndexOfId,
27
+ getOptionById,
28
+ getOptionsMatchingText,
29
+ getOptionsMatchingValue
30
+ };
31
+ }, []);
32
+ const registerOption = React.useCallback((option, element)=>{
33
+ var _nodes_current_index;
34
+ const index = nodes.current.findIndex((node)=>{
35
+ if (!node.element || !element) {
36
+ return false;
37
+ }
38
+ if (node.option.id === option.id) {
39
+ return true;
40
+ }
41
+ // use the DOM method compareDocumentPosition to order the current node against registered nodes
42
+ // eslint-disable-next-line no-bitwise
43
+ return node.element.compareDocumentPosition(element) & Node.DOCUMENT_POSITION_PRECEDING;
44
+ });
45
+ // do not register the option if it already exists
46
+ if (((_nodes_current_index = nodes.current[index]) === null || _nodes_current_index === void 0 ? void 0 : _nodes_current_index.option.id) !== option.id) {
47
+ const newItem = {
48
+ element,
49
+ option
50
+ };
51
+ // If an index is not found we will push the element to the end.
52
+ if (index === -1) {
53
+ nodes.current = [
54
+ ...nodes.current,
55
+ newItem
56
+ ];
57
+ } else {
58
+ nodes.current.splice(index, 0, newItem);
59
+ }
60
+ }
61
+ // return the unregister function
62
+ return ()=>{
63
+ nodes.current = nodes.current.filter((node)=>node.option.id !== option.id);
64
+ };
65
+ }, []);
24
66
  return {
25
- getCount,
26
- getOptionAtIndex,
27
- getIndexOfId,
28
- getOptionById,
29
- getOptionsMatchingText,
30
- getOptionsMatchingValue
31
- };
32
- }, []);
33
- const registerOption = React.useCallback((option, element) => {
34
- var _nodes_current_index;
35
- const index = nodes.current.findIndex(node => {
36
- if (!node.element || !element) {
37
- return false;
38
- }
39
- if (node.option.id === option.id) {
40
- return true;
41
- }
42
- // use the DOM method compareDocumentPosition to order the current node against registered nodes
43
- // eslint-disable-next-line no-bitwise
44
- return node.element.compareDocumentPosition(element) & Node.DOCUMENT_POSITION_PRECEDING;
45
- });
46
- // do not register the option if it already exists
47
- if (((_nodes_current_index = nodes.current[index]) === null || _nodes_current_index === void 0 ? void 0 : _nodes_current_index.option.id) !== option.id) {
48
- const newItem = {
49
- element,
50
- option
51
- };
52
- // If an index is not found we will push the element to the end.
53
- if (index === -1) {
54
- nodes.current = [...nodes.current, newItem];
55
- } else {
56
- nodes.current.splice(index, 0, newItem);
57
- }
58
- }
59
- // return the unregister function
60
- return () => {
61
- nodes.current = nodes.current.filter(node => node.option.id !== option.id);
67
+ ...collectionAPI,
68
+ options: nodes.current.map((node)=>node.option),
69
+ registerOption
62
70
  };
63
- }, []);
64
- return {
65
- ...collectionAPI,
66
- options: nodes.current.map(node => node.option),
67
- registerOption
68
- };
69
71
  };
70
- //# sourceMappingURL=useOptionCollection.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["React","useOptionCollection","nodes","useRef","collectionAPI","useMemo","getCount","current","length","getOptionAtIndex","index","_nodes_current_index","option","getIndexOfId","id","findIndex","node","getOptionById","item","find","getOptionsMatchingText","matcher","filter","text","map","getOptionsMatchingValue","value","registerOption","useCallback","element","compareDocumentPosition","Node","DOCUMENT_POSITION_PRECEDING","newItem","splice","options"],"sources":["../../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: (text: string) => boolean) => {\n return nodes.current.filter(node => matcher(node.option.text)).map(node => node.option);\n };\n const getOptionsMatchingValue = (matcher: (value: string) => boolean) => {\n return nodes.current.filter(node => matcher(node.option.value)).map(node => node.option);\n };\n\n return {\n getCount,\n getOptionAtIndex,\n getIndexOfId,\n getOptionById,\n getOptionsMatchingText,\n getOptionsMatchingValue,\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"],"mappings":"AAAA,YAAYA,KAAA,MAAW;AAGvB;;;AAGA,OAAO,MAAMC,mBAAA,GAAsBA,CAAA,KAA6B;EAC9D,MAAMC,KAAA,GAAQF,KAAA,CAAMG,MAAM,CAAkD,EAAE;EAE9E,MAAMC,aAAA,GAAgBJ,KAAA,CAAMK,OAAO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ionCollectionState, 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: (text: string) => boolean) => {\n return nodes.current.filter(node => matcher(node.option.text)).map(node => node.option);\n };\n const getOptionsMatchingValue = (matcher: (value: string) => boolean) => {\n return nodes.current.filter(node => matcher(node.option.value)).map(node => node.option);\n };\n\n return {\n getCount,\n getOptionAtIndex,\n getIndexOfId,\n getOptionById,\n getOptionsMatchingText,\n getOptionsMatchingValue,\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"],"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","getOptionsMatchingValue","value","registerOption","useCallback","element","compareDocumentPosition","Node","DOCUMENT_POSITION_PRECEDING","newItem","splice","options"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAG/B;;CAEC,GACD,OAAO,MAAMC,sBAAsB,IAA6B;IAC9D,MAAMC,QAAQF,MAAMG,MAAM,CAAkD,EAAE;IAE9E,MAAMC,gBAAgBJ,MAAMK,OAAO,CAAC,IAAM;QACxC,MAAMC,WAAW,IAAMJ,MAAMK,OAAO,CAACC,MAAM;QAC3C,MAAMC,mBAAmB,CAACC;gBAAkBR;YAAAA,OAAAA,CAAAA,uBAAAA,MAAMK,OAAO,CAACG,MAAM,cAApBR,kCAAAA,KAAAA,IAAAA,qBAAsBS,MAAM;;QACxE,MAAMC,eAAe,CAACC,KAAeX,MAAMK,OAAO,CAACO,SAAS,CAACC,CAAAA,OAAQA,KAAKJ,MAAM,CAACE,EAAE,KAAKA;QACxF,MAAMG,gBAAgB,CAACH,KAAe;YACpC,MAAMI,OAAOf,MAAMK,OAAO,CAACW,IAAI,CAACH,CAAAA,OAAQA,KAAKJ,MAAM,CAACE,EAAE,KAAKA;YAC3D,OAAOI,iBAAAA,kBAAAA,KAAAA,IAAAA,KAAMN,MAAM;QACrB;QACA,MAAMQ,yBAAyB,CAACC,UAAuC;YACrE,OAAOlB,MAAMK,OAAO,CAACc,MAAM,CAACN,CAAAA,OAAQK,QAAQL,KAAKJ,MAAM,CAACW,IAAI,GAAGC,GAAG,CAACR,CAAAA,OAAQA,KAAKJ,MAAM;QACxF;QACA,MAAMa,0BAA0B,CAACJ,UAAwC;YACvE,OAAOlB,MAAMK,OAAO,CAACc,MAAM,CAACN,CAAAA,OAAQK,QAAQL,KAAKJ,MAAM,CAACc,KAAK,GAAGF,GAAG,CAACR,CAAAA,OAAQA,KAAKJ,MAAM;QACzF;QAEA,OAAO;YACLL;YACAG;YACAG;YACAI;YACAG;YACAK;QACF;IACF,GAAG,EAAE;IAEL,MAAME,iBAAiB1B,MAAM2B,WAAW,CAAC,CAAChB,QAAqBiB,UAAyB;YAgBlF1B;QAfJ,MAAMQ,QAAQR,MAAMK,OAAO,CAACO,SAAS,CAACC,CAAAA,OAAQ;YAC5C,IAAI,CAACA,KAAKa,OAAO,IAAI,CAACA,SAAS;gBAC7B,OAAO,KAAK;YACd,CAAC;YAED,IAAIb,KAAKJ,MAAM,CAACE,EAAE,KAAKF,OAAOE,EAAE,EAAE;gBAChC,OAAO,IAAI;YACb,CAAC;YAED,gGAAgG;YAChG,sCAAsC;YACtC,OAAOE,KAAKa,OAAO,CAACC,uBAAuB,CAACD,WAAWE,KAAKC,2BAA2B;QACzF;QAEA,kDAAkD;QAClD,IAAI7B,CAAAA,CAAAA,uBAAAA,MAAMK,OAAO,CAACG,MAAM,cAApBR,kCAAAA,KAAAA,IAAAA,qBAAsBS,OAAOE,EAAE,MAAKF,OAAOE,EAAE,EAAE;YACjD,MAAMmB,UAAU;gBACdJ;gBACAjB;YACF;YAEA,gEAAgE;YAChE,IAAID,UAAU,CAAC,GAAG;gBAChBR,MAAMK,OAAO,GAAG;uBAAIL,MAAMK,OAAO;oBAAEyB;iBAAQ;YAC7C,OAAO;gBACL9B,MAAMK,OAAO,CAAC0B,MAAM,CAACvB,OAAO,GAAGsB;YACjC,CAAC;QACH,CAAC;QAED,iCAAiC;QACjC,OAAO,IAAM;YACX9B,MAAMK,OAAO,GAAGL,MAAMK,OAAO,CAACc,MAAM,CAACN,CAAAA,OAAQA,KAAKJ,MAAM,CAACE,EAAE,KAAKF,OAAOE,EAAE;QAC3E;IACF,GAAG,EAAE;IAEL,OAAO;QACL,GAAGT,aAAa;QAChB8B,SAAShC,MAAMK,OAAO,CAACgB,GAAG,CAACR,CAAAA,OAAQA,KAAKJ,MAAM;QAC9Ce;IACF;AACF,EAAE"}
@@ -1,36 +1,29 @@
1
1
  import * as React from 'react';
2
2
  import { canUseDOM } from '@fluentui/react-utilities';
3
3
  export function useScrollOptionsIntoView(state) {
4
- const {
5
- activeOption
6
- } = state;
7
- const scrollContainerRef = React.useRef(null);
8
- React.useEffect(() => {
9
- if (scrollContainerRef.current && activeOption && canUseDOM()) {
10
- const activeOptionElement = scrollContainerRef.current.querySelector(`#${activeOption.id}`);
11
- if (!activeOptionElement) {
12
- return;
13
- }
14
- const {
15
- offsetHeight,
16
- offsetTop
17
- } = activeOptionElement;
18
- const {
19
- offsetHeight: parentOffsetHeight,
20
- scrollTop
21
- } = scrollContainerRef.current;
22
- const isAbove = offsetTop < scrollTop;
23
- const isBelow = offsetTop + offsetHeight > scrollTop + parentOffsetHeight;
24
- // add a small buffer for general visual nicety
25
- // it looks slightly better if the option has some space from the top/bottom while arrowing
26
- const buffer = 2;
27
- if (isAbove) {
28
- scrollContainerRef.current.scrollTo(0, offsetTop - buffer);
29
- } else if (isBelow) {
30
- scrollContainerRef.current.scrollTo(0, offsetTop - parentOffsetHeight + offsetHeight + buffer);
31
- }
32
- }
33
- }, [activeOption]);
34
- return scrollContainerRef;
4
+ const { activeOption } = state;
5
+ const scrollContainerRef = React.useRef(null);
6
+ React.useEffect(()=>{
7
+ if (scrollContainerRef.current && activeOption && canUseDOM()) {
8
+ const activeOptionElement = scrollContainerRef.current.querySelector(`#${activeOption.id}`);
9
+ if (!activeOptionElement) {
10
+ return;
11
+ }
12
+ const { offsetHeight , offsetTop } = activeOptionElement;
13
+ const { offsetHeight: parentOffsetHeight , scrollTop } = scrollContainerRef.current;
14
+ const isAbove = offsetTop < scrollTop;
15
+ const isBelow = offsetTop + offsetHeight > scrollTop + parentOffsetHeight;
16
+ // add a small buffer for general visual nicety
17
+ // it looks slightly better if the option has some space from the top/bottom while arrowing
18
+ const buffer = 2;
19
+ if (isAbove) {
20
+ scrollContainerRef.current.scrollTo(0, offsetTop - buffer);
21
+ } else if (isBelow) {
22
+ scrollContainerRef.current.scrollTo(0, offsetTop - parentOffsetHeight + offsetHeight + buffer);
23
+ }
24
+ }
25
+ }, [
26
+ activeOption
27
+ ]);
28
+ return scrollContainerRef;
35
29
  }
36
- //# sourceMappingURL=useScrollOptionsIntoView.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["React","canUseDOM","useScrollOptionsIntoView","state","activeOption","scrollContainerRef","useRef","useEffect","current","activeOptionElement","querySelector","id","offsetHeight","offsetTop","parentOffsetHeight","scrollTop","isAbove","isBelow","buffer","scrollTo"],"sources":["../../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"],"mappings":"AAAA,YAAYA,KAAA,MAAW;AACvB,SAASC,SAAS,QAAQ;AAG1B,OAAO,SAASC,yBAAyBC,KAAmB,EAA6B;EACvF,MAAM;IAAEC;EAAY,CAAE,GAAGD,KAAA;EACzB,MAAME,kBAAA,GAAqBL,KAAA,CAAMM,MAAM,CAAiB,IAAI;EAE5DN,KAAA,CAAMO,SAAS,CAAC,MAAM;IACpB,IAAIF,kBAAA,CAAmBG,OAAO,IAAIJ,YAAA,IAAgBH,SAAA,IAAa;MAC7D,MAAMQ,mBAAA,GAAsBJ,kBAAA,CAAmBG,OAAO,CAACE,aAAa,CAAE,IAAGN,YAAA,CAAaO,EAAG,EAAC;MAE1F,IAAI,CAACF,mBAAA,EAAqB;QACxB;MACF;MAEA,MAAM;QAAEG,YAAA;QAAcC;MAAS,CAAE,GAAGJ,mBAAA;MACpC,MAAM;QAAEG,YAAA,EAAcE,kBAAA;QAAoBC;MAAS,CAAE,GAAGV,kBAAA,CAAmBG,OAAO;MAElF,MAAMQ,OAAA,GAAUH,SAAA,GAAYE,SAAA;MAC5B,MAAME,OAAA,GAAUJ,SAAA,GAAYD,YAAA,GAAeG,SAAA,GAAYD,kBAAA;MAEvD;MACA;MACA,MAAMI,MAAA,GAAS;MAEf,IAAIF,OAAA,EAAS;QACXX,kBAAA,CAAmBG,OAAO,CAACW,QAAQ,CAAC,GAAGN,SAAA,GAAYK,MAAA;MACrD,OAAO,IAAID,OAAA,EAAS;QAClBZ,kBAAA,CAAmBG,OAAO,CAACW,QAAQ,CAAC,GAAGN,SAAA,GAAYC,kBAAA,GAAqBF,YAAA,GAAeM,MAAA;MACzF;IACF;EACF,GAAG,CAACd,YAAA,CAAa;EAEjB,OAAOC,kBAAA;AACT"}
1
+ {"version":3,"sources":["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"],"names":["React","canUseDOM","useScrollOptionsIntoView","state","activeOption","scrollContainerRef","useRef","useEffect","current","activeOptionElement","querySelector","id","offsetHeight","offsetTop","parentOffsetHeight","scrollTop","isAbove","isBelow","buffer","scrollTo"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,SAAS,QAAQ,4BAA4B;AAGtD,OAAO,SAASC,yBAAyBC,KAAmB,EAA6B;IACvF,MAAM,EAAEC,aAAY,EAAE,GAAGD;IACzB,MAAME,qBAAqBL,MAAMM,MAAM,CAAiB,IAAI;IAE5DN,MAAMO,SAAS,CAAC,IAAM;QACpB,IAAIF,mBAAmBG,OAAO,IAAIJ,gBAAgBH,aAAa;YAC7D,MAAMQ,sBAAsBJ,mBAAmBG,OAAO,CAACE,aAAa,CAAC,CAAC,CAAC,EAAEN,aAAaO,EAAE,CAAC,CAAC;YAE1F,IAAI,CAACF,qBAAqB;gBACxB;YACF,CAAC;YAED,MAAM,EAAEG,aAAY,EAAEC,UAAS,EAAE,GAAGJ;YACpC,MAAM,EAAEG,cAAcE,mBAAkB,EAAEC,UAAS,EAAE,GAAGV,mBAAmBG,OAAO;YAElF,MAAMQ,UAAUH,YAAYE;YAC5B,MAAME,UAAUJ,YAAYD,eAAeG,YAAYD;YAEvD,+CAA+C;YAC/C,2FAA2F;YAC3F,MAAMI,SAAS;YAEf,IAAIF,SAAS;gBACXX,mBAAmBG,OAAO,CAACW,QAAQ,CAAC,GAAGN,YAAYK;YACrD,OAAO,IAAID,SAAS;gBAClBZ,mBAAmBG,OAAO,CAACW,QAAQ,CAAC,GAAGN,YAAYC,qBAAqBF,eAAeM;YACzF,CAAC;QACH,CAAC;IACH,GAAG;QAACd;KAAa;IAEjB,OAAOC;AACT,CAAC"}