@fluentui/react-combobox 9.0.0-beta.8 → 9.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.json +964 -4
- package/CHANGELOG.md +274 -5
- package/README.md +1 -3
- package/dist/index.d.ts +84 -24
- package/lib/Combobox.js.map +1 -1
- package/lib/ComboboxField.js +2 -0
- package/lib/ComboboxField.js.map +1 -0
- package/lib/Dropdown.js.map +1 -1
- package/lib/Listbox.js.map +1 -1
- package/lib/Option.js.map +1 -1
- package/lib/OptionGroup.js.map +1 -1
- package/lib/components/Combobox/Combobox.js +0 -1
- package/lib/components/Combobox/Combobox.js.map +1 -1
- package/lib/components/Combobox/Combobox.types.js.map +1 -1
- package/lib/components/Combobox/index.js.map +1 -1
- package/lib/components/Combobox/renderCombobox.js +11 -8
- package/lib/components/Combobox/renderCombobox.js.map +1 -1
- package/lib/components/Combobox/useCombobox.js +191 -16
- package/lib/components/Combobox/useCombobox.js.map +1 -1
- package/lib/components/Combobox/useComboboxStyles.js +253 -161
- package/lib/components/Combobox/useComboboxStyles.js.map +1 -1
- package/lib/components/ComboboxField/ComboboxField.js +8 -0
- package/lib/components/ComboboxField/ComboboxField.js.map +1 -0
- package/lib/components/ComboboxField/index.js +2 -0
- package/lib/components/ComboboxField/index.js.map +1 -0
- package/lib/components/Dropdown/Dropdown.js +0 -1
- package/lib/components/Dropdown/Dropdown.js.map +1 -1
- package/lib/components/Dropdown/Dropdown.types.js.map +1 -1
- package/lib/components/Dropdown/index.js.map +1 -1
- package/lib/components/Dropdown/renderDropdown.js +11 -8
- package/lib/components/Dropdown/renderDropdown.js.map +1 -1
- package/lib/components/Dropdown/useDropdown.js +90 -9
- package/lib/components/Dropdown/useDropdown.js.map +1 -1
- package/lib/components/Dropdown/useDropdownStyles.js +237 -155
- package/lib/components/Dropdown/useDropdownStyles.js.map +1 -1
- package/lib/components/Listbox/Listbox.js +0 -1
- package/lib/components/Listbox/Listbox.js.map +1 -1
- package/lib/components/Listbox/Listbox.types.js.map +1 -1
- package/lib/components/Listbox/index.js.map +1 -1
- package/lib/components/Listbox/renderListbox.js +2 -2
- package/lib/components/Listbox/renderListbox.js.map +1 -1
- package/lib/components/Listbox/useListbox.js +35 -29
- package/lib/components/Listbox/useListbox.js.map +1 -1
- package/lib/components/Listbox/useListboxStyles.js +16 -20
- package/lib/components/Listbox/useListboxStyles.js.map +1 -1
- package/lib/components/Option/Option.js +0 -1
- package/lib/components/Option/Option.js.map +1 -1
- package/lib/components/Option/Option.types.js.map +1 -1
- package/lib/components/Option/index.js.map +1 -1
- package/lib/components/Option/renderOption.js +4 -3
- package/lib/components/Option/renderOption.js.map +1 -1
- package/lib/components/Option/useOption.js +61 -46
- package/lib/components/Option/useOption.js.map +1 -1
- package/lib/components/Option/useOptionStyles.js +103 -80
- package/lib/components/Option/useOptionStyles.js.map +1 -1
- package/lib/components/OptionGroup/OptionGroup.js +0 -1
- package/lib/components/OptionGroup/OptionGroup.js.map +1 -1
- package/lib/components/OptionGroup/OptionGroup.types.js.map +1 -1
- package/lib/components/OptionGroup/index.js.map +1 -1
- package/lib/components/OptionGroup/renderOptionGroup.js +4 -3
- package/lib/components/OptionGroup/renderOptionGroup.js.map +1 -1
- package/lib/components/OptionGroup/useOptionGroup.js +0 -1
- package/lib/components/OptionGroup/useOptionGroup.js.map +1 -1
- package/lib/components/OptionGroup/useOptionGroupStyles.js +29 -34
- package/lib/components/OptionGroup/useOptionGroupStyles.js.map +1 -1
- package/lib/contexts/ComboboxContext.js +14 -9
- package/lib/contexts/ComboboxContext.js.map +1 -1
- package/lib/contexts/ListboxContext.js +11 -8
- package/lib/contexts/ListboxContext.js.map +1 -1
- package/lib/contexts/useComboboxContextValues.js +8 -2
- package/lib/contexts/useComboboxContextValues.js.map +1 -1
- package/lib/contexts/useListboxContextValues.js +10 -6
- package/lib/contexts/useListboxContextValues.js.map +1 -1
- package/lib/index.js +6 -0
- package/lib/index.js.map +1 -1
- package/lib/utils/ComboboxBase.types.js.map +1 -1
- package/lib/utils/OptionCollection.types.js.map +1 -1
- package/lib/utils/Selection.types.js.map +1 -1
- package/lib/utils/dropdownKeyActions.js +14 -42
- package/lib/utils/dropdownKeyActions.js.map +1 -1
- package/lib/utils/internalTokens.js.map +1 -1
- package/lib/utils/useComboboxBaseState.js +48 -44
- package/lib/utils/useComboboxBaseState.js.map +1 -1
- package/lib/utils/useComboboxPopup.js +10 -6
- package/lib/utils/useComboboxPopup.js.map +1 -1
- package/lib/utils/useOptionCollection.js +13 -23
- package/lib/utils/useOptionCollection.js.map +1 -1
- package/lib/utils/useScrollOptionsIntoView.js +36 -0
- package/lib/utils/useScrollOptionsIntoView.js.map +1 -0
- package/lib/utils/useSelection.js +20 -14
- package/lib/utils/useSelection.js.map +1 -1
- package/lib/utils/useTriggerListboxSlots.js +46 -57
- package/lib/utils/useTriggerListboxSlots.js.map +1 -1
- package/lib-amd/Combobox.js +6 -0
- package/lib-amd/Combobox.js.map +1 -0
- package/lib-amd/ComboboxField.js +6 -0
- package/lib-amd/ComboboxField.js.map +1 -0
- package/lib-amd/Dropdown.js +6 -0
- package/lib-amd/Dropdown.js.map +1 -0
- package/lib-amd/Listbox.js +6 -0
- package/lib-amd/Listbox.js.map +1 -0
- package/lib-amd/Option.js +6 -0
- package/lib-amd/Option.js.map +1 -0
- package/lib-amd/OptionGroup.js +6 -0
- package/lib-amd/OptionGroup.js.map +1 -0
- package/lib-amd/components/Combobox/Combobox.js +16 -0
- package/lib-amd/components/Combobox/Combobox.js.map +1 -0
- package/lib-amd/components/Combobox/Combobox.types.js +5 -0
- package/lib-amd/components/Combobox/Combobox.types.js.map +1 -0
- package/lib-amd/components/Combobox/index.js +10 -0
- package/lib-amd/components/Combobox/index.js.map +1 -0
- package/lib-amd/components/Combobox/renderCombobox.js +20 -0
- package/lib-amd/components/Combobox/renderCombobox.js.map +1 -0
- package/lib-amd/components/Combobox/useCombobox.js +206 -0
- package/lib-amd/components/Combobox/useCombobox.js.map +1 -0
- package/lib-amd/components/Combobox/useComboboxStyles.js +152 -0
- package/lib-amd/components/Combobox/useComboboxStyles.js.map +1 -0
- package/lib-amd/components/ComboboxField/ComboboxField.js +10 -0
- package/lib-amd/components/ComboboxField/ComboboxField.js.map +1 -0
- package/lib-amd/components/ComboboxField/index.js +6 -0
- package/lib-amd/components/ComboboxField/index.js.map +1 -0
- package/lib-amd/components/Dropdown/Dropdown.js +16 -0
- package/lib-amd/components/Dropdown/Dropdown.js.map +1 -0
- package/lib-amd/components/Dropdown/Dropdown.types.js +5 -0
- package/lib-amd/components/Dropdown/Dropdown.types.js.map +1 -0
- package/lib-amd/components/Dropdown/index.js +10 -0
- package/lib-amd/components/Dropdown/index.js.map +1 -0
- package/lib-amd/components/Dropdown/renderDropdown.js +21 -0
- package/lib-amd/components/Dropdown/renderDropdown.js.map +1 -0
- package/lib-amd/components/Dropdown/useDropdown.js +121 -0
- package/lib-amd/components/Dropdown/useDropdown.js.map +1 -0
- package/lib-amd/components/Dropdown/useDropdownStyles.js +127 -0
- package/lib-amd/components/Dropdown/useDropdownStyles.js.map +1 -0
- package/lib-amd/components/Listbox/Listbox.js +16 -0
- package/lib-amd/components/Listbox/Listbox.js.map +1 -0
- package/lib-amd/components/Listbox/Listbox.types.js +5 -0
- package/lib-amd/components/Listbox/Listbox.types.js.map +1 -0
- package/lib-amd/components/Listbox/index.js +10 -0
- package/lib-amd/components/Listbox/index.js.map +1 -0
- package/lib-amd/components/Listbox/renderListbox.js +15 -0
- package/lib-amd/components/Listbox/renderListbox.js.map +1 -0
- package/lib-amd/components/Listbox/useListbox.js +80 -0
- package/lib-amd/components/Listbox/useListbox.js.map +1 -0
- package/lib-amd/components/Listbox/useListboxStyles.js +24 -0
- package/lib-amd/components/Listbox/useListboxStyles.js.map +1 -0
- package/lib-amd/components/Option/Option.js +15 -0
- package/lib-amd/components/Option/Option.js.map +1 -0
- package/lib-amd/components/Option/Option.types.js +5 -0
- package/lib-amd/components/Option/Option.types.js.map +1 -0
- package/lib-amd/components/Option/index.js +10 -0
- package/lib-amd/components/Option/index.js.map +1 -0
- package/lib-amd/components/Option/renderOption.js +16 -0
- package/lib-amd/components/Option/renderOption.js.map +1 -0
- package/lib-amd/components/Option/useOption.js +117 -0
- package/lib-amd/components/Option/useOption.js.map +1 -0
- package/lib-amd/components/Option/useOptionStyles.js +73 -0
- package/lib-amd/components/Option/useOptionStyles.js.map +1 -0
- package/lib-amd/components/OptionGroup/OptionGroup.js +15 -0
- package/lib-amd/components/OptionGroup/OptionGroup.js.map +1 -0
- package/lib-amd/components/OptionGroup/OptionGroup.types.js +5 -0
- package/lib-amd/components/OptionGroup/OptionGroup.types.js.map +1 -0
- package/lib-amd/components/OptionGroup/index.js +10 -0
- package/lib-amd/components/OptionGroup/index.js.map +1 -0
- package/lib-amd/components/OptionGroup/renderOptionGroup.js +16 -0
- package/lib-amd/components/OptionGroup/renderOptionGroup.js.map +1 -0
- package/lib-amd/components/OptionGroup/useOptionGroup.js +33 -0
- package/lib-amd/components/OptionGroup/useOptionGroup.js.map +1 -0
- package/lib-amd/components/OptionGroup/useOptionGroupStyles.js +34 -0
- package/lib-amd/components/OptionGroup/useOptionGroupStyles.js.map +1 -0
- package/lib-amd/contexts/ComboboxContext.js +28 -0
- package/lib-amd/contexts/ComboboxContext.js.map +1 -0
- package/lib-amd/contexts/ListboxContext.js +23 -0
- package/lib-amd/contexts/ListboxContext.js.map +1 -0
- package/lib-amd/contexts/useComboboxContextValues.js +23 -0
- package/lib-amd/contexts/useComboboxContextValues.js.map +1 -0
- package/lib-amd/contexts/useListboxContextValues.js +24 -0
- package/lib-amd/contexts/useListboxContextValues.js.map +1 -0
- package/lib-amd/index.js +37 -0
- package/lib-amd/index.js.map +1 -0
- package/lib-amd/utils/ComboboxBase.types.js +5 -0
- package/lib-amd/utils/ComboboxBase.types.js.map +1 -0
- package/lib-amd/utils/OptionCollection.types.js +5 -0
- package/lib-amd/utils/OptionCollection.types.js.map +1 -0
- package/lib-amd/utils/Selection.types.js +5 -0
- package/lib-amd/utils/Selection.types.js.map +1 -0
- package/lib-amd/utils/dropdownKeyActions.js +85 -0
- package/lib-amd/utils/dropdownKeyActions.js.map +1 -0
- package/lib-amd/utils/internalTokens.js +11 -0
- package/lib-amd/utils/internalTokens.js.map +1 -0
- package/lib-amd/utils/useComboboxBaseState.js +76 -0
- package/lib-amd/utils/useComboboxBaseState.js.map +1 -0
- package/lib-amd/utils/useComboboxPopup.js +16 -0
- package/lib-amd/utils/useComboboxPopup.js.map +1 -0
- package/lib-amd/utils/useOptionCollection.js +65 -0
- package/lib-amd/utils/useOptionCollection.js.map +1 -0
- package/lib-amd/utils/useScrollOptionsIntoView.js +33 -0
- package/lib-amd/utils/useScrollOptionsIntoView.js.map +1 -0
- package/lib-amd/utils/useSelection.js +42 -0
- package/lib-amd/utils/useSelection.js.map +1 -0
- package/lib-amd/utils/useTriggerListboxSlots.js +104 -0
- package/lib-amd/utils/useTriggerListboxSlots.js.map +1 -0
- package/lib-commonjs/Combobox.js +0 -2
- package/lib-commonjs/Combobox.js.map +1 -1
- package/lib-commonjs/ComboboxField.js +8 -0
- package/lib-commonjs/ComboboxField.js.map +1 -0
- package/lib-commonjs/Dropdown.js +0 -2
- package/lib-commonjs/Dropdown.js.map +1 -1
- package/lib-commonjs/Listbox.js +0 -2
- package/lib-commonjs/Listbox.js.map +1 -1
- package/lib-commonjs/Option.js +0 -2
- package/lib-commonjs/Option.js.map +1 -1
- package/lib-commonjs/OptionGroup.js +0 -2
- package/lib-commonjs/OptionGroup.js.map +1 -1
- package/lib-commonjs/components/Combobox/Combobox.js +0 -7
- package/lib-commonjs/components/Combobox/Combobox.js.map +1 -1
- package/lib-commonjs/components/Combobox/Combobox.types.js.map +1 -1
- package/lib-commonjs/components/Combobox/index.js +0 -6
- package/lib-commonjs/components/Combobox/index.js.map +1 -1
- package/lib-commonjs/components/Combobox/renderCombobox.js +11 -14
- package/lib-commonjs/components/Combobox/renderCombobox.js.map +1 -1
- package/lib-commonjs/components/Combobox/useCombobox.js +190 -24
- package/lib-commonjs/components/Combobox/useCombobox.js.map +1 -1
- package/lib-commonjs/components/Combobox/useComboboxStyles.js +252 -165
- package/lib-commonjs/components/Combobox/useComboboxStyles.js.map +1 -1
- package/lib-commonjs/components/ComboboxField/ComboboxField.js +14 -0
- package/lib-commonjs/components/ComboboxField/ComboboxField.js.map +1 -0
- package/lib-commonjs/components/ComboboxField/index.js +8 -0
- package/lib-commonjs/components/ComboboxField/index.js.map +1 -0
- package/lib-commonjs/components/Dropdown/Dropdown.js +0 -7
- package/lib-commonjs/components/Dropdown/Dropdown.js.map +1 -1
- package/lib-commonjs/components/Dropdown/Dropdown.types.js.map +1 -1
- package/lib-commonjs/components/Dropdown/index.js +0 -6
- package/lib-commonjs/components/Dropdown/index.js.map +1 -1
- package/lib-commonjs/components/Dropdown/renderDropdown.js +11 -14
- package/lib-commonjs/components/Dropdown/renderDropdown.js.map +1 -1
- package/lib-commonjs/components/Dropdown/useDropdown.js +89 -17
- package/lib-commonjs/components/Dropdown/useDropdown.js.map +1 -1
- package/lib-commonjs/components/Dropdown/useDropdownStyles.js +236 -159
- package/lib-commonjs/components/Dropdown/useDropdownStyles.js.map +1 -1
- package/lib-commonjs/components/Listbox/Listbox.js +0 -7
- package/lib-commonjs/components/Listbox/Listbox.js.map +1 -1
- package/lib-commonjs/components/Listbox/Listbox.types.js.map +1 -1
- package/lib-commonjs/components/Listbox/index.js +0 -6
- package/lib-commonjs/components/Listbox/index.js.map +1 -1
- package/lib-commonjs/components/Listbox/renderListbox.js +2 -7
- package/lib-commonjs/components/Listbox/renderListbox.js.map +1 -1
- package/lib-commonjs/components/Listbox/useListbox.js +34 -37
- package/lib-commonjs/components/Listbox/useListbox.js.map +1 -1
- package/lib-commonjs/components/Listbox/useListboxStyles.js +16 -24
- package/lib-commonjs/components/Listbox/useListboxStyles.js.map +1 -1
- package/lib-commonjs/components/Option/Option.js +0 -6
- package/lib-commonjs/components/Option/Option.js.map +1 -1
- package/lib-commonjs/components/Option/Option.types.js.map +1 -1
- package/lib-commonjs/components/Option/index.js +0 -6
- package/lib-commonjs/components/Option/index.js.map +1 -1
- package/lib-commonjs/components/Option/renderOption.js +4 -7
- package/lib-commonjs/components/Option/renderOption.js.map +1 -1
- package/lib-commonjs/components/Option/useOption.js +60 -52
- package/lib-commonjs/components/Option/useOption.js.map +1 -1
- package/lib-commonjs/components/Option/useOptionStyles.js +103 -84
- package/lib-commonjs/components/Option/useOptionStyles.js.map +1 -1
- package/lib-commonjs/components/OptionGroup/OptionGroup.js +0 -6
- package/lib-commonjs/components/OptionGroup/OptionGroup.js.map +1 -1
- package/lib-commonjs/components/OptionGroup/OptionGroup.types.js.map +1 -1
- package/lib-commonjs/components/OptionGroup/index.js +0 -6
- package/lib-commonjs/components/OptionGroup/index.js.map +1 -1
- package/lib-commonjs/components/OptionGroup/renderOptionGroup.js +4 -7
- package/lib-commonjs/components/OptionGroup/renderOptionGroup.js.map +1 -1
- package/lib-commonjs/components/OptionGroup/useOptionGroup.js +0 -4
- package/lib-commonjs/components/OptionGroup/useOptionGroup.js.map +1 -1
- package/lib-commonjs/components/OptionGroup/useOptionGroupStyles.js +29 -38
- package/lib-commonjs/components/OptionGroup/useOptionGroupStyles.js.map +1 -1
- package/lib-commonjs/contexts/ComboboxContext.js +15 -12
- package/lib-commonjs/contexts/ComboboxContext.js.map +1 -1
- package/lib-commonjs/contexts/ListboxContext.js +12 -11
- package/lib-commonjs/contexts/ListboxContext.js.map +1 -1
- package/lib-commonjs/contexts/useComboboxContextValues.js +8 -4
- package/lib-commonjs/contexts/useComboboxContextValues.js.map +1 -1
- package/lib-commonjs/contexts/useListboxContextValues.js +10 -10
- package/lib-commonjs/contexts/useListboxContextValues.js.map +1 -1
- package/lib-commonjs/index.js +43 -11
- package/lib-commonjs/index.js.map +1 -1
- package/lib-commonjs/utils/ComboboxBase.types.js.map +1 -1
- package/lib-commonjs/utils/OptionCollection.types.js.map +1 -1
- package/lib-commonjs/utils/Selection.types.js.map +1 -1
- package/lib-commonjs/utils/dropdownKeyActions.js +14 -46
- package/lib-commonjs/utils/dropdownKeyActions.js.map +1 -1
- package/lib-commonjs/utils/internalTokens.js.map +1 -1
- package/lib-commonjs/utils/useComboboxBaseState.js +48 -50
- package/lib-commonjs/utils/useComboboxBaseState.js.map +1 -1
- package/lib-commonjs/utils/useComboboxPopup.js +10 -10
- package/lib-commonjs/utils/useComboboxPopup.js.map +1 -1
- package/lib-commonjs/utils/useOptionCollection.js +13 -26
- package/lib-commonjs/utils/useOptionCollection.js.map +1 -1
- package/lib-commonjs/utils/useScrollOptionsIntoView.js +43 -0
- package/lib-commonjs/utils/useScrollOptionsIntoView.js.map +1 -0
- package/lib-commonjs/utils/useSelection.js +20 -17
- package/lib-commonjs/utils/useSelection.js.map +1 -1
- package/lib-commonjs/utils/useTriggerListboxSlots.js +45 -61
- package/lib-commonjs/utils/useTriggerListboxSlots.js.map +1 -1
- package/package.json +24 -23
- package/Spec-migration.md +0 -13
- package/Spec.md +0 -520
- package/dist/tsdoc-metadata.json +0 -11
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"mappings":";;;;;;AAAAA","names":["tslib_1"],"sourceRoot":"../src/","sources":["packages/react-components/react-combobox/src/Listbox.ts"],"sourcesContent":["export * from './components/Listbox/index';\n"]}
|
package/lib-commonjs/Option.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"mappings":";;;;;;AAAAA","names":["tslib_1"],"sourceRoot":"../src/","sources":["packages/react-components/react-combobox/src/Option.ts"],"sourcesContent":["export * from './components/Option/index';\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"mappings":";;;;;;AAAAA","names":["tslib_1"],"sourceRoot":"../src/","sources":["packages/react-components/react-combobox/src/OptionGroup.ts"],"sourcesContent":["export * from './components/OptionGroup/index';\n"]}
|
|
@@ -4,21 +4,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.Combobox = void 0;
|
|
7
|
-
|
|
8
7
|
const React = /*#__PURE__*/require("react");
|
|
9
|
-
|
|
10
8
|
const useCombobox_1 = /*#__PURE__*/require("./useCombobox");
|
|
11
|
-
|
|
12
9
|
const renderCombobox_1 = /*#__PURE__*/require("./renderCombobox");
|
|
13
|
-
|
|
14
10
|
const useComboboxStyles_1 = /*#__PURE__*/require("./useComboboxStyles");
|
|
15
|
-
|
|
16
11
|
const useComboboxContextValues_1 = /*#__PURE__*/require("../../contexts/useComboboxContextValues");
|
|
17
12
|
/**
|
|
18
13
|
* Combobox component: a selection control that allows users to choose from a set of possible options
|
|
19
14
|
*/
|
|
20
|
-
|
|
21
|
-
|
|
22
15
|
exports.Combobox = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
23
16
|
const state = useCombobox_1.useCombobox_unstable(props, ref);
|
|
24
17
|
const contextValues = useComboboxContextValues_1.useComboboxContextValues(state);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"mappings":";;;;;;AAAA;AACA;AACA;AACA;AAEA;AAGA;;;AAGaA,gBAAQ,gBAAuCC,KAAK,CAACC,UAAU,CAAC,CAACC,KAAK,EAAEC,GAAG,KAAI;EAC1F,MAAMC,KAAK,GAAGC,kCAAoB,CAACH,KAAK,EAAEC,GAAG,CAAC;EAC9C,MAAMG,aAAa,GAAGC,mDAAwB,CAACH,KAAK,CAAC;EAErDI,8CAA0B,CAACJ,KAAK,CAAC;EACjC,OAAOK,wCAAuB,CAACL,KAAK,EAAEE,aAAa,CAAC;AACtD,CAAC,CAAC;AAEFP,gBAAQ,CAACW,WAAW,GAAG,UAAU","names":["exports","React","forwardRef","props","ref","state","useCombobox_1","contextValues","useComboboxContextValues_1","useComboboxStyles_1","renderCombobox_1","displayName"],"sourceRoot":"../src/","sources":["packages/react-components/react-combobox/src/components/Combobox/Combobox.tsx"],"sourcesContent":["import * as React from 'react';\nimport { useCombobox_unstable } from './useCombobox';\nimport { renderCombobox_unstable } from './renderCombobox';\nimport { useComboboxStyles_unstable } from './useComboboxStyles';\nimport type { ComboboxProps } from './Combobox.types';\nimport { useComboboxContextValues } from '../../contexts/useComboboxContextValues';\nimport type { ForwardRefComponent } from '@fluentui/react-utilities';\n\n/**\n * Combobox component: a selection control that allows users to choose from a set of possible options\n */\nexport const Combobox: ForwardRefComponent<ComboboxProps> = React.forwardRef((props, ref) => {\n const state = useCombobox_unstable(props, ref);\n const contextValues = useComboboxContextValues(state);\n\n useComboboxStyles_unstable(state);\n return renderCombobox_unstable(state, contextValues);\n});\n\nCombobox.displayName = 'Combobox';\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"mappings":"","names":[],"sourceRoot":"../src/","sources":[],"sourcesContent":[]}
|
|
@@ -3,16 +3,10 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
|
|
7
6
|
const tslib_1 = /*#__PURE__*/require("tslib");
|
|
8
|
-
|
|
9
7
|
tslib_1.__exportStar(require("./Combobox"), exports);
|
|
10
|
-
|
|
11
8
|
tslib_1.__exportStar(require("./Combobox.types"), exports);
|
|
12
|
-
|
|
13
9
|
tslib_1.__exportStar(require("./renderCombobox"), exports);
|
|
14
|
-
|
|
15
10
|
tslib_1.__exportStar(require("./useCombobox"), exports);
|
|
16
|
-
|
|
17
11
|
tslib_1.__exportStar(require("./useComboboxStyles"), exports);
|
|
18
12
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"mappings":";;;;;;AAAAA;AACAA;AACAA;AACAA;AACAA","names":["tslib_1"],"sourceRoot":"../src/","sources":["packages/react-components/react-combobox/src/components/Combobox/index.ts"],"sourcesContent":["export * from './Combobox';\nexport * from './Combobox.types';\nexport * from './renderCombobox';\nexport * from './useCombobox';\nexport * from './useComboboxStyles';\n"]}
|
|
@@ -4,34 +4,31 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.renderCombobox_unstable = void 0;
|
|
7
|
-
|
|
8
7
|
const React = /*#__PURE__*/require("react");
|
|
9
|
-
|
|
10
8
|
const react_portal_1 = /*#__PURE__*/require("@fluentui/react-portal");
|
|
11
|
-
|
|
12
9
|
const react_utilities_1 = /*#__PURE__*/require("@fluentui/react-utilities");
|
|
13
|
-
|
|
14
10
|
const ComboboxContext_1 = /*#__PURE__*/require("../../contexts/ComboboxContext");
|
|
15
11
|
/**
|
|
16
12
|
* Render the final JSX of Combobox
|
|
17
13
|
*/
|
|
18
|
-
|
|
19
|
-
|
|
20
14
|
const renderCombobox_unstable = (state, contextValues) => {
|
|
21
15
|
const {
|
|
22
16
|
slots,
|
|
23
17
|
slotProps
|
|
24
18
|
} = react_utilities_1.getSlots(state);
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const popup = state.inlinePopup ? listbox : React.createElement(react_portal_1.Portal, null, listbox);
|
|
28
|
-
return React.createElement(slots.root, { ...slotProps.root
|
|
19
|
+
return React.createElement(slots.root, {
|
|
20
|
+
...slotProps.root
|
|
29
21
|
}, React.createElement(ComboboxContext_1.ComboboxContext.Provider, {
|
|
30
22
|
value: contextValues.combobox
|
|
31
|
-
}, React.createElement(slots.input, {
|
|
32
|
-
|
|
33
|
-
}),
|
|
23
|
+
}, React.createElement(slots.input, {
|
|
24
|
+
...slotProps.input
|
|
25
|
+
}), slots.expandIcon && React.createElement(slots.expandIcon, {
|
|
26
|
+
...slotProps.expandIcon
|
|
27
|
+
}), slots.listbox && (state.inlinePopup ? React.createElement(slots.listbox, {
|
|
28
|
+
...slotProps.listbox
|
|
29
|
+
}) : React.createElement(react_portal_1.Portal, null, React.createElement(slots.listbox, {
|
|
30
|
+
...slotProps.listbox
|
|
31
|
+
})))));
|
|
34
32
|
};
|
|
35
|
-
|
|
36
33
|
exports.renderCombobox_unstable = renderCombobox_unstable;
|
|
37
34
|
//# sourceMappingURL=renderCombobox.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"mappings":";;;;;;AAAA;AACA;AACA;AACA;AAGA;;;AAGO,MAAMA,uBAAuB,GAAG,CAACC,KAAoB,EAAEC,aAAoC,KAAI;EACpG,MAAM;IAAEC,KAAK;IAAEC;EAAS,CAAE,GAAGC,0BAAQ,CAAgBJ,KAAK,CAAC;EAE3D,OACEK,oBAACH,KAAK,CAACI,IAAI;IAAA,GAAKH,SAAS,CAACG;EAAI,GAC5BD,oBAACE,iCAAe,CAACC,QAAQ;IAACC,KAAK,EAAER,aAAa,CAACS;EAAQ,GACrDL,oBAACH,KAAK,CAACS,KAAK;IAAA,GAAKR,SAAS,CAACQ;EAAK,EAAI,EACnCT,KAAK,CAACU,UAAU,IAAIP,oBAACH,KAAK,CAACU,UAAU;IAAA,GAAKT,SAAS,CAACS;EAAU,EAAI,EAClEV,KAAK,CAACW,OAAO,KACXb,KAAK,CAACc,WAAW,GAChBT,oBAACH,KAAK,CAACW,OAAO;IAAA,GAAKV,SAAS,CAACU;EAAO,EAAI,GAExCR,oBAACU,qBAAM,QACLV,oBAACH,KAAK,CAACW,OAAO;IAAA,GAAKV,SAAS,CAACU;EAAO,EAAI,CAE3C,CAAC,CACqB,CAChB;AAEjB,CAAC;AAnBYG,+BAAuB","names":["renderCombobox_unstable","state","contextValues","slots","slotProps","react_utilities_1","React","root","ComboboxContext_1","Provider","value","combobox","input","expandIcon","listbox","inlinePopup","react_portal_1","exports"],"sourceRoot":"../src/","sources":["packages/react-components/react-combobox/src/components/Combobox/renderCombobox.tsx"],"sourcesContent":["import * as React from 'react';\nimport { Portal } from '@fluentui/react-portal';\nimport { getSlots } from '@fluentui/react-utilities';\nimport { ComboboxContext } from '../../contexts/ComboboxContext';\nimport type { ComboboxContextValues, ComboboxState, ComboboxSlots } from './Combobox.types';\n\n/**\n * Render the final JSX of Combobox\n */\nexport const renderCombobox_unstable = (state: ComboboxState, contextValues: ComboboxContextValues) => {\n const { slots, slotProps } = getSlots<ComboboxSlots>(state);\n\n return (\n <slots.root {...slotProps.root}>\n <ComboboxContext.Provider value={contextValues.combobox}>\n <slots.input {...slotProps.input} />\n {slots.expandIcon && <slots.expandIcon {...slotProps.expandIcon} />}\n {slots.listbox &&\n (state.inlinePopup ? (\n <slots.listbox {...slotProps.listbox} />\n ) : (\n <Portal>\n <slots.listbox {...slotProps.listbox} />\n </Portal>\n ))}\n </ComboboxContext.Provider>\n </slots.root>\n );\n};\n"]}
|
|
@@ -4,19 +4,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.useCombobox_unstable = void 0;
|
|
7
|
-
|
|
8
7
|
const React = /*#__PURE__*/require("react");
|
|
9
|
-
|
|
8
|
+
const keyboard_keys_1 = /*#__PURE__*/require("@fluentui/keyboard-keys");
|
|
10
9
|
const react_icons_1 = /*#__PURE__*/require("@fluentui/react-icons");
|
|
11
|
-
|
|
12
10
|
const react_utilities_1 = /*#__PURE__*/require("@fluentui/react-utilities");
|
|
13
|
-
|
|
11
|
+
const dropdownKeyActions_1 = /*#__PURE__*/require("../../utils/dropdownKeyActions");
|
|
14
12
|
const useComboboxBaseState_1 = /*#__PURE__*/require("../../utils/useComboboxBaseState");
|
|
15
|
-
|
|
16
|
-
const useTriggerListboxSlots_1 = /*#__PURE__*/require("../../utils/useTriggerListboxSlots");
|
|
17
|
-
|
|
18
13
|
const useComboboxPopup_1 = /*#__PURE__*/require("../../utils/useComboboxPopup");
|
|
19
|
-
|
|
14
|
+
const useTriggerListboxSlots_1 = /*#__PURE__*/require("../../utils/useTriggerListboxSlots");
|
|
20
15
|
const Listbox_1 = /*#__PURE__*/require("../Listbox/Listbox");
|
|
21
16
|
/**
|
|
22
17
|
* Create the state required to render Combobox.
|
|
@@ -27,10 +22,34 @@ const Listbox_1 = /*#__PURE__*/require("../Listbox/Listbox");
|
|
|
27
22
|
* @param props - props from this instance of Combobox
|
|
28
23
|
* @param ref - reference to root HTMLElement of Combobox
|
|
29
24
|
*/
|
|
30
|
-
|
|
31
|
-
|
|
32
25
|
const useCombobox_unstable = (props, ref) => {
|
|
33
|
-
|
|
26
|
+
var _a, _b;
|
|
27
|
+
const baseState = useComboboxBaseState_1.useComboboxBaseState({
|
|
28
|
+
...props,
|
|
29
|
+
editable: true
|
|
30
|
+
});
|
|
31
|
+
const {
|
|
32
|
+
activeOption,
|
|
33
|
+
clearSelection,
|
|
34
|
+
getIndexOfId,
|
|
35
|
+
getOptionsMatchingText,
|
|
36
|
+
hasFocus,
|
|
37
|
+
open,
|
|
38
|
+
selectOption,
|
|
39
|
+
selectedOptions,
|
|
40
|
+
setActiveOption,
|
|
41
|
+
setFocusVisible,
|
|
42
|
+
setOpen,
|
|
43
|
+
setValue,
|
|
44
|
+
value
|
|
45
|
+
} = baseState;
|
|
46
|
+
const {
|
|
47
|
+
disabled,
|
|
48
|
+
freeform,
|
|
49
|
+
inlinePopup,
|
|
50
|
+
multiselect
|
|
51
|
+
} = props;
|
|
52
|
+
const comboId = react_utilities_1.useId('combobox-');
|
|
34
53
|
const {
|
|
35
54
|
primary: triggerNativeProps,
|
|
36
55
|
root: rootNativeProps
|
|
@@ -39,22 +58,123 @@ const useCombobox_unstable = (props, ref) => {
|
|
|
39
58
|
primarySlotTagName: 'input',
|
|
40
59
|
excludedPropNames: ['children', 'size']
|
|
41
60
|
});
|
|
42
|
-
const
|
|
61
|
+
const rootRef = React.useRef(null);
|
|
62
|
+
const triggerRef = React.useRef(null);
|
|
63
|
+
// NVDA and JAWS have bugs that suppress reading the input value text when aria-activedescendant is set
|
|
64
|
+
// To prevent this, we clear the HTML attribute (but save the state) when a user presses left/right arrows
|
|
65
|
+
// ref: https://github.com/microsoft/fluentui/issues/26359#issuecomment-1397759888
|
|
66
|
+
const [hideActiveDescendant, setHideActiveDescendant] = React.useState(false);
|
|
67
|
+
// calculate listbox width style based on trigger width
|
|
68
|
+
const [popupDimensions, setPopupDimensions] = React.useState();
|
|
69
|
+
React.useEffect(() => {
|
|
70
|
+
var _a;
|
|
71
|
+
// only recalculate width when opening
|
|
72
|
+
if (open) {
|
|
73
|
+
const width = `${(_a = rootRef.current) === null || _a === void 0 ? void 0 : _a.clientWidth}px`;
|
|
74
|
+
if (width !== (popupDimensions === null || popupDimensions === void 0 ? void 0 : popupDimensions.width)) {
|
|
75
|
+
setPopupDimensions({
|
|
76
|
+
width
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}, [open, popupDimensions]);
|
|
81
|
+
// set active option and selection based on typing
|
|
82
|
+
const getOptionFromInput = inputValue => {
|
|
83
|
+
var _a;
|
|
84
|
+
const searchString = inputValue === null || inputValue === void 0 ? void 0 : inputValue.trim().toLowerCase();
|
|
85
|
+
if (!searchString || searchString.length === 0) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
const matcher = optionText => optionText.toLowerCase().indexOf(searchString) === 0;
|
|
89
|
+
const matches = getOptionsMatchingText(matcher);
|
|
90
|
+
// return first matching option after the current active option, looping back to the top
|
|
91
|
+
if (matches.length > 1 && activeOption) {
|
|
92
|
+
const startIndex = getIndexOfId(activeOption.id);
|
|
93
|
+
const nextMatch = matches.find(option => getIndexOfId(option.id) >= startIndex);
|
|
94
|
+
return nextMatch !== null && nextMatch !== void 0 ? nextMatch : matches[0];
|
|
95
|
+
}
|
|
96
|
+
return (_a = matches[0]) !== null && _a !== void 0 ? _a : undefined;
|
|
97
|
+
};
|
|
98
|
+
/* Handle typed input */
|
|
99
|
+
// reset any typed value when an option is selected
|
|
100
|
+
baseState.selectOption = (ev, option) => {
|
|
101
|
+
setValue(undefined);
|
|
102
|
+
selectOption(ev, option);
|
|
103
|
+
};
|
|
104
|
+
const onTriggerBlur = ev => {
|
|
105
|
+
// handle selection and updating value if freeform is false
|
|
106
|
+
if (!baseState.open && !freeform) {
|
|
107
|
+
// select matching option, if the value fully matches
|
|
108
|
+
if (value && activeOption && value.trim().toLowerCase() === (activeOption === null || activeOption === void 0 ? void 0 : activeOption.value.toLowerCase())) {
|
|
109
|
+
baseState.selectOption(ev, activeOption);
|
|
110
|
+
}
|
|
111
|
+
// reset typed value when the input loses focus while collapsed, unless freeform is true
|
|
112
|
+
setValue(undefined);
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
baseState.setOpen = (ev, newState) => {
|
|
116
|
+
if (disabled) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
if (!newState && !freeform) {
|
|
120
|
+
setValue(undefined);
|
|
121
|
+
}
|
|
122
|
+
setOpen(ev, newState);
|
|
123
|
+
};
|
|
124
|
+
// update value and active option based on input
|
|
125
|
+
const onTriggerChange = ev => {
|
|
126
|
+
const inputValue = ev.target.value;
|
|
127
|
+
// update uncontrolled value
|
|
128
|
+
baseState.setValue(inputValue);
|
|
129
|
+
// handle updating active option based on input
|
|
130
|
+
const matchingOption = getOptionFromInput(inputValue);
|
|
131
|
+
setActiveOption(matchingOption);
|
|
132
|
+
setFocusVisible(true);
|
|
133
|
+
// clear selection for single-select if the input value no longer matches the selection
|
|
134
|
+
if (!multiselect && selectedOptions.length === 1 && (inputValue.length < 1 || selectedOptions[0].indexOf(inputValue) !== 0)) {
|
|
135
|
+
clearSelection(ev);
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
// open Combobox when typing
|
|
139
|
+
const onTriggerKeyDown = ev => {
|
|
140
|
+
if (!open && dropdownKeyActions_1.getDropdownActionFromKey(ev) === 'Type') {
|
|
141
|
+
baseState.setOpen(ev, true);
|
|
142
|
+
}
|
|
143
|
+
// clear activedescendant when moving the text insertion cursor
|
|
144
|
+
if (ev.key === keyboard_keys_1.ArrowLeft || ev.key === keyboard_keys_1.ArrowRight) {
|
|
145
|
+
setHideActiveDescendant(true);
|
|
146
|
+
} else {
|
|
147
|
+
setHideActiveDescendant(false);
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
// resolve input and listbox slot props
|
|
151
|
+
let triggerSlot;
|
|
152
|
+
let listboxSlot;
|
|
153
|
+
triggerSlot = react_utilities_1.resolveShorthand(props.input, {
|
|
43
154
|
required: true,
|
|
44
155
|
defaultProps: {
|
|
45
|
-
|
|
46
|
-
/* Combobox does not yet support allowFreeForm */
|
|
47
|
-
},
|
|
156
|
+
ref: react_utilities_1.useMergedRefs((_a = props.input) === null || _a === void 0 ? void 0 : _a.ref, triggerRef),
|
|
48
157
|
type: 'text',
|
|
49
|
-
value:
|
|
158
|
+
value: value !== null && value !== void 0 ? value : '',
|
|
50
159
|
...triggerNativeProps
|
|
51
160
|
}
|
|
52
161
|
});
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
162
|
+
triggerSlot.onChange = react_utilities_1.mergeCallbacks(triggerSlot.onChange, onTriggerChange);
|
|
163
|
+
triggerSlot.onBlur = react_utilities_1.mergeCallbacks(triggerSlot.onBlur, onTriggerBlur);
|
|
164
|
+
triggerSlot.onKeyDown = react_utilities_1.mergeCallbacks(triggerSlot.onKeyDown, onTriggerKeyDown);
|
|
165
|
+
// only resolve listbox slot if needed
|
|
166
|
+
listboxSlot = open || hasFocus ? react_utilities_1.resolveShorthand(props.listbox, {
|
|
167
|
+
required: true,
|
|
168
|
+
defaultProps: {
|
|
169
|
+
children: props.children,
|
|
170
|
+
style: popupDimensions
|
|
171
|
+
}
|
|
172
|
+
}) : undefined;
|
|
173
|
+
[triggerSlot, listboxSlot] = useComboboxPopup_1.useComboboxPopup(props, triggerSlot, listboxSlot);
|
|
174
|
+
[triggerSlot, listboxSlot] = useTriggerListboxSlots_1.useTriggerListboxSlots(props, baseState, ref, triggerSlot, listboxSlot);
|
|
175
|
+
if (hideActiveDescendant) {
|
|
176
|
+
triggerSlot['aria-activedescendant'] = undefined;
|
|
177
|
+
}
|
|
58
178
|
const state = {
|
|
59
179
|
components: {
|
|
60
180
|
root: 'div',
|
|
@@ -65,7 +185,7 @@ const useCombobox_unstable = (props, ref) => {
|
|
|
65
185
|
root: react_utilities_1.resolveShorthand(props.root, {
|
|
66
186
|
required: true,
|
|
67
187
|
defaultProps: {
|
|
68
|
-
|
|
188
|
+
'aria-owns': !inlinePopup ? listboxSlot === null || listboxSlot === void 0 ? void 0 : listboxSlot.id : undefined,
|
|
69
189
|
...rootNativeProps
|
|
70
190
|
}
|
|
71
191
|
}),
|
|
@@ -74,13 +194,59 @@ const useCombobox_unstable = (props, ref) => {
|
|
|
74
194
|
expandIcon: react_utilities_1.resolveShorthand(props.expandIcon, {
|
|
75
195
|
required: true,
|
|
76
196
|
defaultProps: {
|
|
77
|
-
|
|
197
|
+
'aria-expanded': open,
|
|
198
|
+
children: React.createElement(react_icons_1.ChevronDownRegular, null),
|
|
199
|
+
role: 'button'
|
|
78
200
|
}
|
|
79
201
|
}),
|
|
80
202
|
...baseState
|
|
81
203
|
};
|
|
204
|
+
state.root.ref = react_utilities_1.useMergedRefs(state.root.ref, rootRef);
|
|
205
|
+
/* handle open/close + focus change when clicking expandIcon */
|
|
206
|
+
const {
|
|
207
|
+
onMouseDown: onIconMouseDown,
|
|
208
|
+
onClick: onIconClick
|
|
209
|
+
} = state.expandIcon || {};
|
|
210
|
+
const onExpandIconMouseDown = react_utilities_1.useEventCallback(react_utilities_1.mergeCallbacks(onIconMouseDown, () => {
|
|
211
|
+
// do not dismiss on blur when closing via clicking the icon
|
|
212
|
+
if (open) {
|
|
213
|
+
baseState.ignoreNextBlur.current = true;
|
|
214
|
+
}
|
|
215
|
+
}));
|
|
216
|
+
const onExpandIconClick = react_utilities_1.useEventCallback(react_utilities_1.mergeCallbacks(onIconClick, event => {
|
|
217
|
+
var _a;
|
|
218
|
+
// open and set focus
|
|
219
|
+
state.setOpen(event, !state.open);
|
|
220
|
+
(_a = triggerRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
221
|
+
// set focus visible=false, since this can only be done with the mouse/pointer
|
|
222
|
+
setFocusVisible(false);
|
|
223
|
+
}));
|
|
224
|
+
if (state.expandIcon) {
|
|
225
|
+
state.expandIcon.onMouseDown = onExpandIconMouseDown;
|
|
226
|
+
state.expandIcon.onClick = onExpandIconClick;
|
|
227
|
+
// If there is no explicit aria-label, calculate default accName attribute for expandIcon button,
|
|
228
|
+
// using the following steps:
|
|
229
|
+
// 1. If there is an aria-label, it is "Open [aria-label]"
|
|
230
|
+
// 2. If there is an aria-labelledby, it is "Open [aria-labelledby target]" (using aria-labelledby + ids)
|
|
231
|
+
// 3. If there is no aria-label/ledby attr, it falls back to "Open"
|
|
232
|
+
// We can't fall back to a label/htmlFor name because of https://github.com/w3c/accname/issues/179
|
|
233
|
+
const hasExpandLabel = state.expandIcon['aria-label'] || state.expandIcon['aria-labelledby'];
|
|
234
|
+
const defaultOpenString = 'Open'; // this is english-only since it is the fallback
|
|
235
|
+
if (!hasExpandLabel) {
|
|
236
|
+
if (props['aria-labelledby']) {
|
|
237
|
+
const chevronId = (_b = state.expandIcon.id) !== null && _b !== void 0 ? _b : `${comboId}-chevron`;
|
|
238
|
+
const chevronLabelledBy = `${chevronId} ${state.input['aria-labelledby']}`;
|
|
239
|
+
state.expandIcon['aria-label'] = defaultOpenString;
|
|
240
|
+
state.expandIcon.id = chevronId;
|
|
241
|
+
state.expandIcon['aria-labelledby'] = chevronLabelledBy;
|
|
242
|
+
} else if (props['aria-label']) {
|
|
243
|
+
state.expandIcon['aria-label'] = `${defaultOpenString} ${props['aria-label']}`;
|
|
244
|
+
} else {
|
|
245
|
+
state.expandIcon['aria-label'] = defaultOpenString;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
82
249
|
return state;
|
|
83
250
|
};
|
|
84
|
-
|
|
85
251
|
exports.useCombobox_unstable = useCombobox_unstable;
|
|
86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CAAC,gBAAD,EAAmB,gBAAnB,IAAuC,kBAAA,CAAA,gBAAA,CAAiB,KAAjB,EAAwB,gBAAxB,EAA0C,gBAA1C,CAA7C;EACA,MAAM,CAAC,WAAD,EAAc,WAAd,IAA6B,wBAAA,CAAA,sBAAA,CAAuB,KAAvB,EAA8B,SAA9B,EAAyC,GAAzC,EAA8C,gBAA9C,EAAgE,gBAAhE,CAAnC;EAEA,MAAM,KAAK,GAAkB;IAC3B,UAAU,EAAE;MACV,IAAI,EAAE,KADI;MAEV,KAAK,EAAE,OAFG;MAGV,UAAU,EAAE,MAHF;MAIV,OAAO,EAAE,SAAA,CAAA;IAJC,CADe;IAO3B,IAAI,EAAE,iBAAA,CAAA,gBAAA,CAAiB,KAAK,CAAC,IAAvB,EAA6B;MACjC,QAAQ,EAAE,IADuB;MAEjC,YAAY,EAAE;QACZ,QAAQ,EAAE,KAAK,CAAC,QADJ;QAEZ,GAAG;MAFS;IAFmB,CAA7B,CAPqB;IAc3B,KAAK,EAAE,WAdoB;IAe3B,OAAO,EAAE,WAfkB;IAgB3B,UAAU,EAAE,iBAAA,CAAA,gBAAA,CAAiB,KAAK,CAAC,UAAvB,EAAmC;MAC7C,QAAQ,EAAE,IADmC;MAE7C,YAAY,EAAE;QACZ,QAAQ,EAAE,KAAA,CAAA,aAAA,CAAC,aAAA,CAAA,kBAAD,EAAgB,IAAhB;MADE;IAF+B,CAAnC,CAhBe;IAsB3B,GAAG;EAtBwB,CAA7B;EAyBA,OAAO,KAAP;AACD,CApDM;;AAAM,OAAA,CAAA,oBAAA,GAAoB,oBAApB","sourcesContent":["import * as React from 'react';\nimport { ChevronDownRegular as ChevronDownIcon } from '@fluentui/react-icons';\nimport { getPartitionedNativeProps, resolveShorthand } from '@fluentui/react-utilities';\nimport { useComboboxBaseState } from '../../utils/useComboboxBaseState';\nimport { useTriggerListboxSlots } from '../../utils/useTriggerListboxSlots';\nimport { useComboboxPopup } from '../../utils/useComboboxPopup';\nimport { Listbox } from '../Listbox/Listbox';\nimport type { ComboboxProps, ComboboxState } from './Combobox.types';\n\n/**\n * Create the state required to render Combobox.\n *\n * The returned state can be modified with hooks such as useComboboxStyles_unstable,\n * before being passed to renderCombobox_unstable.\n *\n * @param props - props from this instance of Combobox\n * @param ref - reference to root HTMLElement of Combobox\n */\nexport const useCombobox_unstable = (props: ComboboxProps, ref: React.Ref<HTMLInputElement>): ComboboxState => {\n const baseState = useComboboxBaseState(props);\n\n const { primary: triggerNativeProps, root: rootNativeProps } = getPartitionedNativeProps({\n props,\n primarySlotTagName: 'input',\n excludedPropNames: ['children', 'size'],\n });\n\n const triggerShorthand = resolveShorthand(props.input, {\n required: true,\n defaultProps: {\n onChange: () => {\n /* Combobox does not yet support allowFreeForm */\n },\n type: 'text',\n value: baseState.value,\n ...triggerNativeProps,\n },\n });\n\n const listboxShorthand = resolveShorthand(props.listbox, { required: true });\n\n const [triggerWithPopup, listboxWithPopup] = useComboboxPopup(props, triggerShorthand, listboxShorthand);\n const [triggerSlot, listboxSlot] = useTriggerListboxSlots(props, baseState, ref, triggerWithPopup, listboxWithPopup);\n\n const state: ComboboxState = {\n components: {\n root: 'div',\n input: 'input',\n expandIcon: 'span',\n listbox: Listbox,\n },\n root: resolveShorthand(props.root, {\n required: true,\n defaultProps: {\n children: props.children,\n ...rootNativeProps,\n },\n }),\n input: triggerSlot,\n listbox: listboxSlot,\n expandIcon: resolveShorthand(props.expandIcon, {\n required: true,\n defaultProps: {\n children: <ChevronDownIcon />,\n },\n }),\n ...baseState,\n };\n\n return state;\n};\n"],"sourceRoot":"../src/"}
|
|
1
|
+
{"version":3,"mappings":";;;;;;AAAA;AACA;AACA;AACA;AAQA;AACA;AACA;AACA;AACA;AAMA;;;;;;;;;AASO,MAAMA,oBAAoB,GAAG,CAACC,KAAoB,EAAEC,GAAgC,KAAmB;;EAC5G,MAAMC,SAAS,GAAGC,2CAAoB,CAAC;IAAE,GAAGH,KAAK;IAAEI,QAAQ,EAAE;EAAI,CAAE,CAAC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AAEwD,KAAK,EAAE;IAE3B;IACAnF,eAAe,CAAC,KAAK,CAAC;EACxB,CAAC,CAAC,CACH;EAED,IAAIqE,KAAK,CAACE,UAAU,EAAE;IACpBF,KAAK,CAACE,UAAU,CAACI,WAAW,GAAGI,qBAAqB;IACpDV,KAAK,CAACE,UAAU,CAACM,OAAO,GAAGI,iBAAiB;IAE5C;IACA;IACA;IACA;IACA;IACA;IACA,MAAMG,cAAc,GAAGf,KAAK,CAACE,UAAU,CAAC,YAAY,CAAC,IAAIF,KAAK,CAACE,UAAU,CAAC,iBAAiB,CAAC;IAC5F,MAAMc,iBAAiB,GAAG,MAAM,CAAC,CAAC;IAClC,IAAI,CAACD,cAAc,EAAE;MACnB,IAAIlG,KAAK,CAAC,iBAAiB,CAAC,EAAE;QAC5B,MAAMoG,SAAS,GAAG,WAAK,CAACf,UAAU,CAAC/B,EAAE,mCAAI,GAAGhC,OAAO,UAAU;QAC7D,MAAM+E,iBAAiB,GAAG,GAAGD,SAAS,IAAIjB,KAAK,CAACZ,KAAK,CAAC,iBAAiB,CAAC,EAAE;QAE1EY,KAAK,CAACE,UAAU,CAAC,YAAY,CAAC,GAAGc,iBAAiB;QAClDhB,KAAK,CAACE,UAAU,CAAC/B,EAAE,GAAG8C,SAAS;QAC/BjB,KAAK,CAACE,UAAU,CAAC,iBAAiB,CAAC,GAAGgB,iBAAiB;OACxD,MAAM,IAAIrG,KAAK,CAAC,YAAY,CAAC,EAAE;QAC9BmF,KAAK,CAACE,UAAU,CAAC,YAAY,CAAC,GAAG,GAAGc,iBAAiB,IAAInG,KAAK,CAAC,YAAY,CAAC,EAAE;OAC/E,MAAM;QACLmF,KAAK,CAACE,UAAU,CAAC,YAAY,CAAC,GAAGc,iBAAiB;;;;EAKxD,OAAOhB,KAAK;AACd,CAAC;AA7PYmB,4BAAoB","names":["useCombobox_unstable","props","ref","baseState","useComboboxBaseState_1","editable","activeOption","clearSelection","getIndexOfId","getOptionsMatchingText","hasFocus","open","selectOption","selectedOptions","setActiveOption","setFocusVisible","setOpen","setValue","value","disabled","freeform","inlinePopup","multiselect","comboId","react_utilities_1","primary","triggerNativeProps","root","rootNativeProps","primarySlotTagName","excludedPropNames","rootRef","React","useRef","triggerRef","hideActiveDescendant","setHideActiveDescendant","useState","popupDimensions","setPopupDimensions","useEffect","width","current","clientWidth","getOptionFromInput","inputValue","searchString","trim","toLowerCase","length","matcher","optionText","indexOf","matches","startIndex","id","nextMatch","find","option","undefined","ev","onTriggerBlur","newState","onTriggerChange","target","matchingOption","onTriggerKeyDown","dropdownKeyActions_1","key","keyboard_keys_1","triggerSlot","listboxSlot","input","required","defaultProps","type","onChange","onBlur","onKeyDown","listbox","children","style","useComboboxPopup_1","useTriggerListboxSlots_1","state","components","expandIcon","Listbox_1","react_icons_1","role","onMouseDown","onIconMouseDown","onClick","onIconClick","onExpandIconMouseDown","ignoreNextBlur","onExpandIconClick","event","focus","hasExpandLabel","defaultOpenString","chevronId","chevronLabelledBy","exports"],"sourceRoot":"../src/","sources":["packages/react-components/react-combobox/src/components/Combobox/useCombobox.tsx"],"sourcesContent":["import * as React from 'react';\nimport { ArrowLeft, ArrowRight } from '@fluentui/keyboard-keys';\nimport { ChevronDownRegular as ChevronDownIcon } from '@fluentui/react-icons';\nimport {\n getPartitionedNativeProps,\n resolveShorthand,\n mergeCallbacks,\n useEventCallback,\n useId,\n useMergedRefs,\n} from '@fluentui/react-utilities';\nimport { getDropdownActionFromKey } from '../../utils/dropdownKeyActions';\nimport { useComboboxBaseState } from '../../utils/useComboboxBaseState';\nimport { useComboboxPopup } from '../../utils/useComboboxPopup';\nimport { useTriggerListboxSlots } from '../../utils/useTriggerListboxSlots';\nimport { Listbox } from '../Listbox/Listbox';\nimport type { Slot } from '@fluentui/react-utilities';\nimport type { SelectionEvents } from '../../utils/Selection.types';\nimport type { OptionValue } from '../../utils/OptionCollection.types';\nimport type { ComboboxProps, ComboboxState } from './Combobox.types';\n\n/**\n * Create the state required to render Combobox.\n *\n * The returned state can be modified with hooks such as useComboboxStyles_unstable,\n * before being passed to renderCombobox_unstable.\n *\n * @param props - props from this instance of Combobox\n * @param ref - reference to root HTMLElement of Combobox\n */\nexport const useCombobox_unstable = (props: ComboboxProps, ref: React.Ref<HTMLInputElement>): ComboboxState => {\n const baseState = useComboboxBaseState({ ...props, editable: true });\n const {\n activeOption,\n clearSelection,\n getIndexOfId,\n getOptionsMatchingText,\n hasFocus,\n open,\n selectOption,\n selectedOptions,\n setActiveOption,\n setFocusVisible,\n setOpen,\n setValue,\n value,\n } = baseState;\n const { disabled, freeform, inlinePopup, multiselect } = props;\n const comboId = useId('combobox-');\n\n const { primary: triggerNativeProps, root: rootNativeProps } = getPartitionedNativeProps({\n props,\n primarySlotTagName: 'input',\n excludedPropNames: ['children', 'size'],\n });\n\n const rootRef = React.useRef<HTMLDivElement>(null);\n const triggerRef = React.useRef<HTMLInputElement>(null);\n\n // NVDA and JAWS have bugs that suppress reading the input value text when aria-activedescendant is set\n // To prevent this, we clear the HTML attribute (but save the state) when a user presses left/right arrows\n // ref: https://github.com/microsoft/fluentui/issues/26359#issuecomment-1397759888\n const [hideActiveDescendant, setHideActiveDescendant] = React.useState(false);\n\n // calculate listbox width style based on trigger width\n const [popupDimensions, setPopupDimensions] = React.useState<{ width: string }>();\n React.useEffect(() => {\n // only recalculate width when opening\n if (open) {\n const width = `${rootRef.current?.clientWidth}px`;\n if (width !== popupDimensions?.width) {\n setPopupDimensions({ width });\n }\n }\n }, [open, popupDimensions]);\n\n // set active option and selection based on typing\n const getOptionFromInput = (inputValue: string): OptionValue | undefined => {\n const searchString = inputValue?.trim().toLowerCase();\n\n if (!searchString || searchString.length === 0) {\n return;\n }\n\n const matcher = (optionText: string) => optionText.toLowerCase().indexOf(searchString) === 0;\n const matches = getOptionsMatchingText(matcher);\n\n // return first matching option after the current active option, looping back to the top\n if (matches.length > 1 && activeOption) {\n const startIndex = getIndexOfId(activeOption.id);\n const nextMatch = matches.find(option => getIndexOfId(option.id) >= startIndex);\n return nextMatch ?? matches[0];\n }\n\n return matches[0] ?? undefined;\n };\n\n /* Handle typed input */\n\n // reset any typed value when an option is selected\n baseState.selectOption = (ev: SelectionEvents, option: OptionValue) => {\n setValue(undefined);\n selectOption(ev, option);\n };\n\n const onTriggerBlur = (ev: React.FocusEvent<HTMLInputElement>) => {\n // handle selection and updating value if freeform is false\n if (!baseState.open && !freeform) {\n // select matching option, if the value fully matches\n if (value && activeOption && value.trim().toLowerCase() === activeOption?.value.toLowerCase()) {\n baseState.selectOption(ev, activeOption);\n }\n\n // reset typed value when the input loses focus while collapsed, unless freeform is true\n setValue(undefined);\n }\n };\n\n baseState.setOpen = (ev, newState: boolean) => {\n if (disabled) {\n return;\n }\n\n if (!newState && !freeform) {\n setValue(undefined);\n }\n\n setOpen(ev, newState);\n };\n\n // update value and active option based on input\n const onTriggerChange = (ev: React.ChangeEvent<HTMLInputElement>) => {\n const inputValue = ev.target.value;\n // update uncontrolled value\n baseState.setValue(inputValue);\n\n // handle updating active option based on input\n const matchingOption = getOptionFromInput(inputValue);\n setActiveOption(matchingOption);\n\n setFocusVisible(true);\n\n // clear selection for single-select if the input value no longer matches the selection\n if (\n !multiselect &&\n selectedOptions.length === 1 &&\n (inputValue.length < 1 || selectedOptions[0].indexOf(inputValue) !== 0)\n ) {\n clearSelection(ev);\n }\n };\n\n // open Combobox when typing\n const onTriggerKeyDown = (ev: React.KeyboardEvent<HTMLInputElement>) => {\n if (!open && getDropdownActionFromKey(ev) === 'Type') {\n baseState.setOpen(ev, true);\n }\n\n // clear activedescendant when moving the text insertion cursor\n if (ev.key === ArrowLeft || ev.key === ArrowRight) {\n setHideActiveDescendant(true);\n } else {\n setHideActiveDescendant(false);\n }\n };\n\n // resolve input and listbox slot props\n let triggerSlot: Slot<'input'>;\n let listboxSlot: Slot<typeof Listbox> | undefined;\n\n triggerSlot = resolveShorthand(props.input, {\n required: true,\n defaultProps: {\n ref: useMergedRefs(props.input?.ref, triggerRef),\n type: 'text',\n value: value ?? '',\n ...triggerNativeProps,\n },\n });\n\n triggerSlot.onChange = mergeCallbacks(triggerSlot.onChange, onTriggerChange);\n triggerSlot.onBlur = mergeCallbacks(triggerSlot.onBlur, onTriggerBlur);\n triggerSlot.onKeyDown = mergeCallbacks(triggerSlot.onKeyDown, onTriggerKeyDown);\n\n // only resolve listbox slot if needed\n listboxSlot =\n open || hasFocus\n ? resolveShorthand(props.listbox, {\n required: true,\n defaultProps: {\n children: props.children,\n style: popupDimensions,\n },\n })\n : undefined;\n\n [triggerSlot, listboxSlot] = useComboboxPopup(props, triggerSlot, listboxSlot);\n [triggerSlot, listboxSlot] = useTriggerListboxSlots(props, baseState, ref, triggerSlot, listboxSlot);\n\n if (hideActiveDescendant) {\n triggerSlot['aria-activedescendant'] = undefined;\n }\n\n const state: ComboboxState = {\n components: {\n root: 'div',\n input: 'input',\n expandIcon: 'span',\n listbox: Listbox,\n },\n root: resolveShorthand(props.root, {\n required: true,\n defaultProps: {\n 'aria-owns': !inlinePopup ? listboxSlot?.id : undefined,\n ...rootNativeProps,\n },\n }),\n input: triggerSlot,\n listbox: listboxSlot,\n expandIcon: resolveShorthand(props.expandIcon, {\n required: true,\n defaultProps: {\n 'aria-expanded': open,\n children: <ChevronDownIcon />,\n role: 'button',\n },\n }),\n ...baseState,\n };\n\n state.root.ref = useMergedRefs(state.root.ref, rootRef);\n\n /* handle open/close + focus change when clicking expandIcon */\n const { onMouseDown: onIconMouseDown, onClick: onIconClick } = state.expandIcon || {};\n const onExpandIconMouseDown = useEventCallback(\n mergeCallbacks(onIconMouseDown, () => {\n // do not dismiss on blur when closing via clicking the icon\n if (open) {\n baseState.ignoreNextBlur.current = true;\n }\n }),\n );\n\n const onExpandIconClick = useEventCallback(\n mergeCallbacks(onIconClick, (event: React.MouseEvent<HTMLSpanElement>) => {\n // open and set focus\n state.setOpen(event, !state.open);\n triggerRef.current?.focus();\n\n // set focus visible=false, since this can only be done with the mouse/pointer\n setFocusVisible(false);\n }),\n );\n\n if (state.expandIcon) {\n state.expandIcon.onMouseDown = onExpandIconMouseDown;\n state.expandIcon.onClick = onExpandIconClick;\n\n // If there is no explicit aria-label, calculate default accName attribute for expandIcon button,\n // using the following steps:\n // 1. If there is an aria-label, it is \"Open [aria-label]\"\n // 2. If there is an aria-labelledby, it is \"Open [aria-labelledby target]\" (using aria-labelledby + ids)\n // 3. If there is no aria-label/ledby attr, it falls back to \"Open\"\n // We can't fall back to a label/htmlFor name because of https://github.com/w3c/accname/issues/179\n const hasExpandLabel = state.expandIcon['aria-label'] || state.expandIcon['aria-labelledby'];\n const defaultOpenString = 'Open'; // this is english-only since it is the fallback\n if (!hasExpandLabel) {\n if (props['aria-labelledby']) {\n const chevronId = state.expandIcon.id ?? `${comboId}-chevron`;\n const chevronLabelledBy = `${chevronId} ${state.input['aria-labelledby']}`;\n\n state.expandIcon['aria-label'] = defaultOpenString;\n state.expandIcon.id = chevronId;\n state.expandIcon['aria-labelledby'] = chevronLabelledBy;\n } else if (props['aria-label']) {\n state.expandIcon['aria-label'] = `${defaultOpenString} ${props['aria-label']}`;\n } else {\n state.expandIcon['aria-label'] = defaultOpenString;\n }\n }\n }\n\n return state;\n};\n"]}
|