@fluentui/react-combobox 9.0.0-beta.19 → 9.0.0-beta.21
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 +117 -1
- package/CHANGELOG.md +32 -2
- package/lib/components/Combobox/Combobox.js +0 -1
- package/lib/components/Combobox/Combobox.js.map +1 -1
- package/lib/components/Combobox/renderCombobox.js +10 -6
- package/lib/components/Combobox/renderCombobox.js.map +1 -1
- package/lib/components/Combobox/useCombobox.js +41 -53
- package/lib/components/Combobox/useCombobox.js.map +1 -1
- package/lib/components/Combobox/useComboboxStyles.js +209 -217
- package/lib/components/Combobox/useComboboxStyles.js.map +1 -1
- package/lib/components/ComboboxField/ComboboxField.js.map +1 -1
- package/lib/components/Dropdown/Dropdown.js +0 -1
- package/lib/components/Dropdown/Dropdown.js.map +1 -1
- package/lib/components/Dropdown/renderDropdown.js +10 -6
- package/lib/components/Dropdown/renderDropdown.js.map +1 -1
- package/lib/components/Dropdown/useDropdown.js +20 -32
- package/lib/components/Dropdown/useDropdown.js.map +1 -1
- package/lib/components/Dropdown/useDropdownStyles.js +199 -206
- 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/renderListbox.js +2 -2
- package/lib/components/Listbox/renderListbox.js.map +1 -1
- package/lib/components/Listbox/useListbox.js +6 -13
- package/lib/components/Listbox/useListbox.js.map +1 -1
- package/lib/components/Listbox/useListboxStyles.js +18 -21
- 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/renderOption.js +4 -3
- package/lib/components/Option/renderOption.js.map +1 -1
- package/lib/components/Option/useOption.js +20 -32
- package/lib/components/Option/useOption.js.map +1 -1
- package/lib/components/Option/useOptionStyles.js +74 -79
- 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/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 +8 -11
- package/lib/contexts/ComboboxContext.js.map +1 -1
- package/lib/contexts/ListboxContext.js +6 -9
- package/lib/contexts/ListboxContext.js.map +1 -1
- package/lib/contexts/useComboboxContextValues.js.map +1 -1
- package/lib/contexts/useListboxContextValues.js +2 -2
- package/lib/contexts/useListboxContextValues.js.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/utils/dropdownKeyActions.js +12 -33
- package/lib/utils/dropdownKeyActions.js.map +1 -1
- package/lib/utils/internalTokens.js.map +1 -1
- package/lib/utils/useComboboxBaseState.js +23 -27
- package/lib/utils/useComboboxBaseState.js.map +1 -1
- package/lib/utils/useComboboxPopup.js +6 -4
- package/lib/utils/useComboboxPopup.js.map +1 -1
- package/lib/utils/useOptionCollection.js +10 -20
- package/lib/utils/useOptionCollection.js.map +1 -1
- package/lib/utils/useScrollOptionsIntoView.js +2 -5
- package/lib/utils/useScrollOptionsIntoView.js.map +1 -1
- package/lib/utils/useSelection.js +7 -12
- package/lib/utils/useSelection.js.map +1 -1
- package/lib/utils/useTriggerListboxSlots.js +31 -39
- package/lib/utils/useTriggerListboxSlots.js.map +1 -1
- package/lib-commonjs/Combobox.js +0 -2
- package/lib-commonjs/Combobox.js.map +1 -1
- package/lib-commonjs/ComboboxField.js +0 -2
- package/lib-commonjs/ComboboxField.js.map +1 -1
- 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 +10 -12
- package/lib-commonjs/components/Combobox/renderCombobox.js.map +1 -1
- package/lib-commonjs/components/Combobox/useCombobox.js +41 -63
- package/lib-commonjs/components/Combobox/useCombobox.js.map +1 -1
- package/lib-commonjs/components/Combobox/useComboboxStyles.js +209 -222
- package/lib-commonjs/components/Combobox/useComboboxStyles.js.map +1 -1
- package/lib-commonjs/components/ComboboxField/ComboboxField.js +0 -4
- package/lib-commonjs/components/ComboboxField/ComboboxField.js.map +1 -1
- package/lib-commonjs/components/ComboboxField/index.js +0 -2
- package/lib-commonjs/components/ComboboxField/index.js.map +1 -1
- 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 +10 -12
- package/lib-commonjs/components/Dropdown/renderDropdown.js.map +1 -1
- package/lib-commonjs/components/Dropdown/useDropdown.js +20 -43
- package/lib-commonjs/components/Dropdown/useDropdown.js.map +1 -1
- package/lib-commonjs/components/Dropdown/useDropdownStyles.js +199 -211
- 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 +6 -23
- package/lib-commonjs/components/Listbox/useListbox.js.map +1 -1
- package/lib-commonjs/components/Listbox/useListboxStyles.js +18 -25
- 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 +20 -39
- package/lib-commonjs/components/Option/useOption.js.map +1 -1
- package/lib-commonjs/components/Option/useOptionStyles.js +74 -83
- 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 +8 -13
- package/lib-commonjs/contexts/ComboboxContext.js.map +1 -1
- package/lib-commonjs/contexts/ListboxContext.js +6 -11
- package/lib-commonjs/contexts/ListboxContext.js.map +1 -1
- package/lib-commonjs/contexts/useComboboxContextValues.js +0 -2
- package/lib-commonjs/contexts/useComboboxContextValues.js.map +1 -1
- package/lib-commonjs/contexts/useListboxContextValues.js +2 -6
- package/lib-commonjs/contexts/useListboxContextValues.js.map +1 -1
- package/lib-commonjs/index.js +0 -20
- 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 +12 -37
- package/lib-commonjs/utils/dropdownKeyActions.js.map +1 -1
- package/lib-commonjs/utils/internalTokens.js.map +1 -1
- package/lib-commonjs/utils/useComboboxBaseState.js +23 -33
- package/lib-commonjs/utils/useComboboxBaseState.js.map +1 -1
- package/lib-commonjs/utils/useComboboxPopup.js +6 -8
- package/lib-commonjs/utils/useComboboxPopup.js.map +1 -1
- package/lib-commonjs/utils/useOptionCollection.js +10 -23
- package/lib-commonjs/utils/useOptionCollection.js.map +1 -1
- package/lib-commonjs/utils/useScrollOptionsIntoView.js +2 -9
- package/lib-commonjs/utils/useScrollOptionsIntoView.js.map +1 -1
- package/lib-commonjs/utils/useSelection.js +7 -15
- package/lib-commonjs/utils/useSelection.js.map +1 -1
- package/lib-commonjs/utils/useTriggerListboxSlots.js +30 -43
- package/lib-commonjs/utils/useTriggerListboxSlots.js.map +1 -1
- package/package.json +9 -9
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["packages/react-components/react-combobox/src/components/Listbox/index.ts"],"
|
|
1
|
+
{"version":3,"mappings":";;;;;;AAAAA;AACAA;AACAA;AACAA;AACAA","names":["tslib_1"],"sourceRoot":"../src/","sources":["packages/react-components/react-combobox/src/components/Listbox/index.ts"],"sourcesContent":["export * from './Listbox';\nexport * from './Listbox.types';\nexport * from './renderListbox';\nexport * from './useListbox';\nexport * from './useListboxStyles';\n"]}
|
|
@@ -4,17 +4,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.renderListbox_unstable = void 0;
|
|
7
|
-
|
|
8
7
|
const React = /*#__PURE__*/require("react");
|
|
9
|
-
|
|
10
8
|
const react_utilities_1 = /*#__PURE__*/require("@fluentui/react-utilities");
|
|
11
|
-
|
|
12
9
|
const ListboxContext_1 = /*#__PURE__*/require("../../contexts/ListboxContext");
|
|
13
10
|
/**
|
|
14
11
|
* Render the final JSX of Listbox
|
|
15
12
|
*/
|
|
16
|
-
|
|
17
|
-
|
|
18
13
|
const renderListbox_unstable = (state, contextValues) => {
|
|
19
14
|
const {
|
|
20
15
|
slots,
|
|
@@ -22,9 +17,9 @@ const renderListbox_unstable = (state, contextValues) => {
|
|
|
22
17
|
} = react_utilities_1.getSlots(state);
|
|
23
18
|
return React.createElement(ListboxContext_1.ListboxContext.Provider, {
|
|
24
19
|
value: contextValues.listbox
|
|
25
|
-
}, React.createElement(slots.root, {
|
|
20
|
+
}, React.createElement(slots.root, {
|
|
21
|
+
...slotProps.root
|
|
26
22
|
}));
|
|
27
23
|
};
|
|
28
|
-
|
|
29
24
|
exports.renderListbox_unstable = renderListbox_unstable;
|
|
30
25
|
//# sourceMappingURL=renderListbox.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"mappings":";;;;;;AAAA;AACA;AAEA;AAEA;;;AAGO,MAAMA,sBAAsB,GAAG,CAACC,KAAmB,EAAEC,aAAmC,KAAI;EACjG,MAAM;IAAEC,KAAK;IAAEC;EAAS,CAAE,GAAGC,0BAAQ,CAAeJ,KAAK,CAAC;EAE1D,OACEK,oBAACC,+BAAc,CAACC,QAAQ;IAACC,KAAK,EAAEP,aAAa,CAACQ;EAAO,GACnDJ,oBAACH,KAAK,CAACQ,IAAI;IAAA,GAAKP,SAAS,CAACO;EAAI,EAAI,CACV;AAE9B,CAAC;AARYC,8BAAsB","names":["renderListbox_unstable","state","contextValues","slots","slotProps","react_utilities_1","React","ListboxContext_1","Provider","value","listbox","root","exports"],"sourceRoot":"../src/","sources":["packages/react-components/react-combobox/src/components/Listbox/renderListbox.tsx"],"sourcesContent":["import * as React from 'react';\nimport { getSlots } from '@fluentui/react-utilities';\nimport type { ListboxContextValues, ListboxState, ListboxSlots } from './Listbox.types';\nimport { ListboxContext } from '../../contexts/ListboxContext';\n\n/**\n * Render the final JSX of Listbox\n */\nexport const renderListbox_unstable = (state: ListboxState, contextValues: ListboxContextValues) => {\n const { slots, slotProps } = getSlots<ListboxSlots>(state);\n\n return (\n <ListboxContext.Provider value={contextValues.listbox}>\n <slots.root {...slotProps.root} />\n </ListboxContext.Provider>\n );\n};\n"]}
|
|
@@ -4,21 +4,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.useListbox_unstable = void 0;
|
|
7
|
-
|
|
8
7
|
const React = /*#__PURE__*/require("react");
|
|
9
|
-
|
|
10
8
|
const react_utilities_1 = /*#__PURE__*/require("@fluentui/react-utilities");
|
|
11
|
-
|
|
12
9
|
const react_context_selector_1 = /*#__PURE__*/require("@fluentui/react-context-selector");
|
|
13
|
-
|
|
14
10
|
const dropdownKeyActions_1 = /*#__PURE__*/require("../../utils/dropdownKeyActions");
|
|
15
|
-
|
|
16
11
|
const useOptionCollection_1 = /*#__PURE__*/require("../../utils/useOptionCollection");
|
|
17
|
-
|
|
18
12
|
const useScrollOptionsIntoView_1 = /*#__PURE__*/require("../../utils/useScrollOptionsIntoView");
|
|
19
|
-
|
|
20
13
|
const useSelection_1 = /*#__PURE__*/require("../../utils/useSelection");
|
|
21
|
-
|
|
22
14
|
const ComboboxContext_1 = /*#__PURE__*/require("../../contexts/ComboboxContext");
|
|
23
15
|
/**
|
|
24
16
|
* Create the state required to render Listbox.
|
|
@@ -29,8 +21,6 @@ const ComboboxContext_1 = /*#__PURE__*/require("../../contexts/ComboboxContext")
|
|
|
29
21
|
* @param props - props from this instance of Listbox
|
|
30
22
|
* @param ref - reference to root HTMLElement of Listbox
|
|
31
23
|
*/
|
|
32
|
-
|
|
33
|
-
|
|
34
24
|
const useListbox_unstable = (props, ref) => {
|
|
35
25
|
const {
|
|
36
26
|
multiselect
|
|
@@ -46,11 +36,10 @@ const useListbox_unstable = (props, ref) => {
|
|
|
46
36
|
selectedOptions,
|
|
47
37
|
selectOption
|
|
48
38
|
} = useSelection_1.useSelection(props);
|
|
49
|
-
const [activeOption, setActiveOption] = React.useState();
|
|
39
|
+
const [activeOption, setActiveOption] = React.useState();
|
|
40
|
+
// track whether keyboard focus outline should be shown
|
|
50
41
|
// tabster/keyborg doesn't work here, since the actual keyboard focus target doesn't move
|
|
51
|
-
|
|
52
42
|
const [focusVisible, setFocusVisible] = React.useState(false);
|
|
53
|
-
|
|
54
43
|
const onKeyDown = event => {
|
|
55
44
|
const action = dropdownKeyActions_1.getDropdownActionFromKey(event, {
|
|
56
45
|
open: true
|
|
@@ -58,17 +47,14 @@ const useListbox_unstable = (props, ref) => {
|
|
|
58
47
|
const maxIndex = getCount() - 1;
|
|
59
48
|
const activeIndex = activeOption ? getIndexOfId(activeOption.id) : -1;
|
|
60
49
|
let newIndex = activeIndex;
|
|
61
|
-
|
|
62
50
|
switch (action) {
|
|
63
51
|
case 'Select':
|
|
64
52
|
case 'CloseSelect':
|
|
65
53
|
activeOption && selectOption(event, activeOption);
|
|
66
54
|
break;
|
|
67
|
-
|
|
68
55
|
default:
|
|
69
56
|
newIndex = dropdownKeyActions_1.getIndexFromAction(action, activeIndex, maxIndex);
|
|
70
57
|
}
|
|
71
|
-
|
|
72
58
|
if (newIndex !== activeIndex) {
|
|
73
59
|
// prevent default page scroll/keyboard action if the index changed
|
|
74
60
|
event.preventDefault();
|
|
@@ -76,19 +62,17 @@ const useListbox_unstable = (props, ref) => {
|
|
|
76
62
|
setFocusVisible(true);
|
|
77
63
|
}
|
|
78
64
|
};
|
|
79
|
-
|
|
80
65
|
const onMouseOver = event => {
|
|
81
66
|
setFocusVisible(false);
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
|
|
67
|
+
};
|
|
68
|
+
// get state from parent combobox, if it exists
|
|
85
69
|
const hasComboboxContext = react_context_selector_1.useHasParentContext(ComboboxContext_1.ComboboxContext);
|
|
86
70
|
const comboboxActiveOption = react_context_selector_1.useContextSelector(ComboboxContext_1.ComboboxContext, ctx => ctx.activeOption);
|
|
87
71
|
const comboboxFocusVisible = react_context_selector_1.useContextSelector(ComboboxContext_1.ComboboxContext, ctx => ctx.focusVisible);
|
|
88
72
|
const comboboxSelectedOptions = react_context_selector_1.useContextSelector(ComboboxContext_1.ComboboxContext, ctx => ctx.selectedOptions);
|
|
89
73
|
const comboboxSelectOption = react_context_selector_1.useContextSelector(ComboboxContext_1.ComboboxContext, ctx => ctx.selectOption);
|
|
90
|
-
const comboboxSetActiveOption = react_context_selector_1.useContextSelector(ComboboxContext_1.ComboboxContext, ctx => ctx.setActiveOption);
|
|
91
|
-
|
|
74
|
+
const comboboxSetActiveOption = react_context_selector_1.useContextSelector(ComboboxContext_1.ComboboxContext, ctx => ctx.setActiveOption);
|
|
75
|
+
// without a parent combobox context, provide values directly from Listbox
|
|
92
76
|
const optionContextValues = hasComboboxContext ? {
|
|
93
77
|
activeOption: comboboxActiveOption,
|
|
94
78
|
focusVisible: comboboxFocusVisible,
|
|
@@ -125,6 +109,5 @@ const useListbox_unstable = (props, ref) => {
|
|
|
125
109
|
state.root.onMouseOver = react_utilities_1.useEventCallback(react_utilities_1.mergeCallbacks(state.root.onMouseOver, onMouseOver));
|
|
126
110
|
return state;
|
|
127
111
|
};
|
|
128
|
-
|
|
129
112
|
exports.useListbox_unstable = useListbox_unstable;
|
|
130
113
|
//# sourceMappingURL=useListbox.js.map
|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AGhC,YAAY,aAAZA,YAAY,uBAAZA,YAAY,CAAEa,EAAE;MAC1E,sBAAsB,EAAEvB,WAAW;MACnC2C,QAAQ,EAAE,CAAC;MACX,GAAG7C;KACJ,CAAC;IACFE,WAAW;IACXM,cAAc;IACd,GAAGL,gBAAgB;IACnB,GAAGmC;GACJ;EAED,MAAMQ,kBAAkB,GAAGC,mDAAwB,CAACR,KAAK,CAAC;EAC1DA,KAAK,CAACE,IAAI,CAACxC,GAAG,GAAGyC,+BAAa,CAACH,KAAK,CAACE,IAAI,CAACxC,GAAG,EAAE6C,kBAAkB,CAAC;EAElEP,KAAK,CAACE,IAAI,CAACvB,SAAS,GAAGwB,kCAAgB,CAACA,gCAAc,CAACH,KAAK,CAACE,IAAI,CAACvB,SAAS,EAAEA,SAAS,CAAC,CAAC;EACxFqB,KAAK,CAACE,IAAI,CAACb,WAAW,GAAGc,kCAAgB,CAACA,gCAAc,CAACH,KAAK,CAACE,IAAI,CAACb,WAAW,EAAEA,WAAW,CAAC,CAAC;EAE9F,OAAOW,KAAK;AACd,CAAC;AA1FYS,2BAAmB","names":["useListbox_unstable","props","ref","multiselect","optionCollection","useOptionCollection_1","getCount","getOptionAtIndex","getIndexOfId","clearSelection","selectedOptions","selectOption","useSelection_1","activeOption","setActiveOption","React","useState","focusVisible","setFocusVisible","onKeyDown","event","action","dropdownKeyActions_1","open","maxIndex","activeIndex","id","newIndex","preventDefault","onMouseOver","hasComboboxContext","react_context_selector_1","ComboboxContext_1","comboboxActiveOption","ctx","comboboxFocusVisible","comboboxSelectedOptions","comboboxSelectOption","comboboxSetActiveOption","optionContextValues","state","components","root","react_utilities_1","role","undefined","tabIndex","scrollContainerRef","useScrollOptionsIntoView_1","exports"],"sourceRoot":"../src/","sources":["packages/react-components/react-combobox/src/components/Listbox/useListbox.ts"],"sourcesContent":["import * as React from 'react';\nimport { getNativeElementProps, mergeCallbacks, useEventCallback, useMergedRefs } from '@fluentui/react-utilities';\nimport { useContextSelector, useHasParentContext } from '@fluentui/react-context-selector';\nimport { getDropdownActionFromKey, getIndexFromAction } from '../../utils/dropdownKeyActions';\nimport type { OptionValue } from '../../utils/OptionCollection.types';\nimport { useOptionCollection } from '../../utils/useOptionCollection';\nimport { useScrollOptionsIntoView } from '../../utils/useScrollOptionsIntoView';\nimport { useSelection } from '../../utils/useSelection';\nimport { ComboboxContext } from '../../contexts/ComboboxContext';\nimport type { ListboxProps, ListboxState } from './Listbox.types';\n\n/**\n * Create the state required to render Listbox.\n *\n * The returned state can be modified with hooks such as useListboxStyles_unstable,\n * before being passed to renderListbox_unstable.\n *\n * @param props - props from this instance of Listbox\n * @param ref - reference to root HTMLElement of Listbox\n */\nexport const useListbox_unstable = (props: ListboxProps, ref: React.Ref<HTMLElement>): ListboxState => {\n const { multiselect } = props;\n const optionCollection = useOptionCollection();\n const { getCount, getOptionAtIndex, getIndexOfId } = optionCollection;\n\n const { clearSelection, selectedOptions, selectOption } = useSelection(props);\n\n const [activeOption, setActiveOption] = React.useState<OptionValue | undefined>();\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\n const onKeyDown = (event: React.KeyboardEvent<HTMLElement>) => {\n const action = getDropdownActionFromKey(event, { open: true });\n const maxIndex = getCount() - 1;\n const activeIndex = activeOption ? getIndexOfId(activeOption.id) : -1;\n let newIndex = activeIndex;\n\n switch (action) {\n case 'Select':\n case 'CloseSelect':\n activeOption && selectOption(event, activeOption);\n break;\n default:\n newIndex = getIndexFromAction(action, activeIndex, maxIndex);\n }\n\n if (newIndex !== activeIndex) {\n // prevent default page scroll/keyboard action if the index changed\n event.preventDefault();\n setActiveOption(getOptionAtIndex(newIndex));\n setFocusVisible(true);\n }\n };\n\n const onMouseOver = (event: React.MouseEvent<HTMLElement>) => {\n setFocusVisible(false);\n };\n\n // get state from parent combobox, if it exists\n const hasComboboxContext = useHasParentContext(ComboboxContext);\n const comboboxActiveOption = useContextSelector(ComboboxContext, ctx => ctx.activeOption);\n const comboboxFocusVisible = useContextSelector(ComboboxContext, ctx => ctx.focusVisible);\n const comboboxSelectedOptions = useContextSelector(ComboboxContext, ctx => ctx.selectedOptions);\n const comboboxSelectOption = useContextSelector(ComboboxContext, ctx => ctx.selectOption);\n const comboboxSetActiveOption = useContextSelector(ComboboxContext, ctx => ctx.setActiveOption);\n\n // without a parent combobox context, provide values directly from Listbox\n const optionContextValues = hasComboboxContext\n ? {\n activeOption: comboboxActiveOption,\n focusVisible: comboboxFocusVisible,\n selectedOptions: comboboxSelectedOptions,\n selectOption: comboboxSelectOption,\n setActiveOption: comboboxSetActiveOption,\n }\n : {\n activeOption,\n focusVisible,\n selectedOptions,\n selectOption,\n setActiveOption,\n };\n\n const state: ListboxState = {\n components: {\n root: 'div',\n },\n root: getNativeElementProps('div', {\n ref,\n role: multiselect ? 'menu' : 'listbox',\n 'aria-activedescendant': hasComboboxContext ? undefined : activeOption?.id,\n 'aria-multiselectable': multiselect,\n tabIndex: 0,\n ...props,\n }),\n multiselect,\n clearSelection,\n ...optionCollection,\n ...optionContextValues,\n };\n\n const scrollContainerRef = useScrollOptionsIntoView(state);\n state.root.ref = useMergedRefs(state.root.ref, scrollContainerRef);\n\n state.root.onKeyDown = useEventCallback(mergeCallbacks(state.root.onKeyDown, onKeyDown));\n state.root.onMouseOver = useEventCallback(mergeCallbacks(state.root.onMouseOver, onMouseOver));\n\n return state;\n};\n"]}
|
|
@@ -4,50 +4,43 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.useListboxStyles_unstable = exports.listboxClassNames = void 0;
|
|
7
|
-
|
|
8
7
|
const react_theme_1 = /*#__PURE__*/require("@fluentui/react-theme");
|
|
9
|
-
|
|
10
8
|
const react_1 = /*#__PURE__*/require("@griffel/react");
|
|
11
|
-
|
|
12
9
|
exports.listboxClassNames = {
|
|
13
10
|
root: 'fui-Listbox'
|
|
14
11
|
};
|
|
15
12
|
/**
|
|
16
13
|
* Styles for the root slot
|
|
17
14
|
*/
|
|
18
|
-
|
|
19
15
|
const useStyles = /*#__PURE__*/react_1.__styles({
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
16
|
+
root: {
|
|
17
|
+
E5pizo: "f1hg901r",
|
|
18
|
+
B7ck84d: "f1ewtqcl",
|
|
19
|
+
Bbmb7ep: ["f1aa9q02", "f16jpd5f"],
|
|
20
|
+
Beyfa6y: ["f16jpd5f", "f1aa9q02"],
|
|
21
|
+
B7oj6ja: ["f1jar5jt", "fyu767a"],
|
|
22
|
+
Btl43ni: ["fyu767a", "f1jar5jt"],
|
|
23
|
+
De3pzq: "fxugw4r",
|
|
24
|
+
mc9l5x: "f22iagw",
|
|
25
|
+
Beiy3e4: "f1vx9l62",
|
|
26
|
+
Bf4jedk: "f3hsy1e",
|
|
27
|
+
Bmxbyg5: "f5zp4f",
|
|
28
|
+
z8tnut: "f1x4af0m",
|
|
29
|
+
z189sj: ["f7x41pl", "fruq291"],
|
|
30
|
+
Byoj8tv: "fd55psn",
|
|
31
|
+
uwmqm3: ["fruq291", "f7x41pl"],
|
|
32
|
+
Belr9w4: "fiut8dr"
|
|
37
33
|
}
|
|
38
34
|
}, {
|
|
39
|
-
|
|
35
|
+
d: [".f1hg901r{box-shadow:var(--shadow16);}", ".f1ewtqcl{box-sizing:border-box;}", ".f1aa9q02{border-bottom-right-radius:var(--borderRadiusMedium);}", ".f16jpd5f{border-bottom-left-radius:var(--borderRadiusMedium);}", ".f1jar5jt{border-top-right-radius:var(--borderRadiusMedium);}", ".fyu767a{border-top-left-radius:var(--borderRadiusMedium);}", ".fxugw4r{background-color:var(--colorNeutralBackground1);}", ".f22iagw{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;}", ".f1vx9l62{-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;}", ".f3hsy1e{min-width:160px;}", ".f5zp4f{overflow-y:auto;}", ".f1x4af0m{padding-top:var(--spacingHorizontalXS);}", ".f7x41pl{padding-right:var(--spacingHorizontalXS);}", ".fruq291{padding-left:var(--spacingHorizontalXS);}", ".fd55psn{padding-bottom:var(--spacingHorizontalXS);}", ".fiut8dr{row-gap:var(--spacingHorizontalXXS);}"]
|
|
40
36
|
});
|
|
41
37
|
/**
|
|
42
38
|
* Apply styling to the Listbox slots based on the state
|
|
43
39
|
*/
|
|
44
|
-
|
|
45
|
-
|
|
46
40
|
const useListboxStyles_unstable = state => {
|
|
47
41
|
const styles = useStyles();
|
|
48
42
|
state.root.className = react_1.mergeClasses(exports.listboxClassNames.root, styles.root, state.root.className);
|
|
49
43
|
return state;
|
|
50
44
|
};
|
|
51
|
-
|
|
52
45
|
exports.useListboxStyles_unstable = useListboxStyles_unstable;
|
|
53
46
|
//# sourceMappingURL=useListboxStyles.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"mappings":";;;;;;AAAA;AAEA;AAGaA,yBAAiB,GAAiC;EAC7DC,IAAI,EAAE;CACP;AAED;;;AAGA,MAAMC,SAAS,gBAAGC,gBAAU;EAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;EAAA;AAAA;EAAA;AAAA,EAa1B;AAEF;;;AAGO,MAAMC,yBAAyB,GAAIC,KAAmB,IAAkB;EAC7E,MAAMC,MAAM,GAAGJ,SAAS,EAAE;EAC1BG,KAAK,CAACJ,IAAI,CAACM,SAAS,GAAGJ,oBAAY,CAACH,yBAAiB,CAACC,IAAI,EAAEK,MAAM,CAACL,IAAI,EAAEI,KAAK,CAACJ,IAAI,CAACM,SAAS,CAAC;EAE9F,OAAOF,KAAK;AACd,CAAC;AALYL,iCAAyB","names":["exports","root","useStyles","react_1","useListboxStyles_unstable","state","styles","className"],"sourceRoot":"../src/","sources":["packages/react-components/react-combobox/src/components/Listbox/useListboxStyles.ts"],"sourcesContent":["import { tokens } from '@fluentui/react-theme';\nimport { SlotClassNames } from '@fluentui/react-utilities';\nimport { makeStyles, mergeClasses, shorthands } from '@griffel/react';\nimport type { ListboxSlots, ListboxState } from './Listbox.types';\n\nexport const listboxClassNames: SlotClassNames<ListboxSlots> = {\n root: 'fui-Listbox',\n};\n\n/**\n * Styles for the root slot\n */\nconst useStyles = makeStyles({\n root: {\n boxShadow: `${tokens.shadow16}`,\n boxSizing: 'border-box',\n ...shorthands.borderRadius(tokens.borderRadiusMedium),\n backgroundColor: tokens.colorNeutralBackground1,\n display: 'flex',\n flexDirection: 'column',\n minWidth: '160px',\n overflowY: 'auto',\n ...shorthands.padding(tokens.spacingHorizontalXS),\n rowGap: tokens.spacingHorizontalXXS,\n },\n});\n\n/**\n * Apply styling to the Listbox slots based on the state\n */\nexport const useListboxStyles_unstable = (state: ListboxState): ListboxState => {\n const styles = useStyles();\n state.root.className = mergeClasses(listboxClassNames.root, styles.root, state.root.className);\n\n return state;\n};\n"]}
|
|
@@ -4,19 +4,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.Option = void 0;
|
|
7
|
-
|
|
8
7
|
const React = /*#__PURE__*/require("react");
|
|
9
|
-
|
|
10
8
|
const useOption_1 = /*#__PURE__*/require("./useOption");
|
|
11
|
-
|
|
12
9
|
const renderOption_1 = /*#__PURE__*/require("./renderOption");
|
|
13
|
-
|
|
14
10
|
const useOptionStyles_1 = /*#__PURE__*/require("./useOptionStyles");
|
|
15
11
|
/**
|
|
16
12
|
* Option component: a styled child option of a Combobox
|
|
17
13
|
*/
|
|
18
|
-
|
|
19
|
-
|
|
20
14
|
exports.Option = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
21
15
|
const state = useOption_1.useOption_unstable(props, ref);
|
|
22
16
|
useOptionStyles_1.useOptionStyles_unstable(state);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"mappings":";;;;;;AAAA;AACA;AACA;AACA;AAIA;;;AAGaA,cAAM,gBAAqCC,KAAK,CAACC,UAAU,CAAC,CAACC,KAAK,EAAEC,GAAG,KAAI;EACtF,MAAMC,KAAK,GAAGC,8BAAkB,CAACH,KAAK,EAAEC,GAAG,CAAC;EAE5CG,0CAAwB,CAACF,KAAK,CAAC;EAC/B,OAAOG,oCAAqB,CAACH,KAAK,CAAC;AACrC,CAAC,CAAC;AAEFL,cAAM,CAACS,WAAW,GAAG,QAAQ","names":["exports","React","forwardRef","props","ref","state","useOption_1","useOptionStyles_1","renderOption_1","displayName"],"sourceRoot":"../src/","sources":["packages/react-components/react-combobox/src/components/Option/Option.tsx"],"sourcesContent":["import * as React from 'react';\nimport { useOption_unstable } from './useOption';\nimport { renderOption_unstable } from './renderOption';\nimport { useOptionStyles_unstable } from './useOptionStyles';\nimport type { OptionProps } from './Option.types';\nimport type { ForwardRefComponent } from '@fluentui/react-utilities';\n\n/**\n * Option component: a styled child option of a Combobox\n */\nexport const Option: ForwardRefComponent<OptionProps> = React.forwardRef((props, ref) => {\n const state = useOption_unstable(props, ref);\n\n useOptionStyles_unstable(state);\n return renderOption_unstable(state);\n});\n\nOption.displayName = 'Option';\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("./Option"), exports);
|
|
10
|
-
|
|
11
8
|
tslib_1.__exportStar(require("./Option.types"), exports);
|
|
12
|
-
|
|
13
9
|
tslib_1.__exportStar(require("./renderOption"), exports);
|
|
14
|
-
|
|
15
10
|
tslib_1.__exportStar(require("./useOption"), exports);
|
|
16
|
-
|
|
17
11
|
tslib_1.__exportStar(require("./useOptionStyles"), exports);
|
|
18
12
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["packages/react-components/react-combobox/src/components/Option/index.ts"],"
|
|
1
|
+
{"version":3,"mappings":";;;;;;AAAAA;AACAA;AACAA;AACAA;AACAA","names":["tslib_1"],"sourceRoot":"../src/","sources":["packages/react-components/react-combobox/src/components/Option/index.ts"],"sourcesContent":["export * from './Option';\nexport * from './Option.types';\nexport * from './renderOption';\nexport * from './useOption';\nexport * from './useOptionStyles';\n"]}
|
|
@@ -4,24 +4,21 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.renderOption_unstable = void 0;
|
|
7
|
-
|
|
8
7
|
const React = /*#__PURE__*/require("react");
|
|
9
|
-
|
|
10
8
|
const react_utilities_1 = /*#__PURE__*/require("@fluentui/react-utilities");
|
|
11
9
|
/**
|
|
12
10
|
* Render the final JSX of Option
|
|
13
11
|
*/
|
|
14
|
-
|
|
15
|
-
|
|
16
12
|
const renderOption_unstable = state => {
|
|
17
13
|
const {
|
|
18
14
|
slots,
|
|
19
15
|
slotProps
|
|
20
16
|
} = react_utilities_1.getSlots(state);
|
|
21
|
-
return React.createElement(slots.root, {
|
|
22
|
-
|
|
17
|
+
return React.createElement(slots.root, {
|
|
18
|
+
...slotProps.root
|
|
19
|
+
}, React.createElement(slots.checkIcon, {
|
|
20
|
+
...slotProps.checkIcon
|
|
23
21
|
}), slotProps.root.children);
|
|
24
22
|
};
|
|
25
|
-
|
|
26
23
|
exports.renderOption_unstable = renderOption_unstable;
|
|
27
24
|
//# sourceMappingURL=renderOption.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"mappings":";;;;;;AAAA;AACA;AAGA;;;AAGO,MAAMA,qBAAqB,GAAIC,KAAkB,IAAI;EAC1D,MAAM;IAAEC,KAAK;IAAEC;EAAS,CAAE,GAAGC,0BAAQ,CAAcH,KAAK,CAAC;EAEzD,OACEI,oBAACH,KAAK,CAACI,IAAI;IAAA,GAAKH,SAAS,CAACG;EAAI,GAC5BD,oBAACH,KAAK,CAACK,SAAS;IAAA,GAAKJ,SAAS,CAACI;EAAS,EAAI,EAC3CJ,SAAS,CAACG,IAAI,CAACE,QAAQ,CACb;AAEjB,CAAC;AATYC,6BAAqB","names":["renderOption_unstable","state","slots","slotProps","react_utilities_1","React","root","checkIcon","children","exports"],"sourceRoot":"../src/","sources":["packages/react-components/react-combobox/src/components/Option/renderOption.tsx"],"sourcesContent":["import * as React from 'react';\nimport { getSlots } from '@fluentui/react-utilities';\nimport type { OptionState, OptionSlots } from './Option.types';\n\n/**\n * Render the final JSX of Option\n */\nexport const renderOption_unstable = (state: OptionState) => {\n const { slots, slotProps } = getSlots<OptionSlots>(state);\n\n return (\n <slots.root {...slotProps.root}>\n <slots.checkIcon {...slotProps.checkIcon} />\n {slotProps.root.children}\n </slots.root>\n );\n};\n"]}
|
|
@@ -4,24 +4,16 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.useOption_unstable = void 0;
|
|
7
|
-
|
|
8
7
|
const React = /*#__PURE__*/require("react");
|
|
9
|
-
|
|
10
8
|
const react_utilities_1 = /*#__PURE__*/require("@fluentui/react-utilities");
|
|
11
|
-
|
|
12
9
|
const react_context_selector_1 = /*#__PURE__*/require("@fluentui/react-context-selector");
|
|
13
|
-
|
|
14
10
|
const react_icons_1 = /*#__PURE__*/require("@fluentui/react-icons");
|
|
15
|
-
|
|
16
11
|
const ComboboxContext_1 = /*#__PURE__*/require("../../contexts/ComboboxContext");
|
|
17
|
-
|
|
18
12
|
const ListboxContext_1 = /*#__PURE__*/require("../../contexts/ListboxContext");
|
|
19
|
-
|
|
20
13
|
function getTextString(text, children) {
|
|
21
14
|
if (text !== undefined) {
|
|
22
15
|
return text;
|
|
23
16
|
}
|
|
24
|
-
|
|
25
17
|
let textString = '';
|
|
26
18
|
let hasNonStringChild = false;
|
|
27
19
|
React.Children.forEach(children, child => {
|
|
@@ -30,13 +22,12 @@ function getTextString(text, children) {
|
|
|
30
22
|
} else {
|
|
31
23
|
hasNonStringChild = true;
|
|
32
24
|
}
|
|
33
|
-
});
|
|
34
|
-
|
|
25
|
+
});
|
|
26
|
+
// warn if an Option has non-string children and no text prop
|
|
35
27
|
if (hasNonStringChild) {
|
|
36
28
|
// eslint-disable-next-line no-console
|
|
37
29
|
console.warn('Provide a `text` prop to Option components when they contain non-string children.');
|
|
38
30
|
}
|
|
39
|
-
|
|
40
31
|
return textString;
|
|
41
32
|
}
|
|
42
33
|
/**
|
|
@@ -48,8 +39,6 @@ function getTextString(text, children) {
|
|
|
48
39
|
* @param props - props from this instance of Option
|
|
49
40
|
* @param ref - reference to root HTMLElement of Option
|
|
50
41
|
*/
|
|
51
|
-
|
|
52
|
-
|
|
53
42
|
const useOption_unstable = (props, ref) => {
|
|
54
43
|
const {
|
|
55
44
|
children,
|
|
@@ -59,17 +48,17 @@ const useOption_unstable = (props, ref) => {
|
|
|
59
48
|
} = props;
|
|
60
49
|
const optionRef = React.useRef(null);
|
|
61
50
|
const optionText = getTextString(text, children);
|
|
62
|
-
const optionValue = value !== null && value !== void 0 ? value : optionText;
|
|
63
|
-
|
|
64
|
-
const id = react_utilities_1.useId('fluent-option', props.id);
|
|
65
|
-
|
|
51
|
+
const optionValue = value !== null && value !== void 0 ? value : optionText;
|
|
52
|
+
// use the id if provided, otherwise use a generated id
|
|
53
|
+
const id = react_utilities_1.useId('fluent-option', props.id);
|
|
54
|
+
// data used for context registration & events
|
|
66
55
|
const optionData = React.useMemo(() => ({
|
|
67
56
|
id,
|
|
68
57
|
disabled,
|
|
69
58
|
text: optionText,
|
|
70
59
|
value: optionValue
|
|
71
|
-
}), [id, disabled, optionText, optionValue]);
|
|
72
|
-
|
|
60
|
+
}), [id, disabled, optionText, optionValue]);
|
|
61
|
+
// context values
|
|
73
62
|
const focusVisible = react_context_selector_1.useContextSelector(ListboxContext_1.ListboxContext, ctx => ctx.focusVisible);
|
|
74
63
|
const multiselect = react_context_selector_1.useContextSelector(ListboxContext_1.ListboxContext, ctx => ctx.multiselect);
|
|
75
64
|
const registerOption = react_context_selector_1.useContextSelector(ListboxContext_1.ListboxContext, ctx => ctx.registerOption);
|
|
@@ -79,41 +68,34 @@ const useOption_unstable = (props, ref) => {
|
|
|
79
68
|
});
|
|
80
69
|
const selectOption = react_context_selector_1.useContextSelector(ListboxContext_1.ListboxContext, ctx => ctx.selectOption);
|
|
81
70
|
const setActiveOption = react_context_selector_1.useContextSelector(ListboxContext_1.ListboxContext, ctx => ctx.setActiveOption);
|
|
82
|
-
const setOpen = react_context_selector_1.useContextSelector(ComboboxContext_1.ComboboxContext, ctx => ctx.setOpen);
|
|
83
|
-
|
|
71
|
+
const setOpen = react_context_selector_1.useContextSelector(ComboboxContext_1.ComboboxContext, ctx => ctx.setOpen);
|
|
72
|
+
// current active option?
|
|
84
73
|
const active = react_context_selector_1.useContextSelector(ListboxContext_1.ListboxContext, ctx => {
|
|
85
74
|
var _a, _b;
|
|
86
|
-
|
|
87
75
|
return ((_a = ctx.activeOption) === null || _a === void 0 ? void 0 : _a.id) !== undefined && ((_b = ctx.activeOption) === null || _b === void 0 ? void 0 : _b.id) === id;
|
|
88
|
-
});
|
|
89
|
-
|
|
76
|
+
});
|
|
77
|
+
// check icon
|
|
90
78
|
let CheckIcon = React.createElement(react_icons_1.CheckmarkFilled, null);
|
|
91
|
-
|
|
92
79
|
if (multiselect) {
|
|
93
80
|
CheckIcon = selected ? React.createElement(react_icons_1.CheckboxCheckedFilled, null) : React.createElement(react_icons_1.CheckboxUncheckedFilled, null);
|
|
94
81
|
}
|
|
95
|
-
|
|
96
82
|
const onClick = event => {
|
|
97
83
|
var _a;
|
|
98
|
-
|
|
99
84
|
if (disabled) {
|
|
100
85
|
event.preventDefault();
|
|
101
86
|
return;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
87
|
+
}
|
|
88
|
+
// clicked option should always become active option
|
|
89
|
+
setActiveOption(optionData);
|
|
90
|
+
// close on option click for single-select options in a combobox
|
|
107
91
|
if (!multiselect) {
|
|
108
92
|
setOpen === null || setOpen === void 0 ? void 0 : setOpen(event, false);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
|
|
93
|
+
}
|
|
94
|
+
// handle selection change
|
|
112
95
|
selectOption(event, optionData);
|
|
113
96
|
(_a = props.onClick) === null || _a === void 0 ? void 0 : _a.call(props, event);
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
|
|
97
|
+
};
|
|
98
|
+
// register option data with context
|
|
117
99
|
React.useEffect(() => {
|
|
118
100
|
if (id && optionRef.current) {
|
|
119
101
|
return registerOption(optionData, optionRef.current);
|
|
@@ -153,6 +135,5 @@ const useOption_unstable = (props, ref) => {
|
|
|
153
135
|
selected
|
|
154
136
|
};
|
|
155
137
|
};
|
|
156
|
-
|
|
157
138
|
exports.useOption_unstable = useOption_unstable;
|
|
158
139
|
//# sourceMappingURL=useOption.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AAIA,SAASA,aAAa,CAACC,IAAwB,EAAEC,QAAyB;EACxE,IAAID,IAAI,KAAKE,SAAS,EAAE;IACtB,OAAOF,IAAI;;EAGb,IAAIG,UAAU,GAAG,EAAE;EACnB,IAAIC,iBAAiB,GAAG,KAAK;EAC7BC,KAAK,CAACC,QAAQ,CA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AAK,CAACoB,OAAO,+CAAb9B,KAAK,EAAW+B,KAAK,CAAC;EACxB,CAAC;EAED;EACAtC,KAAK,CAACwC,SAAS,CAAC,MAAK;IACnB,IAAIzB,EAAE,IAAIJ,SAAS,CAAC8B,OAAO,EAAE;MAC3B,OAAOjB,cAAc,CAACP,UAAU,EAAEN,SAAS,CAAC8B,OAAO,CAAC;;EAExD,CAAC,EAAE,CAAC1B,EAAE,EAAEE,UAAU,EAAEO,cAAc,CAAC,CAAC;EAEpC,MAAMkB,aAAa,GAAGnB,WAAW,GAC7B;IAAEoB,IAAI,EAAE,kBAAkB;IAAE,cAAc,EAAElB;EAAQ,CAAE,GACtD;IAAEkB,IAAI,EAAE,QAAQ;IAAE,eAAe,EAAElB;EAAQ,CAAE;EAEjD,OAAO;IACLmB,UAAU,EAAE;MACVC,IAAI,EAAE,KAAK;MACXC,SAAS,EAAE;KACZ;IACDD,IAAI,EAAE7B,uCAAqB,CAAC,KAAK,EAAE;MACjCR,GAAG,EAAEQ,+BAAa,CAACR,GAAG,EAAEG,SAAS,CAAC;MAClC,eAAe,EAAEF,QAAQ,GAAG,MAAM,GAAGZ,SAAS;MAC9CkB,EAAE;MACF,GAAG2B,aAAa;MAChB,GAAGnC,KAAK;MACR8B;KACD,CAAC;IACFS,SAAS,EAAE9B,kCAAgB,CAACT,KAAK,CAACuC,SAAS,EAAE;MAC3CC,QAAQ,EAAE,IAAI;MACdC,YAAY,EAAE;QACZ,aAAa,EAAE,MAAM;QACrBpD,QAAQ,EAAEuC;;KAEb,CAAC;IACFF,MAAM;IACNxB,QAAQ;IACRU,YAAY;IACZI,WAAW;IACXE;GACD;AACH,CAAC;AAlGYwB,0BAAkB","names":["getTextString","text","children","undefined","textString","hasNonStringChild","React","Children","forEach","child","console","warn","useOption_unstable","props","ref","disabled","value","optionRef","useRef","optionText","optionValue","id","react_utilities_1","optionData","useMemo","focusVisible","react_context_selector_1","ListboxContext_1","ctx","multiselect","registerOption","selected","selectedOptions","find","o","selectOption","setActiveOption","setOpen","ComboboxContext_1","active","activeOption","CheckIcon","react_icons_1","onClick","event","preventDefault","useEffect","current","semanticProps","role","components","root","checkIcon","required","defaultProps","exports"],"sourceRoot":"../src/","sources":["packages/react-components/react-combobox/src/components/Option/useOption.tsx"],"sourcesContent":["import * as React from 'react';\nimport { getNativeElementProps, resolveShorthand, useId, useMergedRefs } from '@fluentui/react-utilities';\nimport { useContextSelector } from '@fluentui/react-context-selector';\nimport { CheckmarkFilled, CheckboxUncheckedFilled, CheckboxCheckedFilled } from '@fluentui/react-icons';\nimport { ComboboxContext } from '../../contexts/ComboboxContext';\nimport { ListboxContext } from '../../contexts/ListboxContext';\nimport type { OptionValue } from '../../utils/OptionCollection.types';\nimport type { OptionProps, OptionState } from './Option.types';\n\nfunction getTextString(text: string | undefined, children: React.ReactNode) {\n if (text !== undefined) {\n return text;\n }\n\n let textString = '';\n let hasNonStringChild = false;\n React.Children.forEach(children, child => {\n if (typeof child === 'string') {\n textString += child;\n } else {\n hasNonStringChild = true;\n }\n });\n\n // warn if an Option has non-string children and no text prop\n if (hasNonStringChild) {\n // eslint-disable-next-line no-console\n console.warn('Provide a `text` prop to Option components when they contain non-string children.');\n }\n\n return textString;\n}\n\n/**\n * Create the state required to render Option.\n *\n * The returned state can be modified with hooks such as useOptionStyles_unstable,\n * before being passed to renderOption_unstable.\n *\n * @param props - props from this instance of Option\n * @param ref - reference to root HTMLElement of Option\n */\nexport const useOption_unstable = (props: OptionProps, ref: React.Ref<HTMLElement>): OptionState => {\n const { children, disabled, text, value } = props;\n const optionRef = React.useRef<HTMLElement>(null);\n const optionText = getTextString(text, children);\n const optionValue = value ?? optionText;\n\n // use the id if provided, otherwise use a generated id\n const id = useId('fluent-option', props.id);\n\n // data used for context registration & events\n const optionData = React.useMemo<OptionValue>(() => ({ id, disabled, text: optionText, value: optionValue }), [\n id,\n disabled,\n optionText,\n optionValue,\n ]);\n\n // context values\n const focusVisible = useContextSelector(ListboxContext, ctx => ctx.focusVisible);\n const multiselect = useContextSelector(ListboxContext, ctx => ctx.multiselect);\n const registerOption = useContextSelector(ListboxContext, ctx => ctx.registerOption);\n const selected = useContextSelector(ListboxContext, ctx => {\n const selectedOptions = ctx.selectedOptions;\n\n return !!optionValue && !!selectedOptions.find(o => o === optionValue);\n });\n const selectOption = useContextSelector(ListboxContext, ctx => ctx.selectOption);\n const setActiveOption = useContextSelector(ListboxContext, ctx => ctx.setActiveOption);\n const setOpen = useContextSelector(ComboboxContext, ctx => ctx.setOpen);\n\n // current active option?\n const active = useContextSelector(ListboxContext, ctx => {\n return ctx.activeOption?.id !== undefined && ctx.activeOption?.id === id;\n });\n\n // check icon\n let CheckIcon = <CheckmarkFilled />;\n if (multiselect) {\n CheckIcon = selected ? <CheckboxCheckedFilled /> : <CheckboxUncheckedFilled />;\n }\n\n const onClick = (event: React.MouseEvent<HTMLDivElement>) => {\n if (disabled) {\n event.preventDefault();\n return;\n }\n\n // clicked option should always become active option\n setActiveOption(optionData);\n\n // close on option click for single-select options in a combobox\n if (!multiselect) {\n setOpen?.(event, false);\n }\n\n // handle selection change\n selectOption(event, optionData);\n\n props.onClick?.(event);\n };\n\n // register option data with context\n React.useEffect(() => {\n if (id && optionRef.current) {\n return registerOption(optionData, optionRef.current);\n }\n }, [id, optionData, registerOption]);\n\n const semanticProps = multiselect\n ? { role: 'menuitemcheckbox', 'aria-checked': selected }\n : { role: 'option', 'aria-selected': selected };\n\n return {\n components: {\n root: 'div',\n checkIcon: 'span',\n },\n root: getNativeElementProps('div', {\n ref: useMergedRefs(ref, optionRef),\n 'aria-disabled': disabled ? 'true' : undefined,\n id,\n ...semanticProps,\n ...props,\n onClick,\n }),\n checkIcon: resolveShorthand(props.checkIcon, {\n required: true,\n defaultProps: {\n 'aria-hidden': 'true',\n children: CheckIcon,\n },\n }),\n active,\n disabled,\n focusVisible,\n multiselect,\n selected,\n };\n};\n"]}
|