@fluentui/react-combobox 9.5.28 → 9.5.29
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 +21 -2
- package/lib/components/Combobox/useCombobox.js +16 -28
- package/lib/components/Combobox/useCombobox.js.map +1 -1
- package/lib/components/Dropdown/useDropdown.js +17 -25
- package/lib/components/Dropdown/useDropdown.js.map +1 -1
- package/lib/utils/{useComboboxPopup.js → useComboboxPositioning.js} +5 -12
- package/lib/utils/useComboboxPositioning.js.map +1 -0
- package/lib-commonjs/components/Combobox/useCombobox.js +16 -28
- package/lib-commonjs/components/Combobox/useCombobox.js.map +1 -1
- package/lib-commonjs/components/Dropdown/useDropdown.js +17 -25
- package/lib-commonjs/components/Dropdown/useDropdown.js.map +1 -1
- package/lib-commonjs/utils/{useComboboxPopup.js → useComboboxPositioning.js} +8 -14
- package/lib-commonjs/utils/useComboboxPositioning.js.map +1 -0
- package/package.json +17 -11
- package/CHANGELOG.json +0 -4238
- package/lib/utils/useComboboxPopup.js.map +0 -1
- package/lib-commonjs/utils/useComboboxPopup.js.map +0 -1
|
@@ -15,7 +15,7 @@ const _reacticons = require("@fluentui/react-icons");
|
|
|
15
15
|
const _reactutilities = require("@fluentui/react-utilities");
|
|
16
16
|
const _dropdownKeyActions = require("../../utils/dropdownKeyActions");
|
|
17
17
|
const _useComboboxBaseState = require("../../utils/useComboboxBaseState");
|
|
18
|
-
const
|
|
18
|
+
const _useComboboxPositioning = require("../../utils/useComboboxPositioning");
|
|
19
19
|
const _useTriggerListboxSlots = require("../../utils/useTriggerListboxSlots");
|
|
20
20
|
const _Listbox = require("../Listbox/Listbox");
|
|
21
21
|
const useDropdown_unstable = (props, ref)=>{
|
|
@@ -33,16 +33,7 @@ const useDropdown_unstable = (props, ref)=>{
|
|
|
33
33
|
'children'
|
|
34
34
|
]
|
|
35
35
|
});
|
|
36
|
-
|
|
37
|
-
const rootRef = _react.useRef(null);
|
|
38
|
-
const [popupWidth, setPopupWidth] = _react.useState();
|
|
39
|
-
_react.useEffect(()=>{
|
|
40
|
-
var _rootRef_current;
|
|
41
|
-
const width = open ? `${(_rootRef_current = rootRef.current) === null || _rootRef_current === void 0 ? void 0 : _rootRef_current.clientWidth}px` : undefined;
|
|
42
|
-
setPopupWidth(width);
|
|
43
|
-
}, [
|
|
44
|
-
open
|
|
45
|
-
]);
|
|
36
|
+
const [comboboxPopupRef, comboboxTargetRef] = (0, _useComboboxPositioning.useComboboxPositioning)(props);
|
|
46
37
|
// jump to matching option based on typing
|
|
47
38
|
const searchString = _react.useRef('');
|
|
48
39
|
const [setKeyTimeout, clearKeyTimeout] = (0, _reactutilities.useTimeout)();
|
|
@@ -109,15 +100,24 @@ const useDropdown_unstable = (props, ref)=>{
|
|
|
109
100
|
listboxSlot = baseState.open || baseState.hasFocus ? _reactutilities.slot.optional(props.listbox, {
|
|
110
101
|
renderByDefault: true,
|
|
111
102
|
defaultProps: {
|
|
112
|
-
children: props.children
|
|
113
|
-
style: {
|
|
114
|
-
width: popupWidth
|
|
115
|
-
}
|
|
103
|
+
children: props.children
|
|
116
104
|
},
|
|
117
105
|
elementType: _Listbox.Listbox
|
|
118
106
|
}) : undefined;
|
|
119
|
-
[triggerSlot, listboxSlot] = (0, _useComboboxPopup.useComboboxPopup)(props, triggerSlot, listboxSlot);
|
|
120
107
|
[triggerSlot, listboxSlot] = (0, _useTriggerListboxSlots.useTriggerListboxSlots)(props, baseState, ref, triggerSlot, listboxSlot);
|
|
108
|
+
const listboxRef = (0, _reactutilities.useMergedRefs)(listboxSlot === null || listboxSlot === void 0 ? void 0 : listboxSlot.ref, comboboxPopupRef);
|
|
109
|
+
if (listboxSlot) {
|
|
110
|
+
listboxSlot.ref = listboxRef;
|
|
111
|
+
}
|
|
112
|
+
const rootSlot = _reactutilities.slot.always(props.root, {
|
|
113
|
+
defaultProps: {
|
|
114
|
+
'aria-owns': !props.inlinePopup ? listboxSlot === null || listboxSlot === void 0 ? void 0 : listboxSlot.id : undefined,
|
|
115
|
+
children: props.children,
|
|
116
|
+
...rootNativeProps
|
|
117
|
+
},
|
|
118
|
+
elementType: 'div'
|
|
119
|
+
});
|
|
120
|
+
rootSlot.ref = (0, _reactutilities.useMergedRefs)(rootSlot.ref, comboboxTargetRef);
|
|
121
121
|
const state = {
|
|
122
122
|
components: {
|
|
123
123
|
root: 'div',
|
|
@@ -125,14 +125,7 @@ const useDropdown_unstable = (props, ref)=>{
|
|
|
125
125
|
expandIcon: 'span',
|
|
126
126
|
listbox: _Listbox.Listbox
|
|
127
127
|
},
|
|
128
|
-
root:
|
|
129
|
-
defaultProps: {
|
|
130
|
-
'aria-owns': !props.inlinePopup ? listboxSlot === null || listboxSlot === void 0 ? void 0 : listboxSlot.id : undefined,
|
|
131
|
-
children: props.children,
|
|
132
|
-
...rootNativeProps
|
|
133
|
-
},
|
|
134
|
-
elementType: 'div'
|
|
135
|
-
}),
|
|
128
|
+
root: rootSlot,
|
|
136
129
|
button: triggerSlot,
|
|
137
130
|
listbox: listboxSlot,
|
|
138
131
|
expandIcon: _reactutilities.slot.optional(props.expandIcon, {
|
|
@@ -145,6 +138,5 @@ const useDropdown_unstable = (props, ref)=>{
|
|
|
145
138
|
placeholderVisible: !baseState.value && !!props.placeholder,
|
|
146
139
|
...baseState
|
|
147
140
|
};
|
|
148
|
-
state.root.ref = (0, _reactutilities.useMergedRefs)(state.root.ref, rootRef);
|
|
149
141
|
return state;
|
|
150
142
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useDropdown.js"],"sourcesContent":["import * as React from 'react';\nimport { useFieldControlProps_unstable } from '@fluentui/react-field';\nimport { ChevronDownRegular as ChevronDownIcon } from '@fluentui/react-icons';\nimport { getPartitionedNativeProps, mergeCallbacks, useMergedRefs, useTimeout, slot } from '@fluentui/react-utilities';\nimport { getDropdownActionFromKey } from '../../utils/dropdownKeyActions';\nimport { useComboboxBaseState } from '../../utils/useComboboxBaseState';\nimport { useComboboxPopup } from '../../utils/useComboboxPopup';\nimport { useTriggerListboxSlots } from '../../utils/useTriggerListboxSlots';\nimport { Listbox } from '../Listbox/Listbox';\n/**\n * Create the state required to render Dropdown.\n *\n * The returned state can be modified with hooks such as useDropdownStyles_unstable,\n * before being passed to renderDropdown_unstable.\n *\n * @param props - props from this instance of Dropdown\n * @param ref - reference to root HTMLElement of Dropdown\n */ export const useDropdown_unstable = (props, ref)=>{\n // Merge props from surrounding <Field>, if any\n props = useFieldControlProps_unstable(props, {\n supportsLabelFor: true,\n supportsSize: true\n });\n const baseState = useComboboxBaseState(props);\n const { activeOption, getIndexOfId, getOptionsMatchingText, open, setActiveOption, setFocusVisible, setOpen } = baseState;\n const { primary: triggerNativeProps, root: rootNativeProps } = getPartitionedNativeProps({\n props,\n primarySlotTagName: 'button',\n excludedPropNames: [\n 'children'\n ]\n });\n // set listbox popup width based off the root/trigger width\n const rootRef = React.useRef(null);\n const [popupWidth, setPopupWidth] = React.useState();\n React.useEffect(()=>{\n var _rootRef_current;\n const width = open ? `${(_rootRef_current = rootRef.current) === null || _rootRef_current === void 0 ? void 0 : _rootRef_current.clientWidth}px` : undefined;\n setPopupWidth(width);\n }, [\n open\n ]);\n // jump to matching option based on typing\n const searchString = React.useRef('');\n const [setKeyTimeout, clearKeyTimeout] = useTimeout();\n const getNextMatchingOption = ()=>{\n // first check for matches for the full searchString\n let matcher = (optionText)=>optionText.toLowerCase().indexOf(searchString.current) === 0;\n let matches = getOptionsMatchingText(matcher);\n let startIndex = activeOption ? getIndexOfId(activeOption.id) : 0;\n // if the dropdown is already open and the searchstring is a single character,\n // then look after the current activeOption for letters\n // this is so slowly typing the same letter will cycle through matches\n if (open && searchString.current.length === 1) {\n startIndex++;\n }\n // if there are no direct matches, check if the search is all the same letter, e.g. \"aaa\"\n if (!matches.length) {\n const letters = searchString.current.split('');\n const allSameLetter = letters.length && letters.every((letter)=>letter === letters[0]);\n // if the search is all the same letter, cycle through options starting with that letter\n if (allSameLetter) {\n startIndex++;\n matcher = (optionText)=>optionText.toLowerCase().indexOf(letters[0]) === 0;\n matches = getOptionsMatchingText(matcher);\n }\n }\n // if there is an active option and multiple matches,\n // return first matching option after the current active option, looping back to the top\n if (matches.length > 1 && activeOption) {\n const nextMatch = matches.find((option)=>getIndexOfId(option.id) >= startIndex);\n return nextMatch !== null && nextMatch !== void 0 ? nextMatch : matches[0];\n }\n var _matches_;\n return (_matches_ = matches[0]) !== null && _matches_ !== void 0 ? _matches_ : undefined;\n };\n const onTriggerKeyDown = (ev)=>{\n // clear timeout, if it exists\n clearKeyTimeout();\n // if the key was a char key, update search string\n if (getDropdownActionFromKey(ev) === 'Type') {\n // update search string\n searchString.current += ev.key.toLowerCase();\n setKeyTimeout(()=>{\n searchString.current = '';\n }, 500);\n // update state\n !open && setOpen(ev, true);\n const nextOption = getNextMatchingOption();\n setActiveOption(nextOption);\n setFocusVisible(true);\n }\n };\n // resolve button and listbox slot props\n let triggerSlot;\n let listboxSlot;\n triggerSlot = slot.always(props.button, {\n defaultProps: {\n type: 'button',\n children: baseState.value || props.placeholder,\n ...triggerNativeProps\n },\n elementType: 'button'\n });\n triggerSlot.onKeyDown = mergeCallbacks(onTriggerKeyDown, triggerSlot.onKeyDown);\n listboxSlot = baseState.open || baseState.hasFocus ? slot.optional(props.listbox, {\n renderByDefault: true,\n defaultProps: {\n children: props.children,\n style: {\n width: popupWidth\n }\n },\n elementType: Listbox\n }) : undefined;\n [triggerSlot, listboxSlot] = useComboboxPopup(props, triggerSlot, listboxSlot);\n [triggerSlot, listboxSlot] = useTriggerListboxSlots(props, baseState, ref, triggerSlot, listboxSlot);\n const state = {\n components: {\n root: 'div',\n button: 'button',\n expandIcon: 'span',\n listbox: Listbox\n },\n root: slot.always(props.root, {\n defaultProps: {\n 'aria-owns': !props.inlinePopup ? listboxSlot === null || listboxSlot === void 0 ? void 0 : listboxSlot.id : undefined,\n children: props.children,\n ...rootNativeProps\n },\n elementType: 'div'\n }),\n button: triggerSlot,\n listbox: listboxSlot,\n expandIcon: slot.optional(props.expandIcon, {\n renderByDefault: true,\n defaultProps: {\n children: /*#__PURE__*/ React.createElement(ChevronDownIcon, null)\n },\n elementType: 'span'\n }),\n placeholderVisible: !baseState.value && !!props.placeholder,\n ...baseState\n };\n state.root.ref = useMergedRefs(state.root.ref, rootRef);\n return state;\n};\n"],"names":["useDropdown_unstable","props","ref","useFieldControlProps_unstable","supportsLabelFor","supportsSize","baseState","useComboboxBaseState","activeOption","getIndexOfId","getOptionsMatchingText","open","setActiveOption","setFocusVisible","setOpen","primary","triggerNativeProps","root","rootNativeProps","getPartitionedNativeProps","primarySlotTagName","excludedPropNames","rootRef","React","useRef","popupWidth","setPopupWidth","useState","useEffect","_rootRef_current","width","current","clientWidth","undefined","searchString","setKeyTimeout","clearKeyTimeout","useTimeout","getNextMatchingOption","matcher","optionText","toLowerCase","indexOf","matches","startIndex","id","length","letters","split","allSameLetter","every","letter","nextMatch","find","option","_matches_","onTriggerKeyDown","ev","getDropdownActionFromKey","key","nextOption","triggerSlot","listboxSlot","slot","always","button","defaultProps","type","children","value","placeholder","elementType","onKeyDown","mergeCallbacks","hasFocus","optional","listbox","renderByDefault","style","Listbox","useComboboxPopup","useTriggerListboxSlots","state","components","expandIcon","inlinePopup","createElement","ChevronDownIcon","placeholderVisible","useMergedRefs"],"mappings":";;;;+BAiBiBA;;;eAAAA;;;;iEAjBM;4BACuB;4BACQ;gCACqC;oCAClD;sCACJ;kCACJ;wCACM;yBACf;AASb,MAAMA,uBAAuB,CAACC,OAAOC;IAC5C,+CAA+C;IAC/CD,QAAQE,IAAAA,yCAA6B,EAACF,OAAO;QACzCG,kBAAkB;QAClBC,cAAc;IAClB;IACA,MAAMC,YAAYC,IAAAA,0CAAoB,EAACN;IACvC,MAAM,EAAEO,YAAY,EAAEC,YAAY,EAAEC,sBAAsB,EAAEC,IAAI,EAAEC,eAAe,EAAEC,eAAe,EAAEC,OAAO,EAAE,GAAGR;IAChH,MAAM,EAAES,SA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Q;YACxBU,OAAO;gBACHhD,OAAOL;YACX;QACJ;QACA8C,aAAaQ,gBAAO;IACxB,KAAK9C;IACL,CAAC4B,aAAaC,YAAY,GAAGkB,IAAAA,kCAAgB,EAAC/E,OAAO4D,aAAaC;IAClE,CAACD,aAAaC,YAAY,GAAGmB,IAAAA,8CAAsB,EAAChF,OAAOK,WAAWJ,KAAK2D,aAAaC;IACxF,MAAMoB,QAAQ;QACVC,YAAY;YACRlE,MAAM;YACNgD,QAAQ;YACRmB,YAAY;YACZR,SAASG,gBAAO;QACpB;QACA9D,MAAM8C,oBAAI,CAACC,MAAM,CAAC/D,MAAMgB,IAAI,EAAE;YAC1BiD,cAAc;gBACV,aAAa,CAACjE,MAAMoF,WAAW,GAAGvB,gBAAgB,QAAQA,gBAAgB,KAAK,IAAI,KAAK,IAAIA,YAAYjB,EAAE,GAAGZ;gBAC7GmC,UAAUnE,MAAMmE,QAAQ;gBACxB,GAAGlD,eAAe;YACtB;YACAqD,aAAa;QACjB;QACAN,QAAQJ;QACRe,SAASd;QACTsB,YAAYrB,oBAAI,CAACY,QAAQ,CAAC1E,MAAMmF,UAAU,EAAE;YACxCP,iBAAiB;YACjBX,cAAc;gBACVE,UAAU,WAAW,GAAG7C,OAAM+D,aAAa,CAACC,8BAAe,EAAE;YACjE;YACAhB,aAAa;QACjB;QACAiB,oBAAoB,CAAClF,UAAU+D,KAAK,IAAI,CAAC,CAACpE,MAAMqE,WAAW;QAC3D,GAAGhE,SAAS;IAChB;IACA4E,MAAMjE,IAAI,CAACf,GAAG,GAAGuF,IAAAA,6BAAa,EAACP,MAAMjE,IAAI,CAACf,GAAG,EAAEoB;IAC/C,OAAO4D;AACX"}
|
|
1
|
+
{"version":3,"sources":["useDropdown.js"],"sourcesContent":["import * as React from 'react';\nimport { useFieldControlProps_unstable } from '@fluentui/react-field';\nimport { ChevronDownRegular as ChevronDownIcon } from '@fluentui/react-icons';\nimport { getPartitionedNativeProps, mergeCallbacks, useMergedRefs, useTimeout, slot } from '@fluentui/react-utilities';\nimport { getDropdownActionFromKey } from '../../utils/dropdownKeyActions';\nimport { useComboboxBaseState } from '../../utils/useComboboxBaseState';\nimport { useComboboxPositioning } from '../../utils/useComboboxPositioning';\nimport { useTriggerListboxSlots } from '../../utils/useTriggerListboxSlots';\nimport { Listbox } from '../Listbox/Listbox';\n/**\n * Create the state required to render Dropdown.\n *\n * The returned state can be modified with hooks such as useDropdownStyles_unstable,\n * before being passed to renderDropdown_unstable.\n *\n * @param props - props from this instance of Dropdown\n * @param ref - reference to root HTMLElement of Dropdown\n */ export const useDropdown_unstable = (props, ref)=>{\n // Merge props from surrounding <Field>, if any\n props = useFieldControlProps_unstable(props, {\n supportsLabelFor: true,\n supportsSize: true\n });\n const baseState = useComboboxBaseState(props);\n const { activeOption, getIndexOfId, getOptionsMatchingText, open, setActiveOption, setFocusVisible, setOpen } = baseState;\n const { primary: triggerNativeProps, root: rootNativeProps } = getPartitionedNativeProps({\n props,\n primarySlotTagName: 'button',\n excludedPropNames: [\n 'children'\n ]\n });\n const [comboboxPopupRef, comboboxTargetRef] = useComboboxPositioning(props);\n // jump to matching option based on typing\n const searchString = React.useRef('');\n const [setKeyTimeout, clearKeyTimeout] = useTimeout();\n const getNextMatchingOption = ()=>{\n // first check for matches for the full searchString\n let matcher = (optionText)=>optionText.toLowerCase().indexOf(searchString.current) === 0;\n let matches = getOptionsMatchingText(matcher);\n let startIndex = activeOption ? getIndexOfId(activeOption.id) : 0;\n // if the dropdown is already open and the searchstring is a single character,\n // then look after the current activeOption for letters\n // this is so slowly typing the same letter will cycle through matches\n if (open && searchString.current.length === 1) {\n startIndex++;\n }\n // if there are no direct matches, check if the search is all the same letter, e.g. \"aaa\"\n if (!matches.length) {\n const letters = searchString.current.split('');\n const allSameLetter = letters.length && letters.every((letter)=>letter === letters[0]);\n // if the search is all the same letter, cycle through options starting with that letter\n if (allSameLetter) {\n startIndex++;\n matcher = (optionText)=>optionText.toLowerCase().indexOf(letters[0]) === 0;\n matches = getOptionsMatchingText(matcher);\n }\n }\n // if there is an active option and multiple matches,\n // return first matching option after the current active option, looping back to the top\n if (matches.length > 1 && activeOption) {\n const nextMatch = matches.find((option)=>getIndexOfId(option.id) >= startIndex);\n return nextMatch !== null && nextMatch !== void 0 ? nextMatch : matches[0];\n }\n var _matches_;\n return (_matches_ = matches[0]) !== null && _matches_ !== void 0 ? _matches_ : undefined;\n };\n const onTriggerKeyDown = (ev)=>{\n // clear timeout, if it exists\n clearKeyTimeout();\n // if the key was a char key, update search string\n if (getDropdownActionFromKey(ev) === 'Type') {\n // update search string\n searchString.current += ev.key.toLowerCase();\n setKeyTimeout(()=>{\n searchString.current = '';\n }, 500);\n // update state\n !open && setOpen(ev, true);\n const nextOption = getNextMatchingOption();\n setActiveOption(nextOption);\n setFocusVisible(true);\n }\n };\n // resolve button and listbox slot props\n let triggerSlot;\n let listboxSlot;\n triggerSlot = slot.always(props.button, {\n defaultProps: {\n type: 'button',\n children: baseState.value || props.placeholder,\n ...triggerNativeProps\n },\n elementType: 'button'\n });\n triggerSlot.onKeyDown = mergeCallbacks(onTriggerKeyDown, triggerSlot.onKeyDown);\n listboxSlot = baseState.open || baseState.hasFocus ? slot.optional(props.listbox, {\n renderByDefault: true,\n defaultProps: {\n children: props.children\n },\n elementType: Listbox\n }) : undefined;\n [triggerSlot, listboxSlot] = useTriggerListboxSlots(props, baseState, ref, triggerSlot, listboxSlot);\n const listboxRef = useMergedRefs(listboxSlot === null || listboxSlot === void 0 ? void 0 : listboxSlot.ref, comboboxPopupRef);\n if (listboxSlot) {\n listboxSlot.ref = listboxRef;\n }\n const rootSlot = slot.always(props.root, {\n defaultProps: {\n 'aria-owns': !props.inlinePopup ? listboxSlot === null || listboxSlot === void 0 ? void 0 : listboxSlot.id : undefined,\n children: props.children,\n ...rootNativeProps\n },\n elementType: 'div'\n });\n rootSlot.ref = useMergedRefs(rootSlot.ref, comboboxTargetRef);\n const state = {\n components: {\n root: 'div',\n button: 'button',\n expandIcon: 'span',\n listbox: Listbox\n },\n root: rootSlot,\n button: triggerSlot,\n listbox: listboxSlot,\n expandIcon: slot.optional(props.expandIcon, {\n renderByDefault: true,\n defaultProps: {\n children: /*#__PURE__*/ React.createElement(ChevronDownIcon, null)\n },\n elementType: 'span'\n }),\n placeholderVisible: !baseState.value && !!props.placeholder,\n ...baseState\n };\n return state;\n};\n"],"names":["useDropdown_unstable","props","ref","useFieldControlProps_unstable","supportsLabelFor","supportsSize","baseState","useComboboxBaseState","activeOption","getIndexOfId","getOptionsMatchingText","open","setActiveOption","setFocusVisible","setOpen","primary","triggerNativeProps","root","rootNativeProps","getPartitionedNativeProps","primarySlotTagName","excludedPropNames","comboboxPopupRef","comboboxTargetRef","useComboboxPositioning","searchString","React","useRef","setKeyTimeout","clearKeyTimeout","useTimeout","getNextMatchingOption","matcher","optionText","toLowerCase","indexOf","current","matches","startIndex","id","length","letters","split","allSameLetter","every","letter","nextMatch","find","option","_matches_","undefined","onTriggerKeyDown","ev","getDropdownActionFromKey","key","nextOption","triggerSlot","listboxSlot","slot","always","button","defaultProps","type","children","value","placeholder","elementType","onKeyDown","mergeCallbacks","hasFocus","optional","listbox","renderByDefault","Listbox","useTriggerListboxSlots","listboxRef","useMergedRefs","rootSlot","inlinePopup","state","components","expandIcon","createElement","ChevronDownIcon","placeholderVisible"],"mappings":";;;;+BAiBiBA;;;eAAAA;;;;iEAjBM;4BACuB;4BACQ;gCACqC;oCAClD;sCACJ;wCACE;wCACA;yBACf;AASb,MAAMA,uBAAuB,CAACC,OAAOC;IAC5C,+CAA+C;IAC/CD,QAAQE,IAAAA,yCAA6B,EAACF,OAAO;QACzCG,kBAAkB;QAClBC,cAAc;IAClB;IACA,MAAMC,YAAYC,IAAAA,0CAAoB,EAACN;IACvC,MAAM,EAAEO,YAAY,EAAEC,YAAY,EAAEC,sBAAsB,EAAEC,IAAI,EAAEC,eAAe,EAAEC,eAAe,EAAEC,OAAO,EAAE,GAAGR;IAChH,MAAM,EAAES,SAASC,k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;IACA,MAAME,WAAWnB,oBAAI,CAACC,MAAM,CAAC1D,MAAMgB,IAAI,EAAE;QACrC4C,cAAc;YACV,aAAa,CAAC5D,MAAM6E,WAAW,GAAGrB,gBAAgB,QAAQA,gBAAgB,KAAK,IAAI,KAAK,IAAIA,YAAYlB,EAAE,GAAGW;YAC7Ga,UAAU9D,MAAM8D,QAAQ;YACxB,GAAG7C,eAAe;QACtB;QACAgD,aAAa;IACjB;IACAW,SAAS3E,GAAG,GAAG0E,IAAAA,6BAAa,EAACC,SAAS3E,GAAG,EAAEqB;IAC3C,MAAMwD,QAAQ;QACVC,YAAY;YACR/D,MAAM;YACN2C,QAAQ;YACRqB,YAAY;YACZV,SAASE,gBAAO;QACpB;QACAxD,MAAM4D;QACNjB,QAAQJ;QACRe,SAASd;QACTwB,YAAYvB,oBAAI,CAACY,QAAQ,CAACrE,MAAMgF,UAAU,EAAE;YACxCT,iBAAiB;YACjBX,cAAc;gBACVE,UAAU,WAAW,GAAGrC,OAAMwD,aAAa,CAACC,8BAAe,EAAE;YACjE;YACAjB,aAAa;QACjB;QACAkB,oBAAoB,CAAC9E,UAAU0D,KAAK,IAAI,CAAC,CAAC/D,MAAMgE,WAAW;QAC3D,GAAG3D,SAAS;IAChB;IACA,OAAOyE;AACX"}
|
|
@@ -2,15 +2,16 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
Object.defineProperty(exports, "
|
|
5
|
+
Object.defineProperty(exports, "useComboboxPositioning", {
|
|
6
6
|
enumerable: true,
|
|
7
7
|
get: function() {
|
|
8
|
-
return
|
|
8
|
+
return useComboboxPositioning;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
+
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
|
|
11
12
|
const _reactpositioning = require("@fluentui/react-positioning");
|
|
12
|
-
const
|
|
13
|
-
function
|
|
13
|
+
const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
|
|
14
|
+
function useComboboxPositioning(props) {
|
|
14
15
|
const { positioning } = props;
|
|
15
16
|
// Set a default set of fallback positions to try if the dropdown does not fit on screen
|
|
16
17
|
const fallbackPositions = [
|
|
@@ -29,19 +30,12 @@ function useComboboxPopup(props, triggerShorthand, listboxShorthand) {
|
|
|
29
30
|
mainAxis: 2
|
|
30
31
|
},
|
|
31
32
|
fallbackPositions,
|
|
33
|
+
matchTargetSize: 'width',
|
|
32
34
|
...(0, _reactpositioning.resolvePositioningShorthand)(positioning)
|
|
33
35
|
};
|
|
34
36
|
const { targetRef, containerRef } = (0, _reactpositioning.usePositioning)(popperOptions);
|
|
35
|
-
const listboxRef = (0, _reactutilities.useMergedRefs)(listboxShorthand === null || listboxShorthand === void 0 ? void 0 : listboxShorthand.ref, containerRef);
|
|
36
|
-
const listbox = listboxShorthand && {
|
|
37
|
-
...listboxShorthand,
|
|
38
|
-
ref: listboxRef
|
|
39
|
-
};
|
|
40
37
|
return [
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
ref: (0, _reactutilities.useMergedRefs)(triggerShorthand === null || triggerShorthand === void 0 ? void 0 : triggerShorthand.ref, targetRef)
|
|
44
|
-
},
|
|
45
|
-
listbox
|
|
38
|
+
containerRef,
|
|
39
|
+
targetRef
|
|
46
40
|
];
|
|
47
41
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["useComboboxPositioning.js"],"sourcesContent":["import { resolvePositioningShorthand, usePositioning } from '@fluentui/react-positioning';\nimport * as React from 'react';\nexport function useComboboxPositioning(props) {\n const { positioning } = props;\n // Set a default set of fallback positions to try if the dropdown does not fit on screen\n const fallbackPositions = [\n 'above',\n 'after',\n 'after-top',\n 'before',\n 'before-top'\n ];\n // popper options\n const popperOptions = {\n position: 'below',\n align: 'start',\n offset: {\n crossAxis: 0,\n mainAxis: 2\n },\n fallbackPositions,\n matchTargetSize: 'width',\n ...resolvePositioningShorthand(positioning)\n };\n const { targetRef, containerRef } = usePositioning(popperOptions);\n return [\n containerRef,\n targetRef\n ];\n}\n"],"names":["useComboboxPositioning","props","positioning","fallbackPositions","popperOptions","position","align","offset","crossAxis","mainAxis","matchTargetSize","resolvePositioningShorthand","targetRef","containerRef","usePositioning"],"mappings":";;;;+BAEgBA;;;eAAAA;;;;kCAF4C;iEACrC;AAChB,SAASA,uBAAuBC,KAAK;IACxC,MAAM,EAAEC,WAAW,EAAE,GAAGD;IACxB,wFAAwF;IACxF,MAAME,oBAAoB;QACtB;QACA;QACA;QACA;QACA;KACH;IACD,iBAAiB;IACjB,MAAMC,gBAAgB;QAClBC,UAAU;QACVC,OAAO;QACPC,QAAQ;YACJC,WAAW;YACXC,UAAU;QACd;QACAN;QACAO,iBAAiB;QACjB,GAAGC,IAAAA,6CAA2B,EAACT,YAAY;IAC/C;IACA,MAAM,EAAEU,SAAS,EAAEC,YAAY,EAAE,GAAGC,IAAAA,gCAAc,EAACV;IACnD,OAAO;QACHS;QACAD;KACH;AACL"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluentui/react-combobox",
|
|
3
|
-
"version": "9.5.
|
|
3
|
+
"version": "9.5.29",
|
|
4
4
|
"description": "Fluent UI React Combobox component",
|
|
5
5
|
"main": "lib-commonjs/index.js",
|
|
6
6
|
"module": "lib/index.js",
|
|
@@ -33,16 +33,16 @@
|
|
|
33
33
|
"@fluentui/scripts-tasks": "*"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@fluentui/keyboard-keys": "^9.0.
|
|
37
|
-
"@fluentui/react-context-selector": "^9.1.
|
|
38
|
-
"@fluentui/react-field": "^9.1.
|
|
36
|
+
"@fluentui/keyboard-keys": "^9.0.7",
|
|
37
|
+
"@fluentui/react-context-selector": "^9.1.42",
|
|
38
|
+
"@fluentui/react-field": "^9.1.41",
|
|
39
39
|
"@fluentui/react-icons": "^2.0.217",
|
|
40
|
-
"@fluentui/react-jsx-runtime": "^9.0.
|
|
41
|
-
"@fluentui/react-portal": "^9.
|
|
42
|
-
"@fluentui/react-positioning": "^9.
|
|
43
|
-
"@fluentui/react-shared-contexts": "^9.
|
|
44
|
-
"@fluentui/react-theme": "^9.1.
|
|
45
|
-
"@fluentui/react-utilities": "^9.15.
|
|
40
|
+
"@fluentui/react-jsx-runtime": "^9.0.19",
|
|
41
|
+
"@fluentui/react-portal": "^9.4.0",
|
|
42
|
+
"@fluentui/react-positioning": "^9.10.0",
|
|
43
|
+
"@fluentui/react-shared-contexts": "^9.12.0",
|
|
44
|
+
"@fluentui/react-theme": "^9.1.16",
|
|
45
|
+
"@fluentui/react-utilities": "^9.15.2",
|
|
46
46
|
"@griffel/react": "^1.5.14",
|
|
47
47
|
"@swc/helpers": "^0.5.1"
|
|
48
48
|
},
|
|
@@ -67,5 +67,11 @@
|
|
|
67
67
|
"require": "./lib-commonjs/index.js"
|
|
68
68
|
},
|
|
69
69
|
"./package.json": "./package.json"
|
|
70
|
-
}
|
|
70
|
+
},
|
|
71
|
+
"files": [
|
|
72
|
+
"*.md",
|
|
73
|
+
"dist/*.d.ts",
|
|
74
|
+
"lib",
|
|
75
|
+
"lib-commonjs"
|
|
76
|
+
]
|
|
71
77
|
}
|