@fluentui/react-combobox 9.5.27 → 9.5.28
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 +46 -1
- package/CHANGELOG.md +16 -2
- package/lib/utils/useTriggerListboxSlots.js +14 -1
- package/lib/utils/useTriggerListboxSlots.js.map +1 -1
- package/lib-commonjs/utils/useTriggerListboxSlots.js +14 -1
- package/lib-commonjs/utils/useTriggerListboxSlots.js.map +1 -1
- package/package.json +6 -6
package/CHANGELOG.json
CHANGED
|
@@ -2,7 +2,52 @@
|
|
|
2
2
|
"name": "@fluentui/react-combobox",
|
|
3
3
|
"entries": [
|
|
4
4
|
{
|
|
5
|
-
"date": "
|
|
5
|
+
"date": "Wed, 01 Nov 2023 12:51:06 GMT",
|
|
6
|
+
"tag": "@fluentui/react-combobox_v9.5.28",
|
|
7
|
+
"version": "9.5.28",
|
|
8
|
+
"comments": {
|
|
9
|
+
"patch": [
|
|
10
|
+
{
|
|
11
|
+
"author": "makotom@microsoft.com",
|
|
12
|
+
"package": "@fluentui/react-combobox",
|
|
13
|
+
"commit": "787e8e99a558d76ac2c2bdfe9f1537cf723b74cb",
|
|
14
|
+
"comment": "fix: Combobox now collapses when mousing up outside of listbox after having moused within it."
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"author": "beachball",
|
|
18
|
+
"package": "@fluentui/react-combobox",
|
|
19
|
+
"comment": "Bump @fluentui/react-field to v9.1.40",
|
|
20
|
+
"commit": "838b05367dbdddb17732b9e0c807090e0a4445d5"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"author": "beachball",
|
|
24
|
+
"package": "@fluentui/react-combobox",
|
|
25
|
+
"comment": "Bump @fluentui/react-portal to v9.3.27",
|
|
26
|
+
"commit": "838b05367dbdddb17732b9e0c807090e0a4445d5"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"author": "beachball",
|
|
30
|
+
"package": "@fluentui/react-combobox",
|
|
31
|
+
"comment": "Bump @fluentui/react-positioning to v9.9.23",
|
|
32
|
+
"commit": "838b05367dbdddb17732b9e0c807090e0a4445d5"
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"author": "beachball",
|
|
36
|
+
"package": "@fluentui/react-combobox",
|
|
37
|
+
"comment": "Bump @fluentui/react-shared-contexts to v9.11.1",
|
|
38
|
+
"commit": "838b05367dbdddb17732b9e0c807090e0a4445d5"
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"author": "beachball",
|
|
42
|
+
"package": "@fluentui/react-combobox",
|
|
43
|
+
"comment": "Bump @fluentui/react-theme to v9.1.15",
|
|
44
|
+
"commit": "838b05367dbdddb17732b9e0c807090e0a4445d5"
|
|
45
|
+
}
|
|
46
|
+
]
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"date": "Sat, 28 Oct 2023 23:35:55 GMT",
|
|
6
51
|
"tag": "@fluentui/react-combobox_v9.5.27",
|
|
7
52
|
"version": "9.5.27",
|
|
8
53
|
"comments": {
|
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,26 @@
|
|
|
1
1
|
# Change Log - @fluentui/react-combobox
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Wed, 01 Nov 2023 12:51:06 GMT and should not be manually modified.
|
|
4
4
|
|
|
5
5
|
<!-- Start content -->
|
|
6
6
|
|
|
7
|
+
## [9.5.28](https://github.com/microsoft/fluentui/tree/@fluentui/react-combobox_v9.5.28)
|
|
8
|
+
|
|
9
|
+
Wed, 01 Nov 2023 12:51:06 GMT
|
|
10
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-combobox_v9.5.27..@fluentui/react-combobox_v9.5.28)
|
|
11
|
+
|
|
12
|
+
### Patches
|
|
13
|
+
|
|
14
|
+
- fix: Combobox now collapses when mousing up outside of listbox after having moused within it. ([PR #29682](https://github.com/microsoft/fluentui/pull/29682) by makotom@microsoft.com)
|
|
15
|
+
- Bump @fluentui/react-field to v9.1.40 ([PR #29663](https://github.com/microsoft/fluentui/pull/29663) by beachball)
|
|
16
|
+
- Bump @fluentui/react-portal to v9.3.27 ([PR #29663](https://github.com/microsoft/fluentui/pull/29663) by beachball)
|
|
17
|
+
- Bump @fluentui/react-positioning to v9.9.23 ([PR #29663](https://github.com/microsoft/fluentui/pull/29663) by beachball)
|
|
18
|
+
- Bump @fluentui/react-shared-contexts to v9.11.1 ([PR #29663](https://github.com/microsoft/fluentui/pull/29663) by beachball)
|
|
19
|
+
- Bump @fluentui/react-theme to v9.1.15 ([PR #29663](https://github.com/microsoft/fluentui/pull/29663) by beachball)
|
|
20
|
+
|
|
7
21
|
## [9.5.27](https://github.com/microsoft/fluentui/tree/@fluentui/react-combobox_v9.5.27)
|
|
8
22
|
|
|
9
|
-
Sat, 28 Oct 2023 23:
|
|
23
|
+
Sat, 28 Oct 2023 23:35:55 GMT
|
|
10
24
|
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-combobox_v9.5.26..@fluentui/react-combobox_v9.5.27)
|
|
11
25
|
|
|
12
26
|
### Patches
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
+
import { useFluent_unstable } from '@fluentui/react-shared-contexts';
|
|
2
3
|
import { mergeCallbacks, useId, useEventCallback, useMergedRefs } from '@fluentui/react-utilities';
|
|
3
4
|
import { getDropdownActionFromKey, getIndexFromAction } from '../utils/dropdownKeyActions';
|
|
4
5
|
/*
|
|
@@ -10,13 +11,16 @@ import { getDropdownActionFromKey, getIndexFromAction } from '../utils/dropdownK
|
|
|
10
11
|
const { activeOption, getCount, getIndexOfId, getOptionAtIndex, ignoreNextBlur, open, selectOption, setActiveOption, setFocusVisible, setHasFocus, setOpen } = state;
|
|
11
12
|
// handle trigger focus/blur
|
|
12
13
|
const triggerRef = React.useRef(null);
|
|
14
|
+
const listboxRef = React.useRef(null);
|
|
13
15
|
// resolve listbox shorthand props
|
|
14
16
|
const listboxId = useId('fluent-listbox', listboxSlot === null || listboxSlot === void 0 ? void 0 : listboxSlot.id);
|
|
17
|
+
const mergedListboxRef = useMergedRefs(listboxSlot === null || listboxSlot === void 0 ? void 0 : listboxSlot.ref, listboxRef);
|
|
15
18
|
const listbox = listboxSlot && {
|
|
16
19
|
id: listboxId,
|
|
17
20
|
multiselect,
|
|
18
21
|
tabIndex: undefined,
|
|
19
|
-
...listboxSlot
|
|
22
|
+
...listboxSlot,
|
|
23
|
+
ref: mergedListboxRef
|
|
20
24
|
};
|
|
21
25
|
// resolve trigger shorthand props
|
|
22
26
|
const trigger = {
|
|
@@ -40,8 +44,17 @@ import { getDropdownActionFromKey, getIndexFromAction } from '../utils/dropdownK
|
|
|
40
44
|
const listboxOnMouseOver = useEventCallback(mergeCallbacks((event)=>{
|
|
41
45
|
setFocusVisible(false);
|
|
42
46
|
}, listbox === null || listbox === void 0 ? void 0 : listbox.onMouseOver));
|
|
47
|
+
const { targetDocument } = useFluent_unstable();
|
|
48
|
+
const documentOnMouseUp = useEventCallback((ev)=>{
|
|
49
|
+
var _listboxRef_current;
|
|
50
|
+
if (!((_listboxRef_current = listboxRef.current) === null || _listboxRef_current === void 0 ? void 0 : _listboxRef_current.contains(ev.target))) {
|
|
51
|
+
setOpen(ev, false);
|
|
52
|
+
}
|
|
53
|
+
targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.removeEventListener('mouseup', documentOnMouseUp);
|
|
54
|
+
});
|
|
43
55
|
const listboxOnMouseDown = useEventCallback(mergeCallbacks((event)=>{
|
|
44
56
|
ignoreNextBlur.current = true;
|
|
57
|
+
targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.addEventListener('mouseup', documentOnMouseUp);
|
|
45
58
|
}, listbox === null || listbox === void 0 ? void 0 : listbox.onMouseDown));
|
|
46
59
|
// listbox is nullable, only add event handlers if it exists
|
|
47
60
|
if (listbox) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useTriggerListboxSlots.ts"],"sourcesContent":["import * as React from 'react';\nimport { mergeCallbacks, useId, useEventCallback, useMergedRefs } from '@fluentui/react-utilities';\nimport type { ExtractSlotProps, Slot } from '@fluentui/react-utilities';\nimport { getDropdownActionFromKey, getIndexFromAction } from '../utils/dropdownKeyActions';\nimport { Listbox } from '../components/Listbox/Listbox';\nimport type { ComboboxBaseProps, ComboboxBaseState } from './ComboboxBase.types';\n\nexport function useTriggerListboxSlots(\n props: ComboboxBaseProps,\n state: ComboboxBaseState,\n ref: React.Ref<HTMLButtonElement>,\n triggerSlot?: ExtractSlotProps<Slot<'button'>>,\n listboxSlot?: ExtractSlotProps<Slot<typeof Listbox>>,\n): [trigger: ExtractSlotProps<Slot<'button'>>, listbox?: ExtractSlotProps<Slot<typeof Listbox>>];\nexport function useTriggerListboxSlots(\n props: ComboboxBaseProps,\n state: ComboboxBaseState,\n ref: React.Ref<HTMLInputElement>,\n triggerSlot?: ExtractSlotProps<Slot<'input'>>,\n listboxSlot?: ExtractSlotProps<Slot<typeof Listbox>>,\n): [trigger: ExtractSlotProps<Slot<'input'>>, listbox?: ExtractSlotProps<Slot<typeof Listbox>>];\n\n/*\n * useTriggerListboxSlots returns a tuple of trigger/listbox shorthand,\n * with the semantics and event handlers needed for the Combobox and Dropdown components.\n * The element type of the ref should always match the element type used in the trigger shorthand.\n */\nexport function useTriggerListboxSlots(\n props: ComboboxBaseProps,\n state: ComboboxBaseState,\n ref: React.Ref<HTMLButtonElement | HTMLInputElement>,\n triggerSlot?: ExtractSlotProps<Slot<'input'>> | ExtractSlotProps<Slot<'button'>>,\n listboxSlot?: ExtractSlotProps<Slot<typeof Listbox>>,\n): [\n trigger: ExtractSlotProps<Slot<'input'>> | ExtractSlotProps<Slot<'button'>>,\n listbox?: ExtractSlotProps<Slot<typeof Listbox>>,\n] {\n const { multiselect } = props;\n const {\n activeOption,\n getCount,\n getIndexOfId,\n getOptionAtIndex,\n ignoreNextBlur,\n open,\n selectOption,\n setActiveOption,\n setFocusVisible,\n setHasFocus,\n setOpen,\n } = state;\n\n // handle trigger focus/blur\n const triggerRef: typeof ref = React.useRef(null);\n\n // resolve listbox shorthand props\n const listboxId = useId('fluent-listbox', listboxSlot?.id);\n const listbox: typeof listboxSlot = listboxSlot && {\n id: listboxId,\n multiselect,\n tabIndex: undefined,\n ...listboxSlot,\n };\n\n // resolve trigger shorthand props\n const trigger: typeof triggerSlot = {\n 'aria-expanded': open,\n 'aria-activedescendant': open ? activeOption?.id : undefined,\n role: 'combobox',\n ...triggerSlot,\n // explicitly type the ref as an intersection here to prevent type errors\n // since the `children` prop has mutually incompatible types between input/button\n // functionally both ref and triggerRef will always be the same element type\n ref: useMergedRefs(ref, triggerSlot?.ref, triggerRef) as React.Ref<HTMLButtonElement & HTMLInputElement>,\n };\n\n /*\n * Handle focus when clicking the listbox popup:\n * 1. Move focus back to the button/input when the listbox is clicked (otherwise it goes to body)\n * 2. Do not close the listbox on button/input blur when clicking into the listbox\n */\n const listboxOnClick = useEventCallback(\n mergeCallbacks((event: React.MouseEvent<HTMLDivElement>) => {\n triggerRef.current?.focus();\n }, listbox?.onClick),\n );\n\n const listboxOnMouseOver = useEventCallback(\n mergeCallbacks((event: React.MouseEvent<HTMLDivElement>) => {\n setFocusVisible(false);\n }, listbox?.onMouseOver),\n );\n\n const listboxOnMouseDown = useEventCallback(\n mergeCallbacks((event: React.MouseEvent<HTMLDivElement>) => {\n ignoreNextBlur.current = true;\n }, listbox?.onMouseDown),\n );\n\n // listbox is nullable, only add event handlers if it exists\n if (listbox) {\n listbox.onClick = listboxOnClick;\n listbox.onMouseOver = listboxOnMouseOver;\n listbox.onMouseDown = listboxOnMouseDown;\n }\n\n // the trigger should open/close the popup on click or blur\n trigger.onBlur = mergeCallbacks((event: React.FocusEvent<HTMLButtonElement> & React.FocusEvent<HTMLInputElement>) => {\n if (!ignoreNextBlur.current) {\n setOpen(event, false);\n }\n\n ignoreNextBlur.current = false;\n\n setHasFocus(false);\n }, trigger.onBlur);\n\n trigger.onClick = mergeCallbacks(\n (event: React.MouseEvent<HTMLButtonElement> & React.MouseEvent<HTMLInputElement>) => {\n setOpen(event, !open);\n },\n trigger.onClick,\n );\n\n trigger.onFocus = mergeCallbacks(\n (event: React.FocusEvent<HTMLButtonElement> & React.FocusEvent<HTMLInputElement>) => {\n setHasFocus(true);\n },\n trigger.onFocus,\n );\n\n // handle combobox keyboard interaction\n trigger.onKeyDown = mergeCallbacks(\n (event: React.KeyboardEvent<HTMLButtonElement> & React.KeyboardEvent<HTMLInputElement>) => {\n const action = getDropdownActionFromKey(event, { open, multiselect });\n const maxIndex = getCount() - 1;\n const activeIndex = activeOption ? getIndexOfId(activeOption.id) : -1;\n let newIndex = activeIndex;\n\n switch (action) {\n case 'Open':\n event.preventDefault();\n setFocusVisible(true);\n setOpen(event, true);\n break;\n case 'Close':\n // stop propagation for escape key to avoid dismissing any parent popups\n event.stopPropagation();\n event.preventDefault();\n setOpen(event, false);\n break;\n case 'CloseSelect':\n !multiselect && !activeOption?.disabled && setOpen(event, false);\n // fallthrough\n case 'Select':\n activeOption && selectOption(event, activeOption);\n event.preventDefault();\n break;\n case 'Tab':\n !multiselect && activeOption && selectOption(event, activeOption);\n break;\n default:\n newIndex = getIndexFromAction(action, activeIndex, maxIndex);\n }\n if (newIndex !== activeIndex) {\n // prevent default page scroll/keyboard action if the index changed\n event.preventDefault();\n setActiveOption(getOptionAtIndex(newIndex));\n setFocusVisible(true);\n }\n },\n trigger.onKeyDown,\n );\n\n trigger.onMouseOver = mergeCallbacks(\n (event: React.MouseEvent<HTMLButtonElement> & React.MouseEvent<HTMLInputElement>) => {\n setFocusVisible(false);\n },\n trigger.onMouseOver,\n );\n\n return [trigger, listbox];\n}\n"],"names":["React","mergeCallbacks","useId","useEventCallback","useMergedRefs","getDropdownActionFromKey","getIndexFromAction","useTriggerListboxSlots","props","state","ref","triggerSlot","listboxSlot","multiselect","activeOption","getCount","getIndexOfId","getOptionAtIndex","ignoreNextBlur","open","selectOption","setActiveOption","setFocusVisible","setHasFocus","setOpen","triggerRef","useRef","listboxId","id","listbox","tabIndex","undefined","trigger","role","listboxOnClick","event","current","focus","onClick","listboxOnMouseOver","onMouseOver","listboxOnMouseDown","onMouseDown","onBlur","onFocus","onKeyDown","action","maxIndex","activeIndex","newIndex","preventDefault","stopPropagation","disabled"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,cAAc,EAAEC,KAAK,EAAEC,gBAAgB,EAAEC,aAAa,QAAQ,4BAA4B;AAEnG,SAASC,wBAAwB,EAAEC,kBAAkB,QAAQ,8BAA8B;AAmB3F;;;;CAIC,GACD,OAAO,SAASC,uBACdC,KAAwB,EACxBC,KAAwB,EACxBC,GAAoD,EACpDC,WAAgF,EAChFC,WAAoD;IAKpD,MAAM,EAAEC,WAAW,EAAE,GAAGL;IACxB,MAAM,EACJM,YAAY,EACZC,QAAQ,EACRC,YAAY,EACZC,gBAAgB,EAChBC,cAAc,EACdC,IAAI,EACJC,YAAY,EACZC,eAAe,EACfC,eAAe,EACfC,WAAW,EACXC,OAAO,EACR,GAAGf;IAEJ,4BAA4B;IAC5B,MAAMgB,aAAyBzB,MAAM0B,MAAM,CAAC;IAE5C,kCAAkC;IAClC,MAAMC,YAAYzB,MAAM,kBAAkBU,wBAAAA,kCAAAA,YAAagB,EAAE;IACzD,MAAMC,UAA8BjB,eAAe;QACjDgB,IAAID;QACJd;QACAiB,UAAUC;QACV,GAAGnB,WAAW;IAChB;IAEA,kCAAkC;IAClC,MAAMoB,UAA8B;QAClC,iBAAiBb;QACjB,yBAAyBA,OAAOL,yBAAAA,mCAAAA,aAAcc,EAAE,GAAGG;QACnDE,MAAM;QACN,GAAGtB,WAAW;QACd,yEAAyE;QACzE,iFAAiF;QACjF,4EAA4E;QAC5ED,KAAKN,cAAcM,KAAKC,wBAAAA,kCAAAA,YAAaD,GAAG,EAAEe;IAC5C;IAEA;;;;GAIC,GACD,MAAMS,iBAAiB/B,i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Ac;gBACpB1B,QAAQW,OAAO;gBACf;YACF,KAAK;gBACH,CAACtB,eAAe,EAACC,yBAAAA,mCAAAA,aAAcsC,QAAQ,KAAI5B,QAAQW,OAAO;YAC5D,cAAc;YACd,KAAK;gBACHrB,gBAAgBM,aAAae,OAAOrB;gBACpCqB,MAAMe,cAAc;gBACpB;YACF,KAAK;gBACH,CAACrC,eAAeC,gBAAgBM,aAAae,OAAOrB;gBACpD;YACF;gBACEmC,WAAW3C,mBAAmBwC,QAAQE,aAAaD;QACvD;QACA,IAAIE,aAAaD,aAAa;YAC5B,mEAAmE;YACnEb,MAAMe,cAAc;YACpB7B,gBAAgBJ,iBAAiBgC;YACjC3B,gBAAgB;QAClB;IACF,GACAU,QAAQa,SAAS;IAGnBb,QAAQQ,WAAW,GAAGvC,eACpB,CAACkC;QACCb,gBAAgB;IAClB,GACAU,QAAQQ,WAAW;IAGrB,OAAO;QAACR;QAASH;KAAQ;AAC3B"}
|
|
1
|
+
{"version":3,"sources":["useTriggerListboxSlots.ts"],"sourcesContent":["import * as React from 'react';\nimport { useFluent_unstable } from '@fluentui/react-shared-contexts';\nimport { mergeCallbacks, useId, useEventCallback, useMergedRefs } from '@fluentui/react-utilities';\nimport type { ExtractSlotProps, Slot } from '@fluentui/react-utilities';\nimport { getDropdownActionFromKey, getIndexFromAction } from '../utils/dropdownKeyActions';\nimport { Listbox } from '../components/Listbox/Listbox';\nimport type { ComboboxBaseProps, ComboboxBaseState } from './ComboboxBase.types';\n\nexport function useTriggerListboxSlots(\n props: ComboboxBaseProps,\n state: ComboboxBaseState,\n ref: React.Ref<HTMLButtonElement>,\n triggerSlot?: ExtractSlotProps<Slot<'button'>>,\n listboxSlot?: ExtractSlotProps<Slot<typeof Listbox>>,\n): [trigger: ExtractSlotProps<Slot<'button'>>, listbox?: ExtractSlotProps<Slot<typeof Listbox>>];\nexport function useTriggerListboxSlots(\n props: ComboboxBaseProps,\n state: ComboboxBaseState,\n ref: React.Ref<HTMLInputElement>,\n triggerSlot?: ExtractSlotProps<Slot<'input'>>,\n listboxSlot?: ExtractSlotProps<Slot<typeof Listbox>>,\n): [trigger: ExtractSlotProps<Slot<'input'>>, listbox?: ExtractSlotProps<Slot<typeof Listbox>>];\n\n/*\n * useTriggerListboxSlots returns a tuple of trigger/listbox shorthand,\n * with the semantics and event handlers needed for the Combobox and Dropdown components.\n * The element type of the ref should always match the element type used in the trigger shorthand.\n */\nexport function useTriggerListboxSlots(\n props: ComboboxBaseProps,\n state: ComboboxBaseState,\n ref: React.Ref<HTMLButtonElement | HTMLInputElement>,\n triggerSlot?: ExtractSlotProps<Slot<'input'>> | ExtractSlotProps<Slot<'button'>>,\n listboxSlot?: ExtractSlotProps<Slot<typeof Listbox>>,\n): [\n trigger: ExtractSlotProps<Slot<'input'>> | ExtractSlotProps<Slot<'button'>>,\n listbox?: ExtractSlotProps<Slot<typeof Listbox>>,\n] {\n const { multiselect } = props;\n const {\n activeOption,\n getCount,\n getIndexOfId,\n getOptionAtIndex,\n ignoreNextBlur,\n open,\n selectOption,\n setActiveOption,\n setFocusVisible,\n setHasFocus,\n setOpen,\n } = state;\n\n // handle trigger focus/blur\n const triggerRef: typeof ref = React.useRef(null);\n const listboxRef: NonNullable<typeof listboxSlot>['ref'] = React.useRef(null);\n\n // resolve listbox shorthand props\n const listboxId = useId('fluent-listbox', listboxSlot?.id);\n const mergedListboxRef = useMergedRefs(listboxSlot?.ref, listboxRef);\n const listbox: typeof listboxSlot = listboxSlot && {\n id: listboxId,\n multiselect,\n tabIndex: undefined,\n ...listboxSlot,\n ref: mergedListboxRef,\n };\n\n // resolve trigger shorthand props\n const trigger: typeof triggerSlot = {\n 'aria-expanded': open,\n 'aria-activedescendant': open ? activeOption?.id : undefined,\n role: 'combobox',\n ...triggerSlot,\n // explicitly type the ref as an intersection here to prevent type errors\n // since the `children` prop has mutually incompatible types between input/button\n // functionally both ref and triggerRef will always be the same element type\n ref: useMergedRefs(ref, triggerSlot?.ref, triggerRef) as React.Ref<HTMLButtonElement & HTMLInputElement>,\n };\n\n /*\n * Handle focus when clicking the listbox popup:\n * 1. Move focus back to the button/input when the listbox is clicked (otherwise it goes to body)\n * 2. Do not close the listbox on button/input blur when clicking into the listbox\n */\n const listboxOnClick = useEventCallback(\n mergeCallbacks((event: React.MouseEvent<HTMLDivElement>) => {\n triggerRef.current?.focus();\n }, listbox?.onClick),\n );\n\n const listboxOnMouseOver = useEventCallback(\n mergeCallbacks((event: React.MouseEvent<HTMLDivElement>) => {\n setFocusVisible(false);\n }, listbox?.onMouseOver),\n );\n\n const { targetDocument } = useFluent_unstable();\n const documentOnMouseUp = useEventCallback((ev: MouseEvent) => {\n if (!listboxRef.current?.contains(ev.target as HTMLElement)) {\n setOpen(ev as unknown as React.MouseEvent<HTMLElement>, false);\n }\n targetDocument?.removeEventListener('mouseup', documentOnMouseUp);\n });\n\n const listboxOnMouseDown = useEventCallback(\n mergeCallbacks((event: React.MouseEvent<HTMLDivElement>) => {\n ignoreNextBlur.current = true;\n targetDocument?.addEventListener('mouseup', documentOnMouseUp);\n }, listbox?.onMouseDown),\n );\n\n // listbox is nullable, only add event handlers if it exists\n if (listbox) {\n listbox.onClick = listboxOnClick;\n listbox.onMouseOver = listboxOnMouseOver;\n listbox.onMouseDown = listboxOnMouseDown;\n }\n\n // the trigger should open/close the popup on click or blur\n trigger.onBlur = mergeCallbacks((event: React.FocusEvent<HTMLButtonElement> & React.FocusEvent<HTMLInputElement>) => {\n if (!ignoreNextBlur.current) {\n setOpen(event, false);\n }\n\n ignoreNextBlur.current = false;\n\n setHasFocus(false);\n }, trigger.onBlur);\n\n trigger.onClick = mergeCallbacks(\n (event: React.MouseEvent<HTMLButtonElement> & React.MouseEvent<HTMLInputElement>) => {\n setOpen(event, !open);\n },\n trigger.onClick,\n );\n\n trigger.onFocus = mergeCallbacks(\n (event: React.FocusEvent<HTMLButtonElement> & React.FocusEvent<HTMLInputElement>) => {\n setHasFocus(true);\n },\n trigger.onFocus,\n );\n\n // handle combobox keyboard interaction\n trigger.onKeyDown = mergeCallbacks(\n (event: React.KeyboardEvent<HTMLButtonElement> & React.KeyboardEvent<HTMLInputElement>) => {\n const action = getDropdownActionFromKey(event, { open, multiselect });\n const maxIndex = getCount() - 1;\n const activeIndex = activeOption ? getIndexOfId(activeOption.id) : -1;\n let newIndex = activeIndex;\n\n switch (action) {\n case 'Open':\n event.preventDefault();\n setFocusVisible(true);\n setOpen(event, true);\n break;\n case 'Close':\n // stop propagation for escape key to avoid dismissing any parent popups\n event.stopPropagation();\n event.preventDefault();\n setOpen(event, false);\n break;\n case 'CloseSelect':\n !multiselect && !activeOption?.disabled && setOpen(event, false);\n // fallthrough\n case 'Select':\n activeOption && selectOption(event, activeOption);\n event.preventDefault();\n break;\n case 'Tab':\n !multiselect && activeOption && selectOption(event, activeOption);\n break;\n default:\n newIndex = getIndexFromAction(action, activeIndex, maxIndex);\n }\n if (newIndex !== activeIndex) {\n // prevent default page scroll/keyboard action if the index changed\n event.preventDefault();\n setActiveOption(getOptionAtIndex(newIndex));\n setFocusVisible(true);\n }\n },\n trigger.onKeyDown,\n );\n\n trigger.onMouseOver = mergeCallbacks(\n (event: React.MouseEvent<HTMLButtonElement> & React.MouseEvent<HTMLInputElement>) => {\n setFocusVisible(false);\n },\n trigger.onMouseOver,\n );\n\n return [trigger, listbox];\n}\n"],"names":["React","useFluent_unstable","mergeCallbacks","useId","useEventCallback","useMergedRefs","getDropdownActionFromKey","getIndexFromAction","useTriggerListboxSlots","props","state","ref","triggerSlot","listboxSlot","multiselect","activeOption","getCount","getIndexOfId","getOptionAtIndex","ignoreNextBlur","open","selectOption","setActiveOption","setFocusVisible","setHasFocus","setOpen","triggerRef","useRef","listboxRef","listboxId","id","mergedListboxRef","listbox","tabIndex","undefined","trigger","role","listboxOnClick","event","current","focus","onClick","listboxOnMouseOver","onMouseOver","targetDocument","documentOnMouseUp","ev","contains","target","removeEventListener","listboxOnMouseDown","addEventListener","onMouseDown","onBlur","onFocus","onKeyDown","action","max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QACC,MAAMkB,SAASlD,yBAAyBgC,OAAO;YAAElB;YAAMN;QAAY;QACnE,MAAM2C,WAAWzC,aAAa;QAC9B,MAAM0C,cAAc3C,eAAeE,aAAaF,aAAae,EAAE,IAAI,CAAC;QACpE,IAAI6B,WAAWD;QAEf,OAAQF;YACN,KAAK;gBACHlB,MAAMsB,cAAc;gBACpBrC,gBAAgB;gBAChBE,QAAQa,OAAO;gBACf;YACF,KAAK;gBACH,wEAAwE;gBACxEA,MAAMuB,eAAe;gBACrBvB,MAAMsB,cAAc;gBACpBnC,QAAQa,OAAO;gBACf;YACF,KAAK;gBACH,CAACxB,eAAe,EAACC,yBAAAA,mCAAAA,aAAc+C,QAAQ,KAAIrC,QAAQa,OAAO;YAC5D,cAAc;YACd,KAAK;gBACHvB,gBAAgBM,aAAaiB,OAAOvB;gBACpCuB,MAAMsB,cAAc;gBACpB;YACF,KAAK;gBACH,CAAC9C,eAAeC,gBAAgBM,aAAaiB,OAAOvB;gBACpD;YACF;gBACE4C,WAAWpD,mBAAmBiD,QAAQE,aAAaD;QACvD;QACA,IAAIE,aAAaD,aAAa;YAC5B,mEAAmE;YACnEpB,MAAMsB,cAAc;YACpBtC,gBAAgBJ,iBAAiByC;YACjCpC,gBAAgB;QAClB;IACF,GACAY,QAAQoB,SAAS;IAGnBpB,QAAQQ,WAAW,GAAGzC,eACpB,CAACoC;QACCf,gBAAgB;IAClB,GACAY,QAAQQ,WAAW;IAGrB,OAAO;QAACR;QAASH;KAAQ;AAC3B"}
|
|
@@ -10,6 +10,7 @@ Object.defineProperty(exports, "useTriggerListboxSlots", {
|
|
|
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 _reactsharedcontexts = require("@fluentui/react-shared-contexts");
|
|
13
14
|
const _reactutilities = require("@fluentui/react-utilities");
|
|
14
15
|
const _dropdownKeyActions = require("../utils/dropdownKeyActions");
|
|
15
16
|
function useTriggerListboxSlots(props, state, ref, triggerSlot, listboxSlot) {
|
|
@@ -17,13 +18,16 @@ function useTriggerListboxSlots(props, state, ref, triggerSlot, listboxSlot) {
|
|
|
17
18
|
const { activeOption, getCount, getIndexOfId, getOptionAtIndex, ignoreNextBlur, open, selectOption, setActiveOption, setFocusVisible, setHasFocus, setOpen } = state;
|
|
18
19
|
// handle trigger focus/blur
|
|
19
20
|
const triggerRef = _react.useRef(null);
|
|
21
|
+
const listboxRef = _react.useRef(null);
|
|
20
22
|
// resolve listbox shorthand props
|
|
21
23
|
const listboxId = (0, _reactutilities.useId)('fluent-listbox', listboxSlot === null || listboxSlot === void 0 ? void 0 : listboxSlot.id);
|
|
24
|
+
const mergedListboxRef = (0, _reactutilities.useMergedRefs)(listboxSlot === null || listboxSlot === void 0 ? void 0 : listboxSlot.ref, listboxRef);
|
|
22
25
|
const listbox = listboxSlot && {
|
|
23
26
|
id: listboxId,
|
|
24
27
|
multiselect,
|
|
25
28
|
tabIndex: undefined,
|
|
26
|
-
...listboxSlot
|
|
29
|
+
...listboxSlot,
|
|
30
|
+
ref: mergedListboxRef
|
|
27
31
|
};
|
|
28
32
|
// resolve trigger shorthand props
|
|
29
33
|
const trigger = {
|
|
@@ -47,8 +51,17 @@ function useTriggerListboxSlots(props, state, ref, triggerSlot, listboxSlot) {
|
|
|
47
51
|
const listboxOnMouseOver = (0, _reactutilities.useEventCallback)((0, _reactutilities.mergeCallbacks)((event)=>{
|
|
48
52
|
setFocusVisible(false);
|
|
49
53
|
}, listbox === null || listbox === void 0 ? void 0 : listbox.onMouseOver));
|
|
54
|
+
const { targetDocument } = (0, _reactsharedcontexts.useFluent_unstable)();
|
|
55
|
+
const documentOnMouseUp = (0, _reactutilities.useEventCallback)((ev)=>{
|
|
56
|
+
var _listboxRef_current;
|
|
57
|
+
if (!((_listboxRef_current = listboxRef.current) === null || _listboxRef_current === void 0 ? void 0 : _listboxRef_current.contains(ev.target))) {
|
|
58
|
+
setOpen(ev, false);
|
|
59
|
+
}
|
|
60
|
+
targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.removeEventListener('mouseup', documentOnMouseUp);
|
|
61
|
+
});
|
|
50
62
|
const listboxOnMouseDown = (0, _reactutilities.useEventCallback)((0, _reactutilities.mergeCallbacks)((event)=>{
|
|
51
63
|
ignoreNextBlur.current = true;
|
|
64
|
+
targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.addEventListener('mouseup', documentOnMouseUp);
|
|
52
65
|
}, listbox === null || listbox === void 0 ? void 0 : listbox.onMouseDown));
|
|
53
66
|
// listbox is nullable, only add event handlers if it exists
|
|
54
67
|
if (listbox) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useTriggerListboxSlots.js"],"sourcesContent":["import * as React from 'react';\nimport { mergeCallbacks, useId, useEventCallback, useMergedRefs } from '@fluentui/react-utilities';\nimport { getDropdownActionFromKey, getIndexFromAction } from '../utils/dropdownKeyActions';\n/*\n * useTriggerListboxSlots returns a tuple of trigger/listbox shorthand,\n * with the semantics and event handlers needed for the Combobox and Dropdown components.\n * The element type of the ref should always match the element type used in the trigger shorthand.\n */ export function useTriggerListboxSlots(props, state, ref, triggerSlot, listboxSlot) {\n const { multiselect } = props;\n const { activeOption, getCount, getIndexOfId, getOptionAtIndex, ignoreNextBlur, open, selectOption, setActiveOption, setFocusVisible, setHasFocus, setOpen } = state;\n // handle trigger focus/blur\n const triggerRef = React.useRef(null);\n // resolve listbox shorthand props\n const listboxId = useId('fluent-listbox', listboxSlot === null || listboxSlot === void 0 ? void 0 : listboxSlot.id);\n const listbox = listboxSlot && {\n id: listboxId,\n multiselect,\n tabIndex: undefined,\n ...listboxSlot\n };\n // resolve trigger shorthand props\n const trigger = {\n 'aria-expanded': open,\n 'aria-activedescendant': open ? activeOption === null || activeOption === void 0 ? void 0 : activeOption.id : undefined,\n role: 'combobox',\n ...triggerSlot,\n // explicitly type the ref as an intersection here to prevent type errors\n // since the `children` prop has mutually incompatible types between input/button\n // functionally both ref and triggerRef will always be the same element type\n ref: useMergedRefs(ref, triggerSlot === null || triggerSlot === void 0 ? void 0 : triggerSlot.ref, triggerRef)\n };\n /*\n * Handle focus when clicking the listbox popup:\n * 1. Move focus back to the button/input when the listbox is clicked (otherwise it goes to body)\n * 2. Do not close the listbox on button/input blur when clicking into the listbox\n */ const listboxOnClick = useEventCallback(mergeCallbacks((event)=>{\n var _triggerRef_current;\n (_triggerRef_current = triggerRef.current) === null || _triggerRef_current === void 0 ? void 0 : _triggerRef_current.focus();\n }, listbox === null || listbox === void 0 ? void 0 : listbox.onClick));\n const listboxOnMouseOver = useEventCallback(mergeCallbacks((event)=>{\n setFocusVisible(false);\n }, listbox === null || listbox === void 0 ? void 0 : listbox.onMouseOver));\n const listboxOnMouseDown = useEventCallback(mergeCallbacks((event)=>{\n ignoreNextBlur.current = true;\n }, listbox === null || listbox === void 0 ? void 0 : listbox.onMouseDown));\n // listbox is nullable, only add event handlers if it exists\n if (listbox) {\n listbox.onClick = listboxOnClick;\n listbox.onMouseOver = listboxOnMouseOver;\n listbox.onMouseDown = listboxOnMouseDown;\n }\n // the trigger should open/close the popup on click or blur\n trigger.onBlur = mergeCallbacks((event)=>{\n if (!ignoreNextBlur.current) {\n setOpen(event, false);\n }\n ignoreNextBlur.current = false;\n setHasFocus(false);\n }, trigger.onBlur);\n trigger.onClick = mergeCallbacks((event)=>{\n setOpen(event, !open);\n }, trigger.onClick);\n trigger.onFocus = mergeCallbacks((event)=>{\n setHasFocus(true);\n }, trigger.onFocus);\n // handle combobox keyboard interaction\n trigger.onKeyDown = mergeCallbacks((event)=>{\n const action = getDropdownActionFromKey(event, {\n open,\n multiselect\n });\n const maxIndex = getCount() - 1;\n const activeIndex = activeOption ? getIndexOfId(activeOption.id) : -1;\n let newIndex = activeIndex;\n switch(action){\n case 'Open':\n event.preventDefault();\n setFocusVisible(true);\n setOpen(event, true);\n break;\n case 'Close':\n // stop propagation for escape key to avoid dismissing any parent popups\n event.stopPropagation();\n event.preventDefault();\n setOpen(event, false);\n break;\n case 'CloseSelect':\n !multiselect && !(activeOption === null || activeOption === void 0 ? void 0 : activeOption.disabled) && setOpen(event, false);\n // fallthrough\n case 'Select':\n activeOption && selectOption(event, activeOption);\n event.preventDefault();\n break;\n case 'Tab':\n !multiselect && activeOption && selectOption(event, activeOption);\n break;\n default:\n newIndex = getIndexFromAction(action, activeIndex, maxIndex);\n }\n if (newIndex !== activeIndex) {\n // prevent default page scroll/keyboard action if the index changed\n event.preventDefault();\n setActiveOption(getOptionAtIndex(newIndex));\n setFocusVisible(true);\n }\n }, trigger.onKeyDown);\n trigger.onMouseOver = mergeCallbacks((event)=>{\n setFocusVisible(false);\n }, trigger.onMouseOver);\n return [\n trigger,\n listbox\n ];\n}\n"],"names":["useTriggerListboxSlots","props","state","ref","triggerSlot","listboxSlot","multiselect","activeOption","getCount","getIndexOfId","getOptionAtIndex","ignoreNextBlur","open","selectOption","setActiveOption","setFocusVisible","setHasFocus","setOpen","triggerRef","React","useRef","listboxId","useId","id","listbox","tabIndex","undefined","trigger","role","useMergedRefs","listboxOnClick","useEventCallback","mergeCallbacks","event","_triggerRef_current","current","focus","onClick","listboxOnMouseOver","onMouseOver","listboxOnMouseDown","onMouseDown","onBlur","onFocus","onKeyDown","action","getDropdownActionFromKey","maxIndex","activeIndex","newIndex","preventDefault","stopPropagation","disabled","getIndexFromAction"],"mappings":";;;;+BAOoBA;;;eAAAA;;;;iEAPG;gCACgD;oCACV;AAKlD,SAASA,uBAAuBC,KAAK,EAAEC,KAAK,EAAEC,GAAG,EAAEC,WAAW,EAAEC,WAAW;IAClF,MAAM,EAAEC,WAAW,EAAE,GAAGL;IACxB,MAAM,EAAEM,YAAY,EAAEC,QAAQ,EAAEC,YAAY,EAAEC,gBAAgB,EAAEC,cAAc,EAAEC,IAAI,EAAEC,YAAY,EAAEC,eAAe,EAAEC,eAAe,EAAEC,WAAW,EAAEC,OAAO,EAAE,GA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gBACD,CAAC5C,eAAeC,gBAAgBM,aAAaoB,OAAO1B;gBACpD;YACJ;gBACI0C,WAAWI,IAAAA,sCAAkB,EAACR,QAAQG,aAAaD;QAC3D;QACA,IAAIE,aAAaD,aAAa;YAC1B,mEAAmE;YACnEf,MAAMiB,cAAc;YACpBpC,gBAAgBJ,iBAAiBuC;YACjClC,gBAAgB;QACpB;IACJ,GAAGY,QAAQiB,SAAS;IACpBjB,QAAQY,WAAW,GAAGP,IAAAA,8BAAc,EAAC,CAACC;QAClClB,gBAAgB;IACpB,GAAGY,QAAQY,WAAW;IACtB,OAAO;QACHZ;QACAH;KACH;AACL"}
|
|
1
|
+
{"version":3,"sources":["useTriggerListboxSlots.js"],"sourcesContent":["import * as React from 'react';\nimport { useFluent_unstable } from '@fluentui/react-shared-contexts';\nimport { mergeCallbacks, useId, useEventCallback, useMergedRefs } from '@fluentui/react-utilities';\nimport { getDropdownActionFromKey, getIndexFromAction } from '../utils/dropdownKeyActions';\n/*\n * useTriggerListboxSlots returns a tuple of trigger/listbox shorthand,\n * with the semantics and event handlers needed for the Combobox and Dropdown components.\n * The element type of the ref should always match the element type used in the trigger shorthand.\n */ export function useTriggerListboxSlots(props, state, ref, triggerSlot, listboxSlot) {\n const { multiselect } = props;\n const { activeOption, getCount, getIndexOfId, getOptionAtIndex, ignoreNextBlur, open, selectOption, setActiveOption, setFocusVisible, setHasFocus, setOpen } = state;\n // handle trigger focus/blur\n const triggerRef = React.useRef(null);\n const listboxRef = React.useRef(null);\n // resolve listbox shorthand props\n const listboxId = useId('fluent-listbox', listboxSlot === null || listboxSlot === void 0 ? void 0 : listboxSlot.id);\n const mergedListboxRef = useMergedRefs(listboxSlot === null || listboxSlot === void 0 ? void 0 : listboxSlot.ref, listboxRef);\n const listbox = listboxSlot && {\n id: listboxId,\n multiselect,\n tabIndex: undefined,\n ...listboxSlot,\n ref: mergedListboxRef\n };\n // resolve trigger shorthand props\n const trigger = {\n 'aria-expanded': open,\n 'aria-activedescendant': open ? activeOption === null || activeOption === void 0 ? void 0 : activeOption.id : undefined,\n role: 'combobox',\n ...triggerSlot,\n // explicitly type the ref as an intersection here to prevent type errors\n // since the `children` prop has mutually incompatible types between input/button\n // functionally both ref and triggerRef will always be the same element type\n ref: useMergedRefs(ref, triggerSlot === null || triggerSlot === void 0 ? void 0 : triggerSlot.ref, triggerRef)\n };\n /*\n * Handle focus when clicking the listbox popup:\n * 1. Move focus back to the button/input when the listbox is clicked (otherwise it goes to body)\n * 2. Do not close the listbox on button/input blur when clicking into the listbox\n */ const listboxOnClick = useEventCallback(mergeCallbacks((event)=>{\n var _triggerRef_current;\n (_triggerRef_current = triggerRef.current) === null || _triggerRef_current === void 0 ? void 0 : _triggerRef_current.focus();\n }, listbox === null || listbox === void 0 ? void 0 : listbox.onClick));\n const listboxOnMouseOver = useEventCallback(mergeCallbacks((event)=>{\n setFocusVisible(false);\n }, listbox === null || listbox === void 0 ? void 0 : listbox.onMouseOver));\n const { targetDocument } = useFluent_unstable();\n const documentOnMouseUp = useEventCallback((ev)=>{\n var _listboxRef_current;\n if (!((_listboxRef_current = listboxRef.current) === null || _listboxRef_current === void 0 ? void 0 : _listboxRef_current.contains(ev.target))) {\n setOpen(ev, false);\n }\n targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.removeEventListener('mouseup', documentOnMouseUp);\n });\n const listboxOnMouseDown = useEventCallback(mergeCallbacks((event)=>{\n ignoreNextBlur.current = true;\n targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.addEventListener('mouseup', documentOnMouseUp);\n }, listbox === null || listbox === void 0 ? void 0 : listbox.onMouseDown));\n // listbox is nullable, only add event handlers if it exists\n if (listbox) {\n listbox.onClick = listboxOnClick;\n listbox.onMouseOver = listboxOnMouseOver;\n listbox.onMouseDown = listboxOnMouseDown;\n }\n // the trigger should open/close the popup on click or blur\n trigger.onBlur = mergeCallbacks((event)=>{\n if (!ignoreNextBlur.current) {\n setOpen(event, false);\n }\n ignoreNextBlur.current = false;\n setHasFocus(false);\n }, trigger.onBlur);\n trigger.onClick = mergeCallbacks((event)=>{\n setOpen(event, !open);\n }, trigger.onClick);\n trigger.onFocus = mergeCallbacks((event)=>{\n setHasFocus(true);\n }, trigger.onFocus);\n // handle combobox keyboard interaction\n trigger.onKeyDown = mergeCallbacks((event)=>{\n const action = getDropdownActionFromKey(event, {\n open,\n multiselect\n });\n const maxIndex = getCount() - 1;\n const activeIndex = activeOption ? getIndexOfId(activeOption.id) : -1;\n let newIndex = activeIndex;\n switch(action){\n case 'Open':\n event.preventDefault();\n setFocusVisible(true);\n setOpen(event, true);\n break;\n case 'Close':\n // stop propagation for escape key to avoid dismissing any parent popups\n event.stopPropagation();\n event.preventDefault();\n setOpen(event, false);\n break;\n case 'CloseSelect':\n !multiselect && !(activeOption === null || activeOption === void 0 ? void 0 : activeOption.disabled) && setOpen(event, false);\n // fallthrough\n case 'Select':\n activeOption && selectOption(event, activeOption);\n event.preventDefault();\n break;\n case 'Tab':\n !multiselect && activeOption && selectOption(event, activeOption);\n break;\n default:\n newIndex = getIndexFromAction(action, activeIndex, maxIndex);\n }\n if (newIndex !== activeIndex) {\n // prevent default page scroll/keyboard action if the index changed\n event.preventDefault();\n setActiveOption(getOptionAtIndex(newIndex));\n setFocusVisible(true);\n }\n }, trigger.onKeyDown);\n trigger.onMouseOver = mergeCallbacks((event)=>{\n setFocusVisible(false);\n }, trigger.onMouseOver);\n return [\n trigger,\n listbox\n ];\n}\n"],"names":["useTriggerListboxSlots","props","state","ref","triggerSlot","listboxSlot","multiselect","activeOption","getCount","getIndexOfId","getOptionAtIndex","ignoreNextBlur","open","selectOption","setActiveOption","setFocusVisible","setHasFocus","setOpen","triggerRef","React","useRef","listboxRef","listboxId","useId","id","mergedListboxRef","useMergedRefs","listbox","tabIndex","undefined","trigger","role","listboxOnClick","useEventCallback","mergeCallbacks","event","_triggerRef_current","current","focus","onClick","listboxOnMouseOver","onMouseOver","targetDocument","useFluent_unstable","documentOnMouseUp","ev","_listboxRef_current","contains","target","removeEventListener","listboxOnMouseDown","addEventListener","onMouseDown","onBlur","onFocus","onKeyDown","action","getDropdownActionFromKey","maxIndex","activeIndex","newIndex","preventDefault","stopPropagation","disabled","getIndexFromAction"],"mappings":";;;;+BAQoBA;;;eAAAA;;;;iEARG;qCACY;gCACoC;oCACV;AAKlD,SAASA,uBAAuBC,KAAK,EAAEC,KAAK,EAAEC,GAAG,EAAEC,WAAW,EAAEC,WAAW;IAClF,MAAM,EAAEC,WAAW,EAAE,GAAGL;IACxB,MAAM,EAAEM,YAAY,EAAEC,QAAQ,EAAEC,YAAY,EAAEC,gBAAgB,EAAEC,cAAc,EAAEC,IAAI,EAAEC,YAAY,EAAEC,eAAe,EAAEC,eAAe,EAAEC,WAAW,EAAEC,OAAO,EAAE,GAAGf;IAC/J,4BAA4B;IAC5B,MAAMgB,aAAaC,OAAMC,MAAM,CAAC;IAChC,MAAMC,aAAaF,OAAMC,MAAM,CAAC;IAChC,kCAAkC;IAClC,MAAME,YAAYC,IAAAA,qBAAK,EAAC,kBAAkBlB,gBAAgB,QAAQA,gBAAgB,KAAK,IAAI,KAAK,IAAIA,YAAYmB,EAAE;IAClH,MAAMC,mBAAmBC,IAAAA,6BAAa,EAACrB,gBAAgB,QAAQA,gBAAgB,KAAK,IAAI,KAAK,IAAIA,YAAYF,GAAG,EAAEkB;IAClH,MAAMM,UAAUtB,eAAe;QAC3BmB,IAAIF;QACJhB;QACAsB,UAAUC;QACV,GAAGxB,WAAW;QACdF,KAAKsB;IACT;IACA,kCAAkC;IAClC,MAAMK,UAAU;QACZ,iBAAiBlB;QACjB,yBAAyBA,OAAOL,iBAAiB,QAAQA,iBAAiB,KAAK,IAAI,KAAK,IAAIA,aAAaiB,EAAE,GAAGK;QAC9GE,MAAM;QACN,GAAG3B,WAAW;QACd,yEAAyE;QACzE,iFAAiF;QACjF,4EAA4E;QAC5ED,KAAKuB,IAAAA,6BAAa,EAACvB,KAAKC,gBAAgB,QAAQA,gBAAgB,KAAK,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I,IAAAA,sCAAkB,EAACR,QAAQG,aAAaD;QAC3D;QACA,IAAIE,aAAaD,aAAa;YAC1B,mEAAmE;YACnExB,MAAM0B,cAAc;YACpB/C,gBAAgBJ,iBAAiBkD;YACjC7C,gBAAgB;QACpB;IACJ,GAAGe,QAAQyB,SAAS;IACpBzB,QAAQW,WAAW,GAAGP,IAAAA,8BAAc,EAAC,CAACC;QAClCpB,gBAAgB;IACpB,GAAGe,QAAQW,WAAW;IACtB,OAAO;QACHX;QACAH;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.28",
|
|
4
4
|
"description": "Fluent UI React Combobox component",
|
|
5
5
|
"main": "lib-commonjs/index.js",
|
|
6
6
|
"module": "lib/index.js",
|
|
@@ -35,13 +35,13 @@
|
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@fluentui/keyboard-keys": "^9.0.6",
|
|
37
37
|
"@fluentui/react-context-selector": "^9.1.41",
|
|
38
|
-
"@fluentui/react-field": "^9.1.
|
|
38
|
+
"@fluentui/react-field": "^9.1.40",
|
|
39
39
|
"@fluentui/react-icons": "^2.0.217",
|
|
40
40
|
"@fluentui/react-jsx-runtime": "^9.0.18",
|
|
41
|
-
"@fluentui/react-portal": "^9.3.
|
|
42
|
-
"@fluentui/react-positioning": "^9.9.
|
|
43
|
-
"@fluentui/react-shared-contexts": "^9.11.
|
|
44
|
-
"@fluentui/react-theme": "^9.1.
|
|
41
|
+
"@fluentui/react-portal": "^9.3.27",
|
|
42
|
+
"@fluentui/react-positioning": "^9.9.23",
|
|
43
|
+
"@fluentui/react-shared-contexts": "^9.11.1",
|
|
44
|
+
"@fluentui/react-theme": "^9.1.15",
|
|
45
45
|
"@fluentui/react-utilities": "^9.15.1",
|
|
46
46
|
"@griffel/react": "^1.5.14",
|
|
47
47
|
"@swc/helpers": "^0.5.1"
|