@fluentui/react-combobox 9.7.5 → 9.8.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.
Files changed (78) hide show
  1. package/CHANGELOG.md +26 -5
  2. package/dist/index.d.ts +54 -11
  3. package/lib/components/Combobox/Combobox.types.js.map +1 -1
  4. package/lib/components/Combobox/renderCombobox.js +15 -11
  5. package/lib/components/Combobox/renderCombobox.js.map +1 -1
  6. package/lib/components/Combobox/useCombobox.js +12 -4
  7. package/lib/components/Combobox/useCombobox.js.map +1 -1
  8. package/lib/components/Combobox/useInputTriggerSlot.js +14 -12
  9. package/lib/components/Combobox/useInputTriggerSlot.js.map +1 -1
  10. package/lib/components/Dropdown/Dropdown.types.js.map +1 -1
  11. package/lib/components/Dropdown/renderDropdown.js +19 -15
  12. package/lib/components/Dropdown/renderDropdown.js.map +1 -1
  13. package/lib/components/Dropdown/useButtonTriggerSlot.js +51 -31
  14. package/lib/components/Dropdown/useButtonTriggerSlot.js.map +1 -1
  15. package/lib/components/Dropdown/useDropdown.js +14 -4
  16. package/lib/components/Dropdown/useDropdown.js.map +1 -1
  17. package/lib/components/Listbox/Listbox.types.js.map +1 -1
  18. package/lib/components/Listbox/renderListbox.js +7 -3
  19. package/lib/components/Listbox/renderListbox.js.map +1 -1
  20. package/lib/components/Listbox/useListbox.js +43 -35
  21. package/lib/components/Listbox/useListbox.js.map +1 -1
  22. package/lib/components/Option/Option.types.js.map +1 -1
  23. package/lib/components/Option/useOption.js +7 -11
  24. package/lib/components/Option/useOption.js.map +1 -1
  25. package/lib/components/Option/useOptionStyles.styles.js +27 -28
  26. package/lib/components/Option/useOptionStyles.styles.js.map +1 -1
  27. package/lib/contexts/useComboboxContextValues.js +14 -5
  28. package/lib/contexts/useComboboxContextValues.js.map +1 -1
  29. package/lib/contexts/useListboxContextValues.js +12 -5
  30. package/lib/contexts/useListboxContextValues.js.map +1 -1
  31. package/lib/utils/ComboboxBase.types.js.map +1 -1
  32. package/lib/utils/OptionCollection.types.js.map +1 -1
  33. package/lib/utils/Selection.types.js.map +1 -1
  34. package/lib/utils/dropdownKeyActions.js +0 -21
  35. package/lib/utils/dropdownKeyActions.js.map +1 -1
  36. package/lib/utils/useComboboxBaseState.js +52 -14
  37. package/lib/utils/useComboboxBaseState.js.map +1 -1
  38. package/lib/utils/useOptionCollection.js +18 -45
  39. package/lib/utils/useOptionCollection.js.map +1 -1
  40. package/lib/utils/useTriggerSlot.js +86 -33
  41. package/lib/utils/useTriggerSlot.js.map +1 -1
  42. package/lib-commonjs/components/Combobox/renderCombobox.js +15 -11
  43. package/lib-commonjs/components/Combobox/renderCombobox.js.map +1 -1
  44. package/lib-commonjs/components/Combobox/useCombobox.js +12 -4
  45. package/lib-commonjs/components/Combobox/useCombobox.js.map +1 -1
  46. package/lib-commonjs/components/Combobox/useInputTriggerSlot.js +14 -12
  47. package/lib-commonjs/components/Combobox/useInputTriggerSlot.js.map +1 -1
  48. package/lib-commonjs/components/Dropdown/renderDropdown.js +19 -15
  49. package/lib-commonjs/components/Dropdown/renderDropdown.js.map +1 -1
  50. package/lib-commonjs/components/Dropdown/useButtonTriggerSlot.js +51 -31
  51. package/lib-commonjs/components/Dropdown/useButtonTriggerSlot.js.map +1 -1
  52. package/lib-commonjs/components/Dropdown/useDropdown.js +14 -4
  53. package/lib-commonjs/components/Dropdown/useDropdown.js.map +1 -1
  54. package/lib-commonjs/components/Listbox/renderListbox.js +7 -3
  55. package/lib-commonjs/components/Listbox/renderListbox.js.map +1 -1
  56. package/lib-commonjs/components/Listbox/useListbox.js +42 -34
  57. package/lib-commonjs/components/Listbox/useListbox.js.map +1 -1
  58. package/lib-commonjs/components/Option/useOption.js +7 -11
  59. package/lib-commonjs/components/Option/useOption.js.map +1 -1
  60. package/lib-commonjs/components/Option/useOptionStyles.styles.js +85 -85
  61. package/lib-commonjs/components/Option/useOptionStyles.styles.js.map +1 -1
  62. package/lib-commonjs/contexts/useComboboxContextValues.js +13 -5
  63. package/lib-commonjs/contexts/useComboboxContextValues.js.map +1 -1
  64. package/lib-commonjs/contexts/useListboxContextValues.js +13 -5
  65. package/lib-commonjs/contexts/useListboxContextValues.js.map +1 -1
  66. package/lib-commonjs/utils/dropdownKeyActions.js +3 -30
  67. package/lib-commonjs/utils/dropdownKeyActions.js.map +1 -1
  68. package/lib-commonjs/utils/useComboboxBaseState.js +52 -14
  69. package/lib-commonjs/utils/useComboboxBaseState.js.map +1 -1
  70. package/lib-commonjs/utils/useOptionCollection.js +18 -45
  71. package/lib-commonjs/utils/useOptionCollection.js.map +1 -1
  72. package/lib-commonjs/utils/useTriggerSlot.js +84 -31
  73. package/lib-commonjs/utils/useTriggerSlot.js.map +1 -1
  74. package/package.json +9 -8
  75. package/lib/utils/useScrollOptionsIntoView.js +0 -29
  76. package/lib/utils/useScrollOptionsIntoView.js.map +0 -1
  77. package/lib-commonjs/utils/useScrollOptionsIntoView.js +0 -40
  78. package/lib-commonjs/utils/useScrollOptionsIntoView.js.map +0 -1
@@ -14,10 +14,36 @@ const _reactutilities = require("@fluentui/react-utilities");
14
14
  const _useOptionCollection = require("../utils/useOptionCollection");
15
15
  const _useSelection = require("../utils/useSelection");
16
16
  const useComboboxBaseState = (props)=>{
17
- const { appearance = 'outline', children, clearable = false, editable = false, inlinePopup = false, mountNode = undefined, multiselect, onOpenChange, size = 'medium' } = props;
17
+ const { appearance = 'outline', children, clearable = false, editable = false, inlinePopup = false, mountNode = undefined, multiselect, onOpenChange, size = 'medium', activeDescendantController } = props;
18
18
  const optionCollection = (0, _useOptionCollection.useOptionCollection)();
19
- const { getOptionAtIndex, getOptionsMatchingValue } = optionCollection;
20
- const [activeOption, setActiveOption] = _react.useState();
19
+ const { getOptionsMatchingValue } = optionCollection;
20
+ const { getOptionById } = optionCollection;
21
+ const getActiveOption = _react.useCallback(()=>{
22
+ const activeOptionId = activeDescendantController.active();
23
+ return activeOptionId ? getOptionById(activeOptionId) : undefined;
24
+ }, [
25
+ activeDescendantController,
26
+ getOptionById
27
+ ]);
28
+ // Keeping some kind of backwards compatible functionality here
29
+ // eslint-disable-next-line @typescript-eslint/naming-convention
30
+ const UNSAFE_activeOption = getActiveOption();
31
+ // eslint-disable-next-line @typescript-eslint/naming-convention
32
+ const UNSAFE_setActiveOption = _react.useCallback((option)=>{
33
+ let nextOption = undefined;
34
+ if (typeof option === 'function') {
35
+ const activeOption = getActiveOption();
36
+ nextOption = option(activeOption);
37
+ }
38
+ if (nextOption) {
39
+ activeDescendantController.focus(nextOption.id);
40
+ } else {
41
+ activeDescendantController.blur();
42
+ }
43
+ }, [
44
+ activeDescendantController,
45
+ getActiveOption
46
+ ]);
21
47
  // track whether keyboard focus outline should be shown
22
48
  // tabster/keyborg doesn't work here, since the actual keyboard focus target doesn't move
23
49
  const [focusVisible, setFocusVisible] = _react.useState(false);
@@ -77,30 +103,42 @@ const useComboboxBaseState = (props)=>{
77
103
  onOpenChange,
78
104
  setOpenState
79
105
  ]);
80
- // update active option based on change in open state or children
106
+ // update active option based on change in open state
81
107
  _react.useEffect(()=>{
82
- if (open && !activeOption) {
108
+ if (open) {
83
109
  // if it is single-select and there is a selected option, start at the selected option
84
110
  if (!multiselect && selectedOptions.length > 0) {
85
111
  const selectedOption = getOptionsMatchingValue((v)=>v === selectedOptions[0]).pop();
86
- selectedOption && setActiveOption(selectedOption);
87
- } else {
88
- setActiveOption(getOptionAtIndex(0));
112
+ if (selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.id) {
113
+ activeDescendantController.focus(selectedOption.id);
114
+ }
89
115
  }
90
- } else if (!open) {
91
- // reset the active option when closing
92
- setActiveOption(undefined);
116
+ } else {
117
+ activeDescendantController.blur();
93
118
  }
94
119
  // this should only be run in response to changes in the open state or children
95
120
  // eslint-disable-next-line react-hooks/exhaustive-deps
96
121
  }, [
97
122
  open,
98
- children
123
+ activeDescendantController
124
+ ]);
125
+ // Fallback focus when children are updated in an open popover results in no item being focused
126
+ _react.useEffect(()=>{
127
+ if (open) {
128
+ if (!activeDescendantController.active()) {
129
+ activeDescendantController.first();
130
+ }
131
+ }
132
+ // this should only be run in response to changes in the open state or children
133
+ }, [
134
+ open,
135
+ children,
136
+ activeDescendantController
99
137
  ]);
100
138
  return {
101
139
  ...optionCollection,
102
140
  ...selectionState,
103
- activeOption,
141
+ activeOption: UNSAFE_activeOption,
104
142
  appearance,
105
143
  clearable,
106
144
  focusVisible,
@@ -109,7 +147,7 @@ const useComboboxBaseState = (props)=>{
109
147
  inlinePopup,
110
148
  mountNode,
111
149
  open,
112
- setActiveOption,
150
+ setActiveOption: UNSAFE_setActiveOption,
113
151
  setFocusVisible,
114
152
  setHasFocus,
115
153
  setOpen,
@@ -1 +1 @@
1
- {"version":3,"sources":["useComboboxBaseState.js"],"sourcesContent":["import * as React from 'react';\nimport { useControllableState, useFirstMount } from '@fluentui/react-utilities';\nimport { useOptionCollection } from '../utils/useOptionCollection';\nimport { useSelection } from '../utils/useSelection';\n/**\n * State shared between Combobox and Dropdown components\n */ export const useComboboxBaseState = (props)=>{\n const { appearance = 'outline', children, clearable = false, editable = false, inlinePopup = false, mountNode = undefined, multiselect, onOpenChange, size = 'medium' } = props;\n const optionCollection = useOptionCollection();\n const { getOptionAtIndex, getOptionsMatchingValue } = optionCollection;\n const [activeOption, setActiveOption] = React.useState();\n // track whether keyboard focus outline should be shown\n // tabster/keyborg doesn't work here, since the actual keyboard focus target doesn't move\n const [focusVisible, setFocusVisible] = React.useState(false);\n // track focused state to conditionally render collapsed listbox\n // when the trigger is focused - the listbox should but hidden until the open state is changed\n const [hasFocus, setHasFocus] = React.useState(false);\n const ignoreNextBlur = React.useRef(false);\n const selectionState = useSelection(props);\n const { selectedOptions } = selectionState;\n // calculate value based on props, internal value changes, and selected options\n const isFirstMount = useFirstMount();\n const [controllableValue, setValue] = useControllableState({\n state: props.value,\n initialState: undefined\n });\n const value = React.useMemo(()=>{\n // don't compute the value if it is defined through props or setValue,\n if (controllableValue !== undefined) {\n return controllableValue;\n }\n // handle defaultValue here, so it is overridden by selection\n if (isFirstMount && props.defaultValue !== undefined) {\n return props.defaultValue;\n }\n const selectedOptionsText = getOptionsMatchingValue((optionValue)=>{\n return selectedOptions.includes(optionValue);\n }).map((option)=>option.text);\n if (multiselect) {\n // editable inputs should not display multiple selected options in the input as text\n return editable ? '' : selectedOptionsText.join(', ');\n }\n return selectedOptionsText[0];\n // do not change value after isFirstMount changes,\n // we do not want to accidentally override defaultValue on a second render\n // unless another value is intentionally set\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [\n controllableValue,\n editable,\n getOptionsMatchingValue,\n multiselect,\n props.defaultValue,\n selectedOptions\n ]);\n // Handle open state, which is shared with options in context\n const [open, setOpenState] = useControllableState({\n state: props.open,\n defaultState: props.defaultOpen,\n initialState: false\n });\n const setOpen = React.useCallback((event, newState)=>{\n onOpenChange === null || onOpenChange === void 0 ? void 0 : onOpenChange(event, {\n open: newState\n });\n setOpenState(newState);\n }, [\n onOpenChange,\n setOpenState\n ]);\n // update active option based on change in open state or children\n React.useEffect(()=>{\n if (open && !activeOption) {\n // if it is single-select and there is a selected option, start at the selected option\n if (!multiselect && selectedOptions.length > 0) {\n const selectedOption = getOptionsMatchingValue((v)=>v === selectedOptions[0]).pop();\n selectedOption && setActiveOption(selectedOption);\n } else {\n setActiveOption(getOptionAtIndex(0));\n }\n } else if (!open) {\n // reset the active option when closing\n setActiveOption(undefined);\n }\n // this should only be run in response to changes in the open state or children\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [\n open,\n children\n ]);\n return {\n ...optionCollection,\n ...selectionState,\n activeOption,\n appearance,\n clearable,\n focusVisible,\n hasFocus,\n ignoreNextBlur,\n inlinePopup,\n mountNode,\n open,\n setActiveOption,\n setFocusVisible,\n setHasFocus,\n setOpen,\n setValue,\n size,\n value,\n multiselect\n };\n};\n"],"names":["useComboboxBaseState","props","appearance","children","clearable","editable","inlinePopup","mountNode","undefined","multiselect","onOpenChange","size","optionCollection","useOptionCollection","getOptionAtIndex","getOptionsMatchingValue","activeOption","setActiveOption","React","useState","focusVisible","setFocusVisible","hasFocus","setHasFocus","ignoreNextBlur","useRef","selectionState","useSelection","selectedOptions","isFirstMount","useFirstMount","controllableValue","setValue","useControllableState","state","value","initialState","useMemo","defaultValue","selectedOptionsText","optionValue","includes","map","option","text","join","open","setOpenState","defaultState","defaultOpen","setOpen","useCallback","event","newState","useEffect","length","selectedOption","v","pop"],"mappings":";;;;+BAMiBA;;;eAAAA;;;;iEANM;gCAC6B;qCAChB;8BACP;AAGlB,MAAMA,uBAAuB,CAACC;IACrC,MAAM,EAAEC,aAAa,SAAS,EAAEC,QAAQ,EAAEC,YAAY,KAAK,EAAEC,WAAW,KAAK,EAAEC,cAAc,KAAK,EAAEC,YAAYC,SAAS,EAAEC,WAAW,EAAEC,YAAY,EAAEC,OAAO,QAAQ,EAAE,GAAGV;IAC1K,MAAMW,mBAAmBC,IAAAA,wCAAmB;IAC5C,MAAM,EAAEC,gBAAgB,EAAEC,uBAAuB,EAAE,GAAGH;IACtD,MAAM,CAACI,cAAcC,gBAAgB,GAAGC,OAAMC,QAAQ;IACtD,uDAAuD;IACvD,yFAAyF;IACzF,MAAM,CAACC,cAAcC,gBAAgB,GAAGH,OAAMC,QAAQ,CAAC;IACvD,gEAAgE;IAChE,8FAA8F;IAC9F,MAAM,CAACG,UAAUC,YAAY,GAAGL,OAAMC,QAAQ,CAAC;IAC/C,MAAMK,iBAAiBN,OAAMO,MAAM,CAAC;IACpC,MAAMC,iBAAiBC,IAAAA,0BAAY,EAAC1B;IACpC,MAAM,EAAE2B,eAAe,EAAE,GAAGF;IAC5B,+EAA+E;IAC/E,MAAMG,eAAeC,IAAAA,6BAAa;IAClC,MAAM,CAACC,mBAAmBC,SAAS,GAAGC,IAAAA,oCAAoB,EAAC;QACvDC,OAAOjC,MAAMkC,KAAK;QAClBC,cAAc5B;IAClB;IACA,MAAM2B,QAAQjB,OAAMmB,OAAO,CAAC;QACxB,sEAAsE;QACtE,IAAIN,sB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AgBT;QACpB;IACJ,+EAA+E;IAC/E,uDAAuD;IACvD,GAAG;QACCsC;QACA3C;KACH;IACD,OAAO;QACH,GAAGS,gBAAgB;QACnB,GAAGc,cAAc;QACjBV;QACAd;QACAE;QACAgB;QACAE;QACAE;QACAlB;QACAC;QACAuC;QACA7B;QACAI;QACAE;QACA2B;QACAlB;QACArB;QACAwB;QACA1B;IACJ;AACJ"}
1
+ {"version":3,"sources":["useComboboxBaseState.js"],"sourcesContent":["import * as React from 'react';\nimport { useControllableState, useFirstMount } from '@fluentui/react-utilities';\nimport { useOptionCollection } from '../utils/useOptionCollection';\nimport { useSelection } from '../utils/useSelection';\n/**\n * State shared between Combobox and Dropdown components\n */ export const useComboboxBaseState = (props)=>{\n const { appearance = 'outline', children, clearable = false, editable = false, inlinePopup = false, mountNode = undefined, multiselect, onOpenChange, size = 'medium', activeDescendantController } = props;\n const optionCollection = useOptionCollection();\n const { getOptionsMatchingValue } = optionCollection;\n const { getOptionById } = optionCollection;\n const getActiveOption = React.useCallback(()=>{\n const activeOptionId = activeDescendantController.active();\n return activeOptionId ? getOptionById(activeOptionId) : undefined;\n }, [\n activeDescendantController,\n getOptionById\n ]);\n // Keeping some kind of backwards compatible functionality here\n // eslint-disable-next-line @typescript-eslint/naming-convention\n const UNSAFE_activeOption = getActiveOption();\n // eslint-disable-next-line @typescript-eslint/naming-convention\n const UNSAFE_setActiveOption = React.useCallback((option)=>{\n let nextOption = undefined;\n if (typeof option === 'function') {\n const activeOption = getActiveOption();\n nextOption = option(activeOption);\n }\n if (nextOption) {\n activeDescendantController.focus(nextOption.id);\n } else {\n activeDescendantController.blur();\n }\n }, [\n activeDescendantController,\n getActiveOption\n ]);\n // track whether keyboard focus outline should be shown\n // tabster/keyborg doesn't work here, since the actual keyboard focus target doesn't move\n const [focusVisible, setFocusVisible] = React.useState(false);\n // track focused state to conditionally render collapsed listbox\n // when the trigger is focused - the listbox should but hidden until the open state is changed\n const [hasFocus, setHasFocus] = React.useState(false);\n const ignoreNextBlur = React.useRef(false);\n const selectionState = useSelection(props);\n const { selectedOptions } = selectionState;\n // calculate value based on props, internal value changes, and selected options\n const isFirstMount = useFirstMount();\n const [controllableValue, setValue] = useControllableState({\n state: props.value,\n initialState: undefined\n });\n const value = React.useMemo(()=>{\n // don't compute the value if it is defined through props or setValue,\n if (controllableValue !== undefined) {\n return controllableValue;\n }\n // handle defaultValue here, so it is overridden by selection\n if (isFirstMount && props.defaultValue !== undefined) {\n return props.defaultValue;\n }\n const selectedOptionsText = getOptionsMatchingValue((optionValue)=>{\n return selectedOptions.includes(optionValue);\n }).map((option)=>option.text);\n if (multiselect) {\n // editable inputs should not display multiple selected options in the input as text\n return editable ? '' : selectedOptionsText.join(', ');\n }\n return selectedOptionsText[0];\n // do not change value after isFirstMount changes,\n // we do not want to accidentally override defaultValue on a second render\n // unless another value is intentionally set\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [\n controllableValue,\n editable,\n getOptionsMatchingValue,\n multiselect,\n props.defaultValue,\n selectedOptions\n ]);\n // Handle open state, which is shared with options in context\n const [open, setOpenState] = useControllableState({\n state: props.open,\n defaultState: props.defaultOpen,\n initialState: false\n });\n const setOpen = React.useCallback((event, newState)=>{\n onOpenChange === null || onOpenChange === void 0 ? void 0 : onOpenChange(event, {\n open: newState\n });\n setOpenState(newState);\n }, [\n onOpenChange,\n setOpenState\n ]);\n // update active option based on change in open state\n React.useEffect(()=>{\n if (open) {\n // if it is single-select and there is a selected option, start at the selected option\n if (!multiselect && selectedOptions.length > 0) {\n const selectedOption = getOptionsMatchingValue((v)=>v === selectedOptions[0]).pop();\n if (selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.id) {\n activeDescendantController.focus(selectedOption.id);\n }\n }\n } else {\n activeDescendantController.blur();\n }\n // this should only be run in response to changes in the open state or children\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [\n open,\n activeDescendantController\n ]);\n // Fallback focus when children are updated in an open popover results in no item being focused\n React.useEffect(()=>{\n if (open) {\n if (!activeDescendantController.active()) {\n activeDescendantController.first();\n }\n }\n // this should only be run in response to changes in the open state or children\n }, [\n open,\n children,\n activeDescendantController\n ]);\n return {\n ...optionCollection,\n ...selectionState,\n activeOption: UNSAFE_activeOption,\n appearance,\n clearable,\n focusVisible,\n hasFocus,\n ignoreNextBlur,\n inlinePopup,\n mountNode,\n open,\n setActiveOption: UNSAFE_setActiveOption,\n setFocusVisible,\n setHasFocus,\n setOpen,\n setValue,\n size,\n value,\n multiselect\n };\n};\n"],"names":["useComboboxBaseState","props","appearance","children","clearable","editable","inlinePopup","mountNode","undefined","multiselect","onOpenChange","size","activeDescendantController","optionCollection","useOptionCollection","getOptionsMatchingValue","getOptionById","getActiveOption","React","useCallback","activeOptionId","active","UNSAFE_activeOption","UNSAFE_setActiveOption","option","nextOption","activeOption","focus","id","blur","focusVisible","setFocusVisible","useState","hasFocus","setHasFocus","ignoreNextBlur","useRef","selectionState","useSelection","selectedOptions","isFirstMount","useFirstMount","controllableValue","setValue","useControllableState","state","value","initialState","useMemo","defaultValue","selectedOptionsText","optionValue","includes","map","text","join","open","setOpenState","defaultState","defaultOpen","setOpen","event","newState","useEffect","length","selectedOption","v","pop","first","setActiveOption"],"mappings":";;;;+BAMiBA;;;eAAAA;;;;iEANM;gCAC6B;qCAChB;8BACP;AAGlB,MAAMA,uBAAuB,CAACC;IACrC,MAAM,EAAEC,aAAa,SAAS,EAAEC,QAAQ,EAAEC,YAAY,KAAK,EAAEC,WAAW,KAAK,EAAEC,cAAc,KAAK,EAAEC,YAAYC,SAAS,EAAEC,WAAW,EAAEC,YAAY,EAAEC,OAAO,QAAQ,EAAEC,0BAA0B,EAAE,GAAGX;IACtM,MAAMY,mBAAmBC,IAAAA,wCAAmB;IAC5C,MAAM,EAAEC,uBAAuB,EAAE,GAAGF;IACpC,MAAM,EAAEG,aAAa,EAAE,GAAGH;IAC1B,MAAMI,kBAAkBC,OAAMC,WAAW,CAAC;QACtC,MAAMC,iBAAiBR,2BA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AA+E;IAC/E,GAAG;QACCZ;QACArD;QACAS;KACH;IACD,OAAO;QACH,GAAGC,gBAAgB;QACnB,GAAGwB,cAAc;QACjBX,cAAcJ;QACdpB;QACAE;QACA0B;QACAG;QACAE;QACA7B;QACAC;QACAiD;QACAa,iBAAiB9C;QACjBQ;QACAG;QACA0B;QACAjB;QACAhC;QACAmC;QACArC;IACJ;AACJ"}
@@ -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 nodes = _react.useRef([]);
14
+ const optionsById = _react.useRef(new Map());
15
15
  const collectionAPI = _react.useMemo(()=>{
16
- const getCount = ()=>nodes.current.length;
17
- const getOptionAtIndex = (index)=>{
18
- var _nodes_current_index;
19
- return (_nodes_current_index = nodes.current[index]) === null || _nodes_current_index === void 0 ? void 0 : _nodes_current_index.option;
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
- const item = nodes.current.find((node)=>node.option.id === id);
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 nodes.current.filter((node)=>matcher(node.option.text)).map((node)=>node.option);
24
+ return Array.from(optionsById.current.values()).filter(({ text })=>matcher(text));
28
25
  };
29
26
  const getOptionsMatchingValue = (matcher)=>{
30
- return nodes.current.filter((node)=>matcher(node.option.value)).map((node)=>node.option);
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, element)=>{
42
- var _nodes_current_index;
43
- const index = nodes.current.findIndex((node)=>{
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: nodes.current.map((node)=>node.option),
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 nodes = React.useRef([]);\n const collectionAPI = React.useMemo(()=>{\n const getCount = ()=>nodes.current.length;\n const getOptionAtIndex = (index)=>{\n var _nodes_current_index;\n return (_nodes_current_index = nodes.current[index]) === null || _nodes_current_index === void 0 ? void 0 : _nodes_current_index.option;\n };\n const getIndexOfId = (id)=>nodes.current.findIndex((node)=>node.option.id === id);\n const getOptionById = (id)=>{\n const item = nodes.current.find((node)=>node.option.id === id);\n return item === null || item === void 0 ? void 0 : item.option;\n };\n const getOptionsMatchingText = (matcher)=>{\n return nodes.current.filter((node)=>matcher(node.option.text)).map((node)=>node.option);\n };\n const getOptionsMatchingValue = (matcher)=>{\n return nodes.current.filter((node)=>matcher(node.option.value)).map((node)=>node.option);\n };\n return {\n getCount,\n getOptionAtIndex,\n getIndexOfId,\n getOptionById,\n getOptionsMatchingText,\n getOptionsMatchingValue\n };\n }, []);\n const registerOption = React.useCallback((option, element)=>{\n var _nodes_current_index;\n const index = nodes.current.findIndex((node)=>{\n if (!node.element || !element) {\n return false;\n }\n if (node.option.id === option.id) {\n return true;\n }\n // use the DOM method compareDocumentPosition to order the current node against registered nodes\n // eslint-disable-next-line no-bitwise\n return node.element.compareDocumentPosition(element) & Node.DOCUMENT_POSITION_PRECEDING;\n });\n // do not register the option if it already exists\n if (((_nodes_current_index = nodes.current[index]) === null || _nodes_current_index === void 0 ? void 0 : _nodes_current_index.option.id) !== option.id) {\n const newItem = {\n element,\n option\n };\n // If an index is not found we will push the element to the end.\n if (index === -1) {\n nodes.current = [\n ...nodes.current,\n newItem\n ];\n } else {\n nodes.current.splice(index, 0, newItem);\n }\n }\n // return the unregister function\n return ()=>{\n nodes.current = nodes.current.filter((node)=>node.option.id !== option.id);\n };\n }, []);\n return {\n ...collectionAPI,\n options: nodes.current.map((node)=>node.option),\n registerOption\n };\n};\n"],"names":["useOptionCollection","nodes","React","useRef","collectionAPI","useMemo","getCount","current","length","getOptionAtIndex","index","_nodes_current_index","option","getIndexOfId","id","findIndex","node","getOptionById","item","find","getOptionsMatchingText","matcher","filter","text","map","getOptionsMatchingValue","value","registerOption","useCallback","element","compareDocumentPosition","Node","DOCUMENT_POSITION_PRECEDING","newItem","splice","options"],"mappings":";;;;+BAGiBA;;;eAAAA;;;;iEAHM;AAGZ,MAAMA,sBAAsB;IACnC,MAAMC,QAAQC,OAAMC,MAAM,CAAC,EAAE;IAC7B,MAAMC,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AAE,KAAKF,OAAOE,EAAE,EAAE;gBAC9B,OAAO;YACX;YACA,gGAAgG;YAChG,sCAAsC;YACtC,OAAOE,KAAKa,OAAO,CAACC,uBAAuB,CAACD,WAAWE,KAAKC,2BAA2B;QAC3F;QACA,kDAAkD;QAClD,IAAI,AAAC,CAAA,AAACrB,CAAAA,uBAAuBV,MAAMM,OAAO,CAACG,MAAM,AAAD,MAAO,QAAQC,yBAAyB,KAAK,IAAI,KAAK,IAAIA,qBAAqBC,MAAM,CAACE,EAAE,AAAD,MAAOF,OAAOE,EAAE,EAAE;YACrJ,MAAMmB,UAAU;gBACZJ;gBACAjB;YACJ;YACA,gEAAgE;YAChE,IAAIF,UAAU,CAAC,GAAG;gBACdT,MAAMM,OAAO,GAAG;uBACTN,MAAMM,OAAO;oBAChB0B;iBACH;YACL,OAAO;gBACHhC,MAAMM,OAAO,CAAC2B,MAAM,CAACxB,OAAO,GAAGuB;YACnC;QACJ;QACA,iCAAiC;QACjC,OAAO;YACHhC,MAAMM,OAAO,GAAGN,MAAMM,OAAO,CAACe,MAAM,CAAC,CAACN,OAAOA,KAAKJ,MAAM,CAACE,EAAE,KAAKF,OAAOE,EAAE;QAC7E;IACJ,GAAG,EAAE;IACL,OAAO;QACH,GAAGV,aAAa;QAChB+B,SAASlC,MAAMM,OAAO,CAACiB,GAAG,CAAC,CAACR,OAAOA,KAAKJ,MAAM;QAC9Ce;IACJ;AACJ"}
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: { activeOption, getCount, getIndexOfId, getOptionAtIndex, open, selectOption, setActiveOption, setFocusVisible, setOpen, multiselect, setHasFocus }, defaultProps, elementType } = options;
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)((event)=>{
45
- const action = (0, _dropdownKeyActions.getDropdownActionFromKey)(event, {
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 maxIndex = getCount() - 1;
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
- event.preventDefault();
55
- setFocusVisible(true);
56
- setOpen(event, true);
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
- event.stopPropagation();
61
- event.preventDefault();
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(event, false);
132
+ !multiselect && !(activeOption === null || activeOption === void 0 ? void 0 : activeOption.disabled) && setOpen(e, false);
66
133
  // fallthrough
67
134
  case 'Select':
68
- activeOption && selectOption(event, activeOption);
69
- event.preventDefault();
135
+ activeOption && selectOption(e, activeOption);
70
136
  break;
71
137
  case 'Tab':
72
- !multiselect && activeOption && selectOption(event, activeOption);
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
- }, trigger.onKeyDown);
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, getIndexFromAction } 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: { activeOption, getCount, getIndexOfId, getOptionAtIndex, open, selectOption, setActiveOption, setFocusVisible, setOpen, multiselect, setHasFocus }, defaultProps, elementType } = options;\n const trigger = slot.always(triggerSlotFromProp, {\n defaultProps: {\n type: 'text',\n 'aria-expanded': open,\n 'aria-activedescendant': open ? activeOption === null || activeOption === void 0 ? void 0 : activeOption.id : undefined,\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((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 // TODO fix cast\n return trigger;\n}\n"],"names":["useTriggerSlot","triggerSlotFromProp","ref","options","state","activeOption","getCount","getIndexOfId","getOptionAtIndex","open","selectOption","setActiveOption","setFocusVisible","setOpen","multiselect","setHasFocus","defaultProps","elementType","trigger","slot","always","type","id","undefined","role","triggerRef","React","useRef","useMergedRefs","onBlur","mergeCallbacks","event","onFocus","target","currentTarget","onClick","onKeyDown","action","getDropdownActionFromKey","maxIndex","activeIndex","newIndex","preventDefault","stopPropagation","disabled","getIndexFromAction","onMouseOver"],"mappings":";;;;+BAMoBA;;;eAAAA;;;;iEANG;gCAC6B;oCACS;AAIlD,SAASA,eAAeC,mBAAmB,EAAEC,GAAG,EAAEC,OAAO;IAChE,MAAM,EAAEC,OAAO,EAAEC,YAAY,EAAEC,QAAQ,EAAEC,YAAY,EAAEC,gBAAgB,EAAEC,IAAI,EAAEC,YAAY,EAAEC,eAAe,EAAEC,eAAe,EAAEC,OAAO,EAAEC,WAAW,EAAEC,WAAW,EAAE,EAAEC,YAAY,EAAEC,WAAW,EAAE,GAAGd;IAClM,MAAMe,UAAUC,oBAAI,CAACC,MAAM,CAACnB,qBAAqB;QAC7Ce,cAAc;YACVK,MAAM;YACN,iBAAiBZ;YACjB,yBAAyBA,OAAOJ,iBAAiB,QAAQA,iBAAiB,KAAK,IAAI,KAAK,IAAIA,aAAaiB,EAAE,GAAGC;YAC9GC,MAAM;YACN,GAAG,OAAOR,iBAAiB,YAAYA,YAAY;QACvD;QACAC;IACJ;IACA,4BAA4B;IAC5B,MAAMQ,aAAaC,OAAMC,MAAM,CAAC;IAChCT,QAAQhB,GAAG,GAAG0B,IAAAA,6BAAa,EAACH,YA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QACA,IAAIE,aAAaD,aAAa;YAC1B,mEAAmE;YACnET,MAAMW,cAAc;YACpB/B,gBAAgBH,iBAAiBiC;YACjC7B,gBAAgB;QACpB;IACJ,GAAGM,QAAQkB,SAAS;IACpBlB,QAAQ4B,WAAW,GAAGhB,IAAAA,8BAAc,EAAC,CAACC;QAClCnB,gBAAgB;IACpB,GAAGM,QAAQ4B,WAAW;IACtB,gBAAgB;IAChB,OAAO5B;AACX"}
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,QAAQ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C,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.7.5",
3
+ "version": "9.8.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.0",
36
37
  "@fluentui/keyboard-keys": "^9.0.7",
37
- "@fluentui/react-context-selector": "^9.1.51",
38
- "@fluentui/react-field": "^9.1.53",
38
+ "@fluentui/react-context-selector": "^9.1.52",
39
+ "@fluentui/react-field": "^9.1.54",
39
40
  "@fluentui/react-icons": "^2.0.224",
40
- "@fluentui/react-jsx-runtime": "^9.0.29",
41
- "@fluentui/react-portal": "^9.4.13",
42
- "@fluentui/react-positioning": "^9.13.3",
41
+ "@fluentui/react-jsx-runtime": "^9.0.30",
42
+ "@fluentui/react-portal": "^9.4.14",
43
+ "@fluentui/react-positioning": "^9.13.4",
43
44
  "@fluentui/react-shared-contexts": "^9.14.0",
44
- "@fluentui/react-tabster": "^9.19.0",
45
+ "@fluentui/react-tabster": "^9.19.1",
45
46
  "@fluentui/react-theme": "^9.1.16",
46
- "@fluentui/react-utilities": "^9.18.0",
47
+ "@fluentui/react-utilities": "^9.18.1",
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"}