@fluentui/react-combobox 9.7.5 → 9.9.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.md +44 -5
- package/dist/index.d.ts +79 -14
- package/lib/components/Combobox/Combobox.types.js.map +1 -1
- package/lib/components/Combobox/renderCombobox.js +19 -11
- package/lib/components/Combobox/renderCombobox.js.map +1 -1
- package/lib/components/Combobox/useCombobox.js +12 -4
- package/lib/components/Combobox/useCombobox.js.map +1 -1
- package/lib/components/Combobox/useInputTriggerSlot.js +14 -12
- package/lib/components/Combobox/useInputTriggerSlot.js.map +1 -1
- package/lib/components/Dropdown/Dropdown.types.js.map +1 -1
- package/lib/components/Dropdown/renderDropdown.js +21 -13
- package/lib/components/Dropdown/renderDropdown.js.map +1 -1
- package/lib/components/Dropdown/useButtonTriggerSlot.js +51 -31
- package/lib/components/Dropdown/useButtonTriggerSlot.js.map +1 -1
- package/lib/components/Dropdown/useDropdown.js +14 -4
- package/lib/components/Dropdown/useDropdown.js.map +1 -1
- package/lib/components/Listbox/Listbox.types.js.map +1 -1
- package/lib/components/Listbox/renderListbox.js +7 -3
- package/lib/components/Listbox/renderListbox.js.map +1 -1
- package/lib/components/Listbox/useListbox.js +52 -44
- package/lib/components/Listbox/useListbox.js.map +1 -1
- package/lib/components/Option/Option.types.js.map +1 -1
- package/lib/components/Option/useOption.js +14 -24
- package/lib/components/Option/useOption.js.map +1 -1
- package/lib/components/Option/useOptionStyles.styles.js +27 -28
- package/lib/components/Option/useOptionStyles.styles.js.map +1 -1
- package/lib/contexts/ComboboxContext.js +9 -1
- package/lib/contexts/ComboboxContext.js.map +1 -1
- package/lib/contexts/ListboxContext.js +9 -4
- package/lib/contexts/ListboxContext.js.map +1 -1
- package/lib/contexts/useComboboxContextValues.js +22 -5
- package/lib/contexts/useComboboxContextValues.js.map +1 -1
- package/lib/contexts/useListboxContextValues.js +19 -10
- package/lib/contexts/useListboxContextValues.js.map +1 -1
- package/lib/index.js +2 -1
- package/lib/index.js.map +1 -1
- package/lib/utils/ComboboxBase.types.js.map +1 -1
- package/lib/utils/OptionCollection.types.js.map +1 -1
- package/lib/utils/Selection.types.js.map +1 -1
- package/lib/utils/dropdownKeyActions.js +0 -21
- package/lib/utils/dropdownKeyActions.js.map +1 -1
- package/lib/utils/useComboboxBaseState.js +60 -17
- package/lib/utils/useComboboxBaseState.js.map +1 -1
- package/lib/utils/useListboxSlot.js.map +1 -1
- package/lib/utils/useOptionCollection.js +18 -45
- package/lib/utils/useOptionCollection.js.map +1 -1
- package/lib/utils/useTriggerSlot.js +86 -33
- package/lib/utils/useTriggerSlot.js.map +1 -1
- package/lib-commonjs/components/Combobox/renderCombobox.js +19 -11
- package/lib-commonjs/components/Combobox/renderCombobox.js.map +1 -1
- package/lib-commonjs/components/Combobox/useCombobox.js +12 -4
- package/lib-commonjs/components/Combobox/useCombobox.js.map +1 -1
- package/lib-commonjs/components/Combobox/useInputTriggerSlot.js +14 -12
- package/lib-commonjs/components/Combobox/useInputTriggerSlot.js.map +1 -1
- package/lib-commonjs/components/Dropdown/renderDropdown.js +21 -13
- package/lib-commonjs/components/Dropdown/renderDropdown.js.map +1 -1
- package/lib-commonjs/components/Dropdown/useButtonTriggerSlot.js +51 -31
- package/lib-commonjs/components/Dropdown/useButtonTriggerSlot.js.map +1 -1
- package/lib-commonjs/components/Dropdown/useDropdown.js +14 -4
- package/lib-commonjs/components/Dropdown/useDropdown.js.map +1 -1
- package/lib-commonjs/components/Listbox/renderListbox.js +7 -3
- package/lib-commonjs/components/Listbox/renderListbox.js.map +1 -1
- package/lib-commonjs/components/Listbox/useListbox.js +49 -41
- package/lib-commonjs/components/Listbox/useListbox.js.map +1 -1
- package/lib-commonjs/components/Option/useOption.js +13 -23
- package/lib-commonjs/components/Option/useOption.js.map +1 -1
- package/lib-commonjs/components/Option/useOptionStyles.styles.js +85 -85
- package/lib-commonjs/components/Option/useOptionStyles.styles.js.map +1 -1
- package/lib-commonjs/contexts/ComboboxContext.js.map +1 -1
- package/lib-commonjs/contexts/ListboxContext.js +12 -2
- package/lib-commonjs/contexts/ListboxContext.js.map +1 -1
- package/lib-commonjs/contexts/useComboboxContextValues.js +23 -5
- package/lib-commonjs/contexts/useComboboxContextValues.js.map +1 -1
- package/lib-commonjs/contexts/useListboxContextValues.js +19 -9
- package/lib-commonjs/contexts/useListboxContextValues.js.map +1 -1
- package/lib-commonjs/index.js +4 -0
- package/lib-commonjs/index.js.map +1 -1
- package/lib-commonjs/utils/dropdownKeyActions.js +3 -30
- package/lib-commonjs/utils/dropdownKeyActions.js.map +1 -1
- package/lib-commonjs/utils/useComboboxBaseState.js +59 -16
- package/lib-commonjs/utils/useComboboxBaseState.js.map +1 -1
- package/lib-commonjs/utils/useOptionCollection.js +18 -45
- package/lib-commonjs/utils/useOptionCollection.js.map +1 -1
- package/lib-commonjs/utils/useTriggerSlot.js +84 -31
- package/lib-commonjs/utils/useTriggerSlot.js.map +1 -1
- package/package.json +10 -9
- package/lib/utils/useScrollOptionsIntoView.js +0 -29
- package/lib/utils/useScrollOptionsIntoView.js.map +0 -1
- package/lib-commonjs/utils/useScrollOptionsIntoView.js +0 -40
- package/lib-commonjs/utils/useScrollOptionsIntoView.js.map +0 -1
|
@@ -11,23 +11,26 @@ Object.defineProperty(exports, "useOptionCollection", {
|
|
|
11
11
|
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
|
|
12
12
|
const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
|
|
13
13
|
const useOptionCollection = ()=>{
|
|
14
|
-
const
|
|
14
|
+
const optionsById = _react.useRef(new Map());
|
|
15
15
|
const collectionAPI = _react.useMemo(()=>{
|
|
16
|
-
const getCount = ()=>
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
};
|
|
21
|
-
const getIndexOfId = (id)=>nodes.current.findIndex((node)=>node.option.id === id);
|
|
16
|
+
const getCount = ()=>optionsById.current.size;
|
|
17
|
+
// index searches are no longer used
|
|
18
|
+
const getOptionAtIndex = ()=>undefined;
|
|
19
|
+
const getIndexOfId = ()=>-1;
|
|
22
20
|
const getOptionById = (id)=>{
|
|
23
|
-
|
|
24
|
-
return item === null || item === void 0 ? void 0 : item.option;
|
|
21
|
+
return optionsById.current.get(id);
|
|
25
22
|
};
|
|
26
23
|
const getOptionsMatchingText = (matcher)=>{
|
|
27
|
-
return
|
|
24
|
+
return Array.from(optionsById.current.values()).filter(({ text })=>matcher(text));
|
|
28
25
|
};
|
|
29
26
|
const getOptionsMatchingValue = (matcher)=>{
|
|
30
|
-
|
|
27
|
+
const matches = [];
|
|
28
|
+
for (const option of optionsById.current.values()){
|
|
29
|
+
if (matcher(option.value)) {
|
|
30
|
+
matches.push(option);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return matches;
|
|
31
34
|
};
|
|
32
35
|
return {
|
|
33
36
|
getCount,
|
|
@@ -38,43 +41,13 @@ const useOptionCollection = ()=>{
|
|
|
38
41
|
getOptionsMatchingValue
|
|
39
42
|
};
|
|
40
43
|
}, []);
|
|
41
|
-
const registerOption = _react.useCallback((option
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
if (!node.element || !element) {
|
|
45
|
-
return false;
|
|
46
|
-
}
|
|
47
|
-
if (node.option.id === option.id) {
|
|
48
|
-
return true;
|
|
49
|
-
}
|
|
50
|
-
// use the DOM method compareDocumentPosition to order the current node against registered nodes
|
|
51
|
-
// eslint-disable-next-line no-bitwise
|
|
52
|
-
return node.element.compareDocumentPosition(element) & Node.DOCUMENT_POSITION_PRECEDING;
|
|
53
|
-
});
|
|
54
|
-
// do not register the option if it already exists
|
|
55
|
-
if (((_nodes_current_index = nodes.current[index]) === null || _nodes_current_index === void 0 ? void 0 : _nodes_current_index.option.id) !== option.id) {
|
|
56
|
-
const newItem = {
|
|
57
|
-
element,
|
|
58
|
-
option
|
|
59
|
-
};
|
|
60
|
-
// If an index is not found we will push the element to the end.
|
|
61
|
-
if (index === -1) {
|
|
62
|
-
nodes.current = [
|
|
63
|
-
...nodes.current,
|
|
64
|
-
newItem
|
|
65
|
-
];
|
|
66
|
-
} else {
|
|
67
|
-
nodes.current.splice(index, 0, newItem);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
// return the unregister function
|
|
71
|
-
return ()=>{
|
|
72
|
-
nodes.current = nodes.current.filter((node)=>node.option.id !== option.id);
|
|
73
|
-
};
|
|
44
|
+
const registerOption = _react.useCallback((option)=>{
|
|
45
|
+
optionsById.current.set(option.id, option);
|
|
46
|
+
return ()=>optionsById.current.delete(option.id);
|
|
74
47
|
}, []);
|
|
75
48
|
return {
|
|
76
49
|
...collectionAPI,
|
|
77
|
-
options:
|
|
50
|
+
options: Array.from(optionsById.current.values()),
|
|
78
51
|
registerOption
|
|
79
52
|
};
|
|
80
53
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useOptionCollection.js"],"sourcesContent":["import * as React from 'react';\n/**\n * A hook for managing a collection of child Options\n */ export const useOptionCollection = ()=>{\n const
|
|
1
|
+
{"version":3,"sources":["useOptionCollection.js"],"sourcesContent":["import * as React from 'react';\n/**\n * A hook for managing a collection of child Options\n */ export const useOptionCollection = ()=>{\n const optionsById = React.useRef(new Map());\n const collectionAPI = React.useMemo(()=>{\n const getCount = ()=>optionsById.current.size;\n // index searches are no longer used\n const getOptionAtIndex = ()=>undefined;\n const getIndexOfId = ()=>-1;\n const getOptionById = (id)=>{\n return optionsById.current.get(id);\n };\n const getOptionsMatchingText = (matcher)=>{\n return Array.from(optionsById.current.values()).filter(({ text })=>matcher(text));\n };\n const getOptionsMatchingValue = (matcher)=>{\n const matches = [];\n for (const option of optionsById.current.values()){\n if (matcher(option.value)) {\n matches.push(option);\n }\n }\n return matches;\n };\n return {\n getCount,\n getOptionAtIndex,\n getIndexOfId,\n getOptionById,\n getOptionsMatchingText,\n getOptionsMatchingValue\n };\n }, []);\n const registerOption = React.useCallback((option)=>{\n optionsById.current.set(option.id, option);\n return ()=>optionsById.current.delete(option.id);\n }, []);\n return {\n ...collectionAPI,\n options: Array.from(optionsById.current.values()),\n registerOption\n };\n};\n"],"names":["useOptionCollection","optionsById","React","useRef","Map","collectionAPI","useMemo","getCount","current","size","getOptionAtIndex","undefined","getIndexOfId","getOptionById","id","get","getOptionsMatchingText","matcher","Array","from","values","filter","text","getOptionsMatchingValue","matches","option","value","push","registerOption","useCallback","set","delete","options"],"mappings":";;;;+BAGiBA;;;eAAAA;;;;iEAHM;AAGZ,MAAMA,sBAAsB;IACnC,MAAMC,cAAcC,OAAMC,MAAM,CAAC,IAAIC;IACrC,MAAMC,gBAAgBH,OAAMI,OAAO,CAAC;QAChC,MAAMC,WAAW,IAAIN,YAAYO,OAAO,CAACC,IAAI;QAC7C,oCAAoC;QACpC,MAAMC,mBAAmB,IAAIC;QAC7B,MAAMC,eAAe,IAAI,CAAC;QAC1B,MAAMC,gBAAgB,CAACC;YACnB,OAAOb,YAAYO,OAAO,CAACO,GAAG,CAACD;QACnC;QACA,MAAME,yBAAyB,CAACC;YAC5B,OAAOC,MAAMC,IAAI,CAAClB,YAAYO,OAAO,CAACY,MAAM,IAAIC,MAAM,CAAC,CAAC,EAAEC,IAAI,EAAE,GAAGL,QAAQK;QAC/E;QACA,MAAMC,0BAA0B,CAACN;YAC7B,MAAMO,UAAU,EAAE;YAClB,KAAK,MAAMC,UAAUxB,YAAYO,OAAO,CAACY,MAAM,GAAG;gBAC9C,IAAIH,QAAQQ,OAAOC,KAAK,GAAG;oBACvBF,QAAQG,IAAI,CAACF;gBACjB;YACJ;YACA,OAAOD;QACX;QACA,OAAO;YACHjB;YACAG;YACAE;YACAC;YACAG;YACAO;QACJ;IACJ,GAAG,EAAE;IACL,MAAMK,iBAAiB1B,OAAM2B,WAAW,CAAC,CAACJ;QACtCxB,YAAYO,OAAO,CAACsB,GAAG,CAACL,OAAOX,EAAE,EAAEW;QACnC,OAAO,IAAIxB,YAAYO,OAAO,CAACuB,MAAM,CAACN,OAAOX,EAAE;IACnD,GAAG,EAAE;IACL,OAAO;QACH,GAAGT,aAAa;QAChB2B,SAASd,MAAMC,IAAI,CAAClB,YAAYO,OAAO,CAACY,MAAM;QAC9CQ;IACJ;AACJ"}
|
|
@@ -10,15 +10,15 @@ Object.defineProperty(exports, "useTriggerSlot", {
|
|
|
10
10
|
});
|
|
11
11
|
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
|
|
12
12
|
const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
|
|
13
|
+
const _reacttabster = require("@fluentui/react-tabster");
|
|
13
14
|
const _reactutilities = require("@fluentui/react-utilities");
|
|
14
15
|
const _dropdownKeyActions = require("../utils/dropdownKeyActions");
|
|
15
16
|
function useTriggerSlot(triggerSlotFromProp, ref, options) {
|
|
16
|
-
const { state: {
|
|
17
|
+
const { state: { open, setOpen, setHasFocus }, defaultProps, elementType, activeDescendantController } = options;
|
|
17
18
|
const trigger = _reactutilities.slot.always(triggerSlotFromProp, {
|
|
18
19
|
defaultProps: {
|
|
19
20
|
type: 'text',
|
|
20
21
|
'aria-expanded': open,
|
|
21
|
-
'aria-activedescendant': open ? activeOption === null || activeOption === void 0 ? void 0 : activeOption.id : undefined,
|
|
22
22
|
role: 'combobox',
|
|
23
23
|
...typeof defaultProps === 'object' && defaultProps
|
|
24
24
|
},
|
|
@@ -41,49 +41,102 @@ function useTriggerSlot(triggerSlotFromProp, ref, options) {
|
|
|
41
41
|
setOpen(event, !open);
|
|
42
42
|
}, trigger.onClick);
|
|
43
43
|
// handle combobox keyboard interaction
|
|
44
|
-
trigger.onKeyDown = (0, _reactutilities.mergeCallbacks)((
|
|
45
|
-
|
|
44
|
+
trigger.onKeyDown = (0, _reactutilities.mergeCallbacks)(useTriggerKeydown({
|
|
45
|
+
activeDescendantController,
|
|
46
|
+
...options.state
|
|
47
|
+
}), trigger.onKeyDown);
|
|
48
|
+
return trigger;
|
|
49
|
+
}
|
|
50
|
+
function useTriggerKeydown(options) {
|
|
51
|
+
const { activeDescendantController, getOptionById, setOpen, selectOption, multiselect, open } = options;
|
|
52
|
+
const getActiveOption = _react.useCallback(()=>{
|
|
53
|
+
const activeOptionId = activeDescendantController.active();
|
|
54
|
+
return activeOptionId ? getOptionById(activeOptionId) : undefined;
|
|
55
|
+
}, [
|
|
56
|
+
activeDescendantController,
|
|
57
|
+
getOptionById
|
|
58
|
+
]);
|
|
59
|
+
const first = ()=>{
|
|
60
|
+
activeDescendantController.first();
|
|
61
|
+
};
|
|
62
|
+
const next = (activeOption)=>{
|
|
63
|
+
if (activeOption) {
|
|
64
|
+
activeDescendantController.next();
|
|
65
|
+
} else {
|
|
66
|
+
activeDescendantController.first();
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
const previous = (activeOption)=>{
|
|
70
|
+
if (activeOption) {
|
|
71
|
+
activeDescendantController.prev();
|
|
72
|
+
} else {
|
|
73
|
+
activeDescendantController.first();
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
const pageUp = ()=>{
|
|
77
|
+
for(let i = 0; i < 10; i++){
|
|
78
|
+
activeDescendantController.prev();
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
const pageDown = ()=>{
|
|
82
|
+
for(let i = 0; i < 10; i++){
|
|
83
|
+
activeDescendantController.next();
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
const setKeyboardNavigation = (0, _reacttabster.useSetKeyboardNavigation)();
|
|
87
|
+
return (0, _reactutilities.useEventCallback)((e)=>{
|
|
88
|
+
const action = (0, _dropdownKeyActions.getDropdownActionFromKey)(e, {
|
|
46
89
|
open,
|
|
47
90
|
multiselect
|
|
48
91
|
});
|
|
49
|
-
const
|
|
50
|
-
const activeIndex = activeOption ? getIndexOfId(activeOption.id) : -1;
|
|
51
|
-
let newIndex = activeIndex;
|
|
92
|
+
const activeOption = getActiveOption();
|
|
52
93
|
switch(action){
|
|
94
|
+
case 'First':
|
|
95
|
+
case 'Next':
|
|
96
|
+
case 'Previous':
|
|
97
|
+
case 'PageDown':
|
|
98
|
+
case 'PageUp':
|
|
53
99
|
case 'Open':
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
100
|
+
case 'Close':
|
|
101
|
+
case 'CloseSelect':
|
|
102
|
+
case 'Select':
|
|
103
|
+
e.preventDefault();
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
setKeyboardNavigation(true);
|
|
107
|
+
switch(action){
|
|
108
|
+
case 'First':
|
|
109
|
+
first();
|
|
110
|
+
break;
|
|
111
|
+
case 'Next':
|
|
112
|
+
next(activeOption);
|
|
113
|
+
break;
|
|
114
|
+
case 'Previous':
|
|
115
|
+
previous(activeOption);
|
|
116
|
+
break;
|
|
117
|
+
case 'PageDown':
|
|
118
|
+
pageDown();
|
|
119
|
+
break;
|
|
120
|
+
case 'PageUp':
|
|
121
|
+
pageUp();
|
|
122
|
+
break;
|
|
123
|
+
case 'Open':
|
|
124
|
+
setOpen(e, true);
|
|
57
125
|
break;
|
|
58
126
|
case 'Close':
|
|
59
127
|
// stop propagation for escape key to avoid dismissing any parent popups
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
setOpen(event, false);
|
|
128
|
+
e.stopPropagation();
|
|
129
|
+
setOpen(e, false);
|
|
63
130
|
break;
|
|
64
131
|
case 'CloseSelect':
|
|
65
|
-
!multiselect && !(activeOption === null || activeOption === void 0 ? void 0 : activeOption.disabled) && setOpen(
|
|
132
|
+
!multiselect && !(activeOption === null || activeOption === void 0 ? void 0 : activeOption.disabled) && setOpen(e, false);
|
|
66
133
|
// fallthrough
|
|
67
134
|
case 'Select':
|
|
68
|
-
activeOption && selectOption(
|
|
69
|
-
event.preventDefault();
|
|
135
|
+
activeOption && selectOption(e, activeOption);
|
|
70
136
|
break;
|
|
71
137
|
case 'Tab':
|
|
72
|
-
!multiselect && activeOption && selectOption(
|
|
138
|
+
!multiselect && activeOption && selectOption(e, activeOption);
|
|
73
139
|
break;
|
|
74
|
-
default:
|
|
75
|
-
newIndex = (0, _dropdownKeyActions.getIndexFromAction)(action, activeIndex, maxIndex);
|
|
76
|
-
}
|
|
77
|
-
if (newIndex !== activeIndex) {
|
|
78
|
-
// prevent default page scroll/keyboard action if the index changed
|
|
79
|
-
event.preventDefault();
|
|
80
|
-
setActiveOption(getOptionAtIndex(newIndex));
|
|
81
|
-
setFocusVisible(true);
|
|
82
140
|
}
|
|
83
|
-
}
|
|
84
|
-
trigger.onMouseOver = (0, _reactutilities.mergeCallbacks)((event)=>{
|
|
85
|
-
setFocusVisible(false);
|
|
86
|
-
}, trigger.onMouseOver);
|
|
87
|
-
// TODO fix cast
|
|
88
|
-
return trigger;
|
|
141
|
+
});
|
|
89
142
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useTriggerSlot.js"],"sourcesContent":["import * as React from 'react';\nimport { mergeCallbacks, slot, useMergedRefs } from '@fluentui/react-utilities';\nimport { getDropdownActionFromKey
|
|
1
|
+
{"version":3,"sources":["useTriggerSlot.js"],"sourcesContent":["import * as React from 'react';\nimport { useSetKeyboardNavigation } from '@fluentui/react-tabster';\nimport { mergeCallbacks, slot, useEventCallback, useMergedRefs } from '@fluentui/react-utilities';\nimport { getDropdownActionFromKey } from '../utils/dropdownKeyActions';\n/**\n * Shared trigger behaviour for combobox and dropdown\n * @returns trigger slot with desired behaviour and props\n */ export function useTriggerSlot(triggerSlotFromProp, ref, options) {\n const { state: { open, setOpen, setHasFocus }, defaultProps, elementType, activeDescendantController } = options;\n const trigger = slot.always(triggerSlotFromProp, {\n defaultProps: {\n type: 'text',\n 'aria-expanded': open,\n role: 'combobox',\n ...typeof defaultProps === 'object' && defaultProps\n },\n elementType\n });\n // handle trigger focus/blur\n const triggerRef = React.useRef(null);\n trigger.ref = useMergedRefs(triggerRef, trigger.ref, ref);\n // the trigger should open/close the popup on click or blur\n trigger.onBlur = mergeCallbacks((event)=>{\n setOpen(event, false);\n setHasFocus(false);\n }, trigger.onBlur);\n trigger.onFocus = mergeCallbacks((event)=>{\n if (event.target === event.currentTarget) {\n setHasFocus(true);\n }\n }, trigger.onFocus);\n trigger.onClick = mergeCallbacks((event)=>{\n setOpen(event, !open);\n }, trigger.onClick);\n // handle combobox keyboard interaction\n trigger.onKeyDown = mergeCallbacks(useTriggerKeydown({\n activeDescendantController,\n ...options.state\n }), trigger.onKeyDown);\n return trigger;\n}\nfunction useTriggerKeydown(options) {\n const { activeDescendantController, getOptionById, setOpen, selectOption, multiselect, open } = options;\n const getActiveOption = React.useCallback(()=>{\n const activeOptionId = activeDescendantController.active();\n return activeOptionId ? getOptionById(activeOptionId) : undefined;\n }, [\n activeDescendantController,\n getOptionById\n ]);\n const first = ()=>{\n activeDescendantController.first();\n };\n const next = (activeOption)=>{\n if (activeOption) {\n activeDescendantController.next();\n } else {\n activeDescendantController.first();\n }\n };\n const previous = (activeOption)=>{\n if (activeOption) {\n activeDescendantController.prev();\n } else {\n activeDescendantController.first();\n }\n };\n const pageUp = ()=>{\n for(let i = 0; i < 10; i++){\n activeDescendantController.prev();\n }\n };\n const pageDown = ()=>{\n for(let i = 0; i < 10; i++){\n activeDescendantController.next();\n }\n };\n const setKeyboardNavigation = useSetKeyboardNavigation();\n return useEventCallback((e)=>{\n const action = getDropdownActionFromKey(e, {\n open,\n multiselect\n });\n const activeOption = getActiveOption();\n switch(action){\n case 'First':\n case 'Next':\n case 'Previous':\n case 'PageDown':\n case 'PageUp':\n case 'Open':\n case 'Close':\n case 'CloseSelect':\n case 'Select':\n e.preventDefault();\n break;\n }\n setKeyboardNavigation(true);\n switch(action){\n case 'First':\n first();\n break;\n case 'Next':\n next(activeOption);\n break;\n case 'Previous':\n previous(activeOption);\n break;\n case 'PageDown':\n pageDown();\n break;\n case 'PageUp':\n pageUp();\n break;\n case 'Open':\n setOpen(e, true);\n break;\n case 'Close':\n // stop propagation for escape key to avoid dismissing any parent popups\n e.stopPropagation();\n setOpen(e, false);\n break;\n case 'CloseSelect':\n !multiselect && !(activeOption === null || activeOption === void 0 ? void 0 : activeOption.disabled) && setOpen(e, false);\n // fallthrough\n case 'Select':\n activeOption && selectOption(e, activeOption);\n break;\n case 'Tab':\n !multiselect && activeOption && selectOption(e, activeOption);\n break;\n }\n });\n}\n"],"names":["useTriggerSlot","triggerSlotFromProp","ref","options","state","open","setOpen","setHasFocus","defaultProps","elementType","activeDescendantController","trigger","slot","always","type","role","triggerRef","React","useRef","useMergedRefs","onBlur","mergeCallbacks","event","onFocus","target","currentTarget","onClick","onKeyDown","useTriggerKeydown","getOptionById","selectOption","multiselect","getActiveOption","useCallback","activeOptionId","active","undefined","first","next","activeOption","previous","prev","pageUp","i","pageDown","setKeyboardNavigation","useSetKeyboardNavigation","useEventCallback","e","action","getDropdownActionFromKey","preventDefault","stopPropagation","disabled"],"mappings":";;;;+BAOoBA;;;eAAAA;;;;iEAPG;8BACkB;gCAC6B;oCAC7B;AAI9B,SAASA,eAAeC,mBAAmB,EAAEC,GAAG,EAAEC,OAAO;IAChE,MAAM,EAAEC,OAAO,EAAEC,IAAI,EAAEC,OAAO,EAAEC,WAAW,EAAE,EAAEC,YAAY,EAAEC,WAAW,EAAEC,0BAA0B,EAAE,GAAGP;IACzG,MAAMQ,UAAUC,oBAAI,CAACC,MAAM,CAACZ,qBAAqB;QAC7CO,cAAc;YACVM,MAAM;YACN,iBAAiBT;YACjBU,MAAM;YACN,GAAG,OAAOP,iBAAiB,YAAYA,YAAY;QACvD;QACAC;IACJ;IACA,4BAA4B;IAC5B,MAAMO,aAAaC,OAAMC,MAAM,CAAC;IAChCP,QAAQT,GAAG,GAAGiB,IAAAA,6BAAa,EAACH,YAAYL,QAAQT,GAAG,EAAEA;IACrD,2DAA2D;IAC3DS,QAAQS,MAAM,GAAGC,IAAAA,8BAAc,EAAC,CAACC;QAC7BhB,QAAQgB,OAAO;QACff,YAAY;IAChB,GAAGI,QAAQS,MAAM;IACjBT,QAAQY,OAAO,GAAGF,IAAAA,8BAAc,EAAC,CAACC;QAC9B,IAAIA,MAAME,MAAM,KAAKF,MAAMG,aAAa,EAAE;YACtClB,YAAY;QAChB;IACJ,GAAGI,QAAQY,OAAO;IAClBZ,QAAQe,OAAO,GAAGL,IAAAA,8BAAc,EAAC,CAACC;QAC9BhB,QAAQgB,OAAO,CAACjB;IACpB,GAAGM,QAAQe,OAAO;IAClB,uCAAuC;IACvCf,QAAQgB,SAAS,GAAGN,IAAAA,8BAAc,EAACO,kBAAkB;QACjDlB;QACA,GAAGP,QAAQC,KAAK;IACpB,IAAIO,QAAQgB,SAAS;IACrB,OAAOhB;AACX;AACA,SAASiB,kBAAkBzB,OAAO;IAC9B,MAAM,EAAEO,0BAA0B,EAAEmB,aAAa,EAAEvB,OAAO,EAAEwB,YAAY,EAAEC,WAAW,EAAE1B,IAAI,EAAE,GAAGF;IAChG,MAAM6B,kBAAkBf,OAAMgB,WAAW,CAAC;QACtC,MAAMC,iBAAiBxB,2BAA2ByB,MAAM;QACxD,OAAOD,iBAAiBL,cAAcK,kBAAkBE;IAC5D,GAAG;QACC1B;QACAmB;KACH;IACD,MAAMQ,QAAQ;QACV3B,2BAA2B2B,KAAK;IACpC;IACA,MAAMC,OAAO,CAACC;QACV,IAAIA,cAAc;YACd7B,2BAA2B4B,IAAI;QACnC,OAAO;YACH5B,2BAA2B2B,KAAK;QACpC;IACJ;IACA,MAAMG,WAAW,CAACD;QACd,IAAIA,cAAc;YACd7B,2BAA2B+B,IAAI;QACnC,OAAO;YACH/B,2BAA2B2B,KAAK;QACpC;IACJ;IACA,MAAMK,SAAS;QACX,IAAI,IAAIC,IAAI,GAAGA,IAAI,IAAIA,IAAI;YACvBjC,2BAA2B+B,IAAI;QACnC;IACJ;IACA,MAAMG,WAAW;QACb,IAAI,IAAID,IAAI,GAAGA,IAAI,IAAIA,IAAI;YACvBjC,2BAA2B4B,IAAI;QACnC;IACJ;IACA,MAAMO,wBAAwBC,IAAAA,sCAAwB;IACtD,OAAOC,IAAAA,gCAAgB,EAAC,CAACC;QACrB,MAAMC,SAASC,IAAAA,4CAAwB,EAACF,GAAG;YACvC3C;YACA0B;QACJ;QACA,MAAMQ,eAAeP;QACrB,OAAOiB;YACH,KAAK;YACL,KAAK;YACL,KAAK;YACL,KAAK;YACL,KAAK;YACL,KAAK;YACL,KAAK;YACL,KAAK;YACL,KAAK;gBACDD,EAAEG,cAAc;gBAChB;QACR;QACAN,sBAAsB;QACtB,OAAOI;YACH,KAAK;gBACDZ;gBACA;YACJ,KAAK;gBACDC,KAAKC;gBACL;YACJ,KAAK;gBACDC,SAASD;gBACT;YACJ,KAAK;gBACDK;gBACA;YACJ,KAAK;gBACDF;gBACA;YACJ,KAAK;gBACDpC,QAAQ0C,GAAG;gBACX;YACJ,KAAK;gBACD,wEAAwE;gBACxEA,EAAEI,eAAe;gBACjB9C,QAAQ0C,GAAG;gBACX;YACJ,KAAK;gBACD,CAACjB,eAAe,CAAEQ,CAAAA,iBAAiB,QAAQA,iBAAiB,KAAK,IAAI,KAAK,IAAIA,aAAac,QAAQ,AAAD,KAAM/C,QAAQ0C,GAAG;YACvH,cAAc;YACd,KAAK;gBACDT,gBAAgBT,aAAakB,GAAGT;gBAChC;YACJ,KAAK;gBACD,CAACR,eAAeQ,gBAAgBT,aAAakB,GAAGT;gBAChD;QACR;IACJ;AACJ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluentui/react-combobox",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.9.0",
|
|
4
4
|
"description": "Fluent UI React Combobox component",
|
|
5
5
|
"main": "lib-commonjs/index.js",
|
|
6
6
|
"module": "lib/index.js",
|
|
@@ -33,17 +33,18 @@
|
|
|
33
33
|
"@fluentui/scripts-tasks": "*"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
+
"@fluentui/react-aria": "^9.9.1",
|
|
36
37
|
"@fluentui/keyboard-keys": "^9.0.7",
|
|
37
|
-
"@fluentui/react-context-selector": "^9.1.
|
|
38
|
-
"@fluentui/react-field": "^9.1.
|
|
38
|
+
"@fluentui/react-context-selector": "^9.1.53",
|
|
39
|
+
"@fluentui/react-field": "^9.1.55",
|
|
39
40
|
"@fluentui/react-icons": "^2.0.224",
|
|
40
|
-
"@fluentui/react-jsx-runtime": "^9.0.
|
|
41
|
-
"@fluentui/react-portal": "^9.4.
|
|
42
|
-
"@fluentui/react-positioning": "^9.13.
|
|
43
|
-
"@fluentui/react-shared-contexts": "^9.14.
|
|
44
|
-
"@fluentui/react-tabster": "^9.19.
|
|
41
|
+
"@fluentui/react-jsx-runtime": "^9.0.31",
|
|
42
|
+
"@fluentui/react-portal": "^9.4.15",
|
|
43
|
+
"@fluentui/react-positioning": "^9.13.5",
|
|
44
|
+
"@fluentui/react-shared-contexts": "^9.14.1",
|
|
45
|
+
"@fluentui/react-tabster": "^9.19.2",
|
|
45
46
|
"@fluentui/react-theme": "^9.1.16",
|
|
46
|
-
"@fluentui/react-utilities": "^9.18.
|
|
47
|
+
"@fluentui/react-utilities": "^9.18.2",
|
|
47
48
|
"@griffel/react": "^1.5.14",
|
|
48
49
|
"@swc/helpers": "^0.5.1"
|
|
49
50
|
},
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { canUseDOM } from '@fluentui/react-utilities';
|
|
3
|
-
export function useScrollOptionsIntoView(state) {
|
|
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;
|
|
29
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
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;IAC1D,MAAM,EAAEC,YAAY,EAAE,GAAGD;IACzB,MAAME,qBAAqBL,MAAMM,MAAM,CAAiB;IAExDN,MAAMO,SAAS,CAAC;QACd,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;YAEA,MAAM,EAAEG,YAAY,EAAEC,SAAS,EAAE,GAAGJ;YACpC,MAAM,EAAEG,cAAcE,kBAAkB,EAAEC,SAAS,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;QACF;IACF,GAAG;QAACd;KAAa;IAEjB,OAAOC;AACT"}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "useScrollOptionsIntoView", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return useScrollOptionsIntoView;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
|
|
12
|
-
const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
|
|
13
|
-
const _reactutilities = require("@fluentui/react-utilities");
|
|
14
|
-
function useScrollOptionsIntoView(state) {
|
|
15
|
-
const { activeOption } = state;
|
|
16
|
-
const scrollContainerRef = _react.useRef(null);
|
|
17
|
-
_react.useEffect(()=>{
|
|
18
|
-
if (scrollContainerRef.current && activeOption && (0, _reactutilities.canUseDOM)()) {
|
|
19
|
-
const activeOptionElement = scrollContainerRef.current.querySelector(`#${activeOption.id}`);
|
|
20
|
-
if (!activeOptionElement) {
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
const { offsetHeight, offsetTop } = activeOptionElement;
|
|
24
|
-
const { offsetHeight: parentOffsetHeight, scrollTop } = scrollContainerRef.current;
|
|
25
|
-
const isAbove = offsetTop < scrollTop;
|
|
26
|
-
const isBelow = offsetTop + offsetHeight > scrollTop + parentOffsetHeight;
|
|
27
|
-
// add a small buffer for general visual nicety
|
|
28
|
-
// it looks slightly better if the option has some space from the top/bottom while arrowing
|
|
29
|
-
const buffer = 2;
|
|
30
|
-
if (isAbove) {
|
|
31
|
-
scrollContainerRef.current.scrollTo(0, offsetTop - buffer);
|
|
32
|
-
} else if (isBelow) {
|
|
33
|
-
scrollContainerRef.current.scrollTo(0, offsetTop - parentOffsetHeight + offsetHeight + buffer);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}, [
|
|
37
|
-
activeOption
|
|
38
|
-
]);
|
|
39
|
-
return scrollContainerRef;
|
|
40
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["useScrollOptionsIntoView.js"],"sourcesContent":["import * as React from 'react';\nimport { canUseDOM } from '@fluentui/react-utilities';\nexport function useScrollOptionsIntoView(state) {\n const { activeOption } = state;\n const scrollContainerRef = React.useRef(null);\n React.useEffect(()=>{\n if (scrollContainerRef.current && activeOption && canUseDOM()) {\n const activeOptionElement = scrollContainerRef.current.querySelector(`#${activeOption.id}`);\n if (!activeOptionElement) {\n return;\n }\n const { offsetHeight, offsetTop } = activeOptionElement;\n const { offsetHeight: parentOffsetHeight, scrollTop } = scrollContainerRef.current;\n const isAbove = offsetTop < scrollTop;\n const isBelow = offsetTop + offsetHeight > scrollTop + parentOffsetHeight;\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 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 }, [\n activeOption\n ]);\n return scrollContainerRef;\n}\n"],"names":["useScrollOptionsIntoView","state","activeOption","scrollContainerRef","React","useRef","useEffect","current","canUseDOM","activeOptionElement","querySelector","id","offsetHeight","offsetTop","parentOffsetHeight","scrollTop","isAbove","isBelow","buffer","scrollTo"],"mappings":";;;;+BAEgBA;;;eAAAA;;;;iEAFO;gCACG;AACnB,SAASA,yBAAyBC,KAAK;IAC1C,MAAM,EAAEC,YAAY,EAAE,GAAGD;IACzB,MAAME,qBAAqBC,OAAMC,MAAM,CAAC;IACxCD,OAAME,SAAS,CAAC;QACZ,IAAIH,mBAAmBI,OAAO,IAAIL,gBAAgBM,IAAAA,yBAAS,KAAI;YAC3D,MAAMC,sBAAsBN,mBAAmBI,OAAO,CAACG,aAAa,CAAC,CAAC,CAAC,EAAER,aAAaS,EAAE,CAAC,CAAC;YAC1F,IAAI,CAACF,qBAAqB;gBACtB;YACJ;YACA,MAAM,EAAEG,YAAY,EAAEC,SAAS,EAAE,GAAGJ;YACpC,MAAM,EAAEG,cAAcE,kBAAkB,EAAEC,SAAS,EAAE,GAAGZ,mBAAmBI,OAAO;YAClF,MAAMS,UAAUH,YAAYE;YAC5B,MAAME,UAAUJ,YAAYD,eAAeG,YAAYD;YACvD,+CAA+C;YAC/C,2FAA2F;YAC3F,MAAMI,SAAS;YACf,IAAIF,SAAS;gBACTb,mBAAmBI,OAAO,CAACY,QAAQ,CAAC,GAAGN,YAAYK;YACvD,OAAO,IAAID,SAAS;gBAChBd,mBAAmBI,OAAO,CAACY,QAAQ,CAAC,GAAGN,YAAYC,qBAAqBF,eAAeM;YAC3F;QACJ;IACJ,GAAG;QACChB;KACH;IACD,OAAOC;AACX"}
|