@fluentui/react-combobox 9.3.3 → 9.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.json +111 -1
- package/CHANGELOG.md +36 -2
- package/dist/index.d.ts +2 -2
- package/lib/Combobox.js +0 -1
- package/lib/Combobox.js.map +1 -1
- package/lib/Dropdown.js +0 -1
- package/lib/Dropdown.js.map +1 -1
- package/lib/Listbox.js +0 -1
- package/lib/Listbox.js.map +1 -1
- package/lib/Option.js +0 -1
- package/lib/Option.js.map +1 -1
- package/lib/OptionGroup.js +0 -1
- package/lib/OptionGroup.js.map +1 -1
- package/lib/Selection.js +1 -0
- package/lib/Selection.js.map +1 -0
- package/lib/components/Combobox/Combobox.js +6 -8
- package/lib/components/Combobox/Combobox.js.map +1 -1
- package/lib/components/Combobox/Combobox.types.js +0 -1
- package/lib/components/Combobox/Combobox.types.js.map +1 -1
- package/lib/components/Combobox/index.js +0 -1
- package/lib/components/Combobox/index.js.map +1 -1
- package/lib/components/Combobox/renderCombobox.js +6 -11
- package/lib/components/Combobox/renderCombobox.js.map +1 -1
- package/lib/components/Combobox/useCombobox.js +228 -251
- package/lib/components/Combobox/useCombobox.js.map +1 -1
- package/lib/components/Combobox/useComboboxStyles.styles.js.map +1 -1
- package/lib/components/Dropdown/Dropdown.js +6 -8
- package/lib/components/Dropdown/Dropdown.js.map +1 -1
- package/lib/components/Dropdown/Dropdown.types.js +1 -2
- package/lib/components/Dropdown/Dropdown.types.js.map +1 -1
- package/lib/components/Dropdown/index.js +0 -1
- package/lib/components/Dropdown/index.js.map +1 -1
- package/lib/components/Dropdown/renderDropdown.js +6 -11
- package/lib/components/Dropdown/renderDropdown.js.map +1 -1
- package/lib/components/Dropdown/useDropdown.js +127 -136
- package/lib/components/Dropdown/useDropdown.js.map +1 -1
- package/lib/components/Dropdown/useDropdownStyles.styles.js.map +1 -1
- package/lib/components/Listbox/Listbox.js +6 -8
- package/lib/components/Listbox/Listbox.js.map +1 -1
- package/lib/components/Listbox/Listbox.types.js +1 -2
- package/lib/components/Listbox/Listbox.types.js.map +1 -1
- package/lib/components/Listbox/index.js +0 -1
- package/lib/components/Listbox/index.js.map +1 -1
- package/lib/components/Listbox/renderListbox.js +6 -11
- package/lib/components/Listbox/renderListbox.js.map +1 -1
- package/lib/components/Listbox/useListbox.js +77 -89
- package/lib/components/Listbox/useListbox.js.map +1 -1
- package/lib/components/Listbox/useListboxStyles.styles.js.map +1 -1
- package/lib/components/Option/Option.js +5 -7
- package/lib/components/Option/Option.js.map +1 -1
- package/lib/components/Option/Option.types.js +0 -1
- package/lib/components/Option/Option.types.js.map +1 -1
- package/lib/components/Option/index.js +0 -1
- package/lib/components/Option/index.js.map +1 -1
- package/lib/components/Option/renderOption.js +4 -9
- package/lib/components/Option/renderOption.js.map +1 -1
- package/lib/components/Option/useOption.js +115 -113
- package/lib/components/Option/useOption.js.map +1 -1
- package/lib/components/Option/useOptionStyles.styles.js.map +1 -1
- package/lib/components/OptionGroup/OptionGroup.js +5 -7
- package/lib/components/OptionGroup/OptionGroup.js.map +1 -1
- package/lib/components/OptionGroup/OptionGroup.types.js +1 -2
- package/lib/components/OptionGroup/OptionGroup.types.js.map +1 -1
- package/lib/components/OptionGroup/index.js +0 -1
- package/lib/components/OptionGroup/index.js.map +1 -1
- package/lib/components/OptionGroup/renderOptionGroup.js +4 -9
- package/lib/components/OptionGroup/renderOptionGroup.js.map +1 -1
- package/lib/components/OptionGroup/useOptionGroup.js +21 -25
- package/lib/components/OptionGroup/useOptionGroup.js.map +1 -1
- package/lib/components/OptionGroup/useOptionGroupStyles.styles.js.map +1 -1
- package/lib/contexts/ComboboxContext.js +16 -17
- package/lib/contexts/ComboboxContext.js.map +1 -1
- package/lib/contexts/ListboxContext.js +12 -13
- package/lib/contexts/ListboxContext.js.map +1 -1
- package/lib/contexts/useComboboxContextValues.js +16 -28
- package/lib/contexts/useComboboxContextValues.js.map +1 -1
- package/lib/contexts/useListboxContextValues.js +17 -26
- package/lib/contexts/useListboxContextValues.js.map +1 -1
- package/lib/index.js +0 -1
- package/lib/index.js.map +1 -1
- package/lib/utils/ComboboxBase.types.js +0 -1
- package/lib/utils/ComboboxBase.types.js.map +1 -1
- package/lib/utils/OptionCollection.types.js +1 -2
- package/lib/utils/OptionCollection.types.js.map +1 -1
- package/lib/utils/Selection.types.js +0 -1
- package/lib/utils/Selection.types.js.map +1 -1
- package/lib/utils/dropdownKeyActions.js +66 -77
- package/lib/utils/dropdownKeyActions.js.map +1 -1
- package/lib/utils/internalTokens.js +3 -4
- package/lib/utils/internalTokens.js.map +1 -1
- package/lib/utils/useComboboxBaseState.js +94 -96
- package/lib/utils/useComboboxBaseState.js.map +1 -1
- package/lib/utils/useComboboxPopup.js +33 -30
- package/lib/utils/useComboboxPopup.js.map +1 -1
- package/lib/utils/useOptionCollection.js +65 -64
- package/lib/utils/useOptionCollection.js.map +1 -1
- package/lib/utils/useScrollOptionsIntoView.js +25 -32
- package/lib/utils/useScrollOptionsIntoView.js.map +1 -1
- package/lib/utils/useSelection.js +57 -49
- package/lib/utils/useSelection.js.map +1 -1
- package/lib/utils/useTriggerListboxSlots.js +105 -119
- package/lib/utils/useTriggerListboxSlots.js.map +1 -1
- package/lib-commonjs/Combobox.js +0 -3
- package/lib-commonjs/Combobox.js.map +1 -1
- package/lib-commonjs/Dropdown.js +0 -3
- package/lib-commonjs/Dropdown.js.map +1 -1
- package/lib-commonjs/Listbox.js +0 -3
- package/lib-commonjs/Listbox.js.map +1 -1
- package/lib-commonjs/Option.js +0 -3
- package/lib-commonjs/Option.js.map +1 -1
- package/lib-commonjs/OptionGroup.js +0 -3
- package/lib-commonjs/OptionGroup.js.map +1 -1
- package/lib-commonjs/Selection.js +6 -0
- package/lib-commonjs/Selection.js.map +1 -0
- package/lib-commonjs/components/Combobox/Combobox.js +1 -3
- package/lib-commonjs/components/Combobox/Combobox.js.map +1 -1
- package/lib-commonjs/components/Combobox/Combobox.types.js +0 -3
- package/lib-commonjs/components/Combobox/Combobox.types.js.map +1 -1
- package/lib-commonjs/components/Combobox/index.js +0 -3
- package/lib-commonjs/components/Combobox/index.js.map +1 -1
- package/lib-commonjs/components/Combobox/renderCombobox.js +1 -3
- package/lib-commonjs/components/Combobox/renderCombobox.js.map +1 -1
- package/lib-commonjs/components/Combobox/useCombobox.js +1 -3
- package/lib-commonjs/components/Combobox/useCombobox.js.map +1 -1
- package/lib-commonjs/components/Combobox/useComboboxStyles.styles.js +0 -2
- package/lib-commonjs/components/Combobox/useComboboxStyles.styles.js.map +1 -1
- package/lib-commonjs/components/Dropdown/Dropdown.js +1 -3
- package/lib-commonjs/components/Dropdown/Dropdown.js.map +1 -1
- package/lib-commonjs/components/Dropdown/Dropdown.types.js +0 -3
- package/lib-commonjs/components/Dropdown/Dropdown.types.js.map +1 -1
- package/lib-commonjs/components/Dropdown/index.js +0 -3
- package/lib-commonjs/components/Dropdown/index.js.map +1 -1
- package/lib-commonjs/components/Dropdown/renderDropdown.js +1 -3
- package/lib-commonjs/components/Dropdown/renderDropdown.js.map +1 -1
- package/lib-commonjs/components/Dropdown/useDropdown.js +1 -3
- package/lib-commonjs/components/Dropdown/useDropdown.js.map +1 -1
- package/lib-commonjs/components/Dropdown/useDropdownStyles.styles.js +0 -2
- package/lib-commonjs/components/Dropdown/useDropdownStyles.styles.js.map +1 -1
- package/lib-commonjs/components/Listbox/Listbox.js +1 -3
- package/lib-commonjs/components/Listbox/Listbox.js.map +1 -1
- package/lib-commonjs/components/Listbox/Listbox.types.js +0 -3
- package/lib-commonjs/components/Listbox/Listbox.types.js.map +1 -1
- package/lib-commonjs/components/Listbox/index.js +0 -3
- package/lib-commonjs/components/Listbox/index.js.map +1 -1
- package/lib-commonjs/components/Listbox/renderListbox.js +1 -3
- package/lib-commonjs/components/Listbox/renderListbox.js.map +1 -1
- package/lib-commonjs/components/Listbox/useListbox.js +1 -3
- package/lib-commonjs/components/Listbox/useListbox.js.map +1 -1
- package/lib-commonjs/components/Listbox/useListboxStyles.styles.js +0 -2
- package/lib-commonjs/components/Listbox/useListboxStyles.styles.js.map +1 -1
- package/lib-commonjs/components/Option/Option.js +1 -3
- package/lib-commonjs/components/Option/Option.js.map +1 -1
- package/lib-commonjs/components/Option/Option.types.js +0 -3
- package/lib-commonjs/components/Option/Option.types.js.map +1 -1
- package/lib-commonjs/components/Option/index.js +0 -3
- package/lib-commonjs/components/Option/index.js.map +1 -1
- package/lib-commonjs/components/Option/renderOption.js +1 -3
- package/lib-commonjs/components/Option/renderOption.js.map +1 -1
- package/lib-commonjs/components/Option/useOption.js +1 -3
- package/lib-commonjs/components/Option/useOption.js.map +1 -1
- package/lib-commonjs/components/Option/useOptionStyles.styles.js +0 -2
- package/lib-commonjs/components/Option/useOptionStyles.styles.js.map +1 -1
- package/lib-commonjs/components/OptionGroup/OptionGroup.js +1 -3
- package/lib-commonjs/components/OptionGroup/OptionGroup.js.map +1 -1
- package/lib-commonjs/components/OptionGroup/OptionGroup.types.js +0 -3
- package/lib-commonjs/components/OptionGroup/OptionGroup.types.js.map +1 -1
- package/lib-commonjs/components/OptionGroup/index.js +0 -3
- package/lib-commonjs/components/OptionGroup/index.js.map +1 -1
- package/lib-commonjs/components/OptionGroup/renderOptionGroup.js +1 -3
- package/lib-commonjs/components/OptionGroup/renderOptionGroup.js.map +1 -1
- package/lib-commonjs/components/OptionGroup/useOptionGroup.js +1 -3
- package/lib-commonjs/components/OptionGroup/useOptionGroup.js.map +1 -1
- package/lib-commonjs/components/OptionGroup/useOptionGroupStyles.styles.js +0 -2
- package/lib-commonjs/components/OptionGroup/useOptionGroupStyles.styles.js.map +1 -1
- package/lib-commonjs/contexts/ComboboxContext.js +2 -4
- package/lib-commonjs/contexts/ComboboxContext.js.map +1 -1
- package/lib-commonjs/contexts/ListboxContext.js +2 -4
- package/lib-commonjs/contexts/ListboxContext.js.map +1 -1
- package/lib-commonjs/contexts/useComboboxContextValues.js +1 -3
- package/lib-commonjs/contexts/useComboboxContextValues.js.map +1 -1
- package/lib-commonjs/contexts/useListboxContextValues.js +1 -3
- package/lib-commonjs/contexts/useListboxContextValues.js.map +1 -1
- package/lib-commonjs/index.js +0 -3
- package/lib-commonjs/index.js.map +1 -1
- package/lib-commonjs/utils/ComboboxBase.types.js +0 -3
- package/lib-commonjs/utils/ComboboxBase.types.js.map +1 -1
- package/lib-commonjs/utils/OptionCollection.types.js +0 -3
- package/lib-commonjs/utils/OptionCollection.types.js.map +1 -1
- package/lib-commonjs/utils/Selection.types.js +0 -3
- package/lib-commonjs/utils/Selection.types.js.map +1 -1
- package/lib-commonjs/utils/dropdownKeyActions.js +1 -3
- package/lib-commonjs/utils/dropdownKeyActions.js.map +1 -1
- package/lib-commonjs/utils/internalTokens.js +1 -3
- package/lib-commonjs/utils/internalTokens.js.map +1 -1
- package/lib-commonjs/utils/useComboboxBaseState.js +1 -3
- package/lib-commonjs/utils/useComboboxBaseState.js.map +1 -1
- package/lib-commonjs/utils/useComboboxPopup.js +1 -3
- package/lib-commonjs/utils/useComboboxPopup.js.map +1 -1
- package/lib-commonjs/utils/useOptionCollection.js +1 -3
- package/lib-commonjs/utils/useOptionCollection.js.map +1 -1
- package/lib-commonjs/utils/useScrollOptionsIntoView.js +1 -3
- package/lib-commonjs/utils/useScrollOptionsIntoView.js.map +1 -1
- package/lib-commonjs/utils/useSelection.js +1 -3
- package/lib-commonjs/utils/useSelection.js.map +1 -1
- package/lib-commonjs/utils/useTriggerListboxSlots.js +5 -7
- package/lib-commonjs/utils/useTriggerListboxSlots.js.map +1 -1
- package/package.json +9 -9
|
@@ -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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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,"
|
|
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":"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"}
|
|
@@ -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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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,"
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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,"
|
|
1
|
+
{"version":3,"sources":["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"],"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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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,"
|
|
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"}
|