@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
|
@@ -15,7 +15,6 @@ import { ComboboxContext } from '../../contexts/ComboboxContext';
|
|
|
15
15
|
* @param props - props from this instance of Listbox
|
|
16
16
|
* @param ref - reference to root HTMLElement of Listbox
|
|
17
17
|
*/
|
|
18
|
-
|
|
19
18
|
export const useListbox_unstable = (props, ref) => {
|
|
20
19
|
const {
|
|
21
20
|
multiselect
|
|
@@ -31,11 +30,10 @@ export const useListbox_unstable = (props, ref) => {
|
|
|
31
30
|
selectedOptions,
|
|
32
31
|
selectOption
|
|
33
32
|
} = useSelection(props);
|
|
34
|
-
const [activeOption, setActiveOption] = React.useState();
|
|
33
|
+
const [activeOption, setActiveOption] = React.useState();
|
|
34
|
+
// track whether keyboard focus outline should be shown
|
|
35
35
|
// tabster/keyborg doesn't work here, since the actual keyboard focus target doesn't move
|
|
36
|
-
|
|
37
36
|
const [focusVisible, setFocusVisible] = React.useState(false);
|
|
38
|
-
|
|
39
37
|
const onKeyDown = event => {
|
|
40
38
|
const action = getDropdownActionFromKey(event, {
|
|
41
39
|
open: true
|
|
@@ -43,17 +41,14 @@ export const useListbox_unstable = (props, ref) => {
|
|
|
43
41
|
const maxIndex = getCount() - 1;
|
|
44
42
|
const activeIndex = activeOption ? getIndexOfId(activeOption.id) : -1;
|
|
45
43
|
let newIndex = activeIndex;
|
|
46
|
-
|
|
47
44
|
switch (action) {
|
|
48
45
|
case 'Select':
|
|
49
46
|
case 'CloseSelect':
|
|
50
47
|
activeOption && selectOption(event, activeOption);
|
|
51
48
|
break;
|
|
52
|
-
|
|
53
49
|
default:
|
|
54
50
|
newIndex = getIndexFromAction(action, activeIndex, maxIndex);
|
|
55
51
|
}
|
|
56
|
-
|
|
57
52
|
if (newIndex !== activeIndex) {
|
|
58
53
|
// prevent default page scroll/keyboard action if the index changed
|
|
59
54
|
event.preventDefault();
|
|
@@ -61,19 +56,17 @@ export const useListbox_unstable = (props, ref) => {
|
|
|
61
56
|
setFocusVisible(true);
|
|
62
57
|
}
|
|
63
58
|
};
|
|
64
|
-
|
|
65
59
|
const onMouseOver = event => {
|
|
66
60
|
setFocusVisible(false);
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
|
|
61
|
+
};
|
|
62
|
+
// get state from parent combobox, if it exists
|
|
70
63
|
const hasComboboxContext = useHasParentContext(ComboboxContext);
|
|
71
64
|
const comboboxActiveOption = useContextSelector(ComboboxContext, ctx => ctx.activeOption);
|
|
72
65
|
const comboboxFocusVisible = useContextSelector(ComboboxContext, ctx => ctx.focusVisible);
|
|
73
66
|
const comboboxSelectedOptions = useContextSelector(ComboboxContext, ctx => ctx.selectedOptions);
|
|
74
67
|
const comboboxSelectOption = useContextSelector(ComboboxContext, ctx => ctx.selectOption);
|
|
75
|
-
const comboboxSetActiveOption = useContextSelector(ComboboxContext, ctx => ctx.setActiveOption);
|
|
76
|
-
|
|
68
|
+
const comboboxSetActiveOption = useContextSelector(ComboboxContext, ctx => ctx.setActiveOption);
|
|
69
|
+
// without a parent combobox context, provide values directly from Listbox
|
|
77
70
|
const optionContextValues = hasComboboxContext ? {
|
|
78
71
|
activeOption: comboboxActiveOption,
|
|
79
72
|
focusVisible: comboboxFocusVisible,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SAASC,qBAAqB,EAAEC,cAAc,EAAEC,gBAAgB,EAAEC,aAAa,QAAQ,2BAA2B;AAClH,SAASC,kBAAkB,EAAEC,mBAAmB,QAAQ,kCAAkC;AAC1F,SAASC,wBAAwB,EAAEC,kBAAkB,QAAQ,gCAAgC;AAE7F,SAASC,mBAAmB,QAAQ,iCAAiC;AACrE,SAASC,wBAAwB,QAAQ,sCAAsC;AAC/E,SAASC,YAAY,QAAQ,0BAA0B;AACvD,SAASC,eAAe,QAAQ,gCAAgC;AAGhE;;;;;;;;;AASA,OAAO,MAAMC,mBAAmB,GAAG,CAACC,KAAmB,EAAEC,GAA2B,KAAkB;EACpG,MAAM;IAAEC;EAAW,CAAE,GAAGF,KAAK;EAC7B,MAAMG,gBAAgB,GAAGR,mBAAmB,EAAE;EAC9C,MAAM;IAAES,QAAQ;IAAEC,gBAAgB;IAAEC;EAAY,CAAE,GAAGH,gBAAgB;EAErE,MAAM;IAAEI,cAAc;IAAEC,eAAe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AACE,IAAI,CAACpB,SAAS,GAAG1B,gBAAgB,CAACD,cAAc,CAAC6C,KAAK,CAACE,IAAI,CAACpB,SAAS,EAAEA,SAAS,CAAC,CAAC;EACxFkB,KAAK,CAACE,IAAI,CAACX,WAAW,GAAGnC,gBAAgB,CAACD,cAAc,CAAC6C,KAAK,CAACE,IAAI,CAACX,WAAW,EAAEA,WAAW,CAAC,CAAC;EAE9F,OAAOS,KAAK;AACd,CAAC","names":["React","getNativeElementProps","mergeCallbacks","useEventCallback","useMergedRefs","useContextSelector","useHasParentContext","getDropdownActionFromKey","getIndexFromAction","useOptionCollection","useScrollOptionsIntoView","useSelection","ComboboxContext","useListbox_unstable","props","ref","multiselect","optionCollection","getCount","getOptionAtIndex","getIndexOfId","clearSelection","selectedOptions","selectOption","activeOption","setActiveOption","useState","focusVisible","setFocusVisible","onKeyDown","event","action","open","maxIndex","activeIndex","id","newIndex","preventDefault","onMouseOver","hasComboboxContext","comboboxActiveOption","ctx","comboboxFocusVisible","comboboxSelectedOptions","comboboxSelectOption","comboboxSetActiveOption","optionContextValues","state","components","root","role","undefined","tabIndex","scrollContainerRef"],"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"]}
|
|
@@ -6,34 +6,31 @@ export const listboxClassNames = {
|
|
|
6
6
|
/**
|
|
7
7
|
* Styles for the root slot
|
|
8
8
|
*/
|
|
9
|
-
|
|
10
9
|
const useStyles = /*#__PURE__*/__styles({
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
10
|
+
root: {
|
|
11
|
+
E5pizo: "f1hg901r",
|
|
12
|
+
B7ck84d: "f1ewtqcl",
|
|
13
|
+
Bbmb7ep: ["f1aa9q02", "f16jpd5f"],
|
|
14
|
+
Beyfa6y: ["f16jpd5f", "f1aa9q02"],
|
|
15
|
+
B7oj6ja: ["f1jar5jt", "fyu767a"],
|
|
16
|
+
Btl43ni: ["fyu767a", "f1jar5jt"],
|
|
17
|
+
De3pzq: "fxugw4r",
|
|
18
|
+
mc9l5x: "f22iagw",
|
|
19
|
+
Beiy3e4: "f1vx9l62",
|
|
20
|
+
Bf4jedk: "f3hsy1e",
|
|
21
|
+
Bmxbyg5: "f5zp4f",
|
|
22
|
+
z8tnut: "f1x4af0m",
|
|
23
|
+
z189sj: ["f7x41pl", "fruq291"],
|
|
24
|
+
Byoj8tv: "fd55psn",
|
|
25
|
+
uwmqm3: ["fruq291", "f7x41pl"],
|
|
26
|
+
Belr9w4: "fiut8dr"
|
|
28
27
|
}
|
|
29
28
|
}, {
|
|
30
|
-
|
|
29
|
+
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);}"]
|
|
31
30
|
});
|
|
32
31
|
/**
|
|
33
32
|
* Apply styling to the Listbox slots based on the state
|
|
34
33
|
*/
|
|
35
|
-
|
|
36
|
-
|
|
37
34
|
export const useListboxStyles_unstable = state => {
|
|
38
35
|
const styles = useStyles();
|
|
39
36
|
state.root.className = mergeClasses(listboxClassNames.root, styles.root, state.root.className);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"mappings":"AAAA,SAASA,MAAM,QAAQ,uBAAuB;AAE9C,mBAAqBC,YAAY,EAAEC,UAAU,QAAQ,gBAAgB;AAGrE,OAAO,MAAMC,iBAAiB,GAAiC;EAC7DC,IAAI,EAAE;CACP;AAED;;;AAGA,MAAMC,SAAS,gBAAG;EAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;EAAA;AAAA;EAAA;AAAA,EAahB;AAEF;;;AAGA,OAAO,MAAMC,yBAAyB,GAAIC,KAAmB,IAAkB;EAC7E,MAAMC,MAAM,GAAGH,SAAS,EAAE;EAC1BE,KAAK,CAACH,IAAI,CAACK,SAAS,GAAGR,YAAY,CAACE,iBAAiB,CAACC,IAAI,EAAEI,MAAM,CAACJ,IAAI,EAAEG,KAAK,CAACH,IAAI,CAACK,SAAS,CAAC;EAE9F,OAAOF,KAAK;AACd,CAAC","names":["tokens","mergeClasses","shorthands","listboxClassNames","root","useStyles","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"]}
|
|
@@ -5,7 +5,6 @@ import { useOptionStyles_unstable } from './useOptionStyles';
|
|
|
5
5
|
/**
|
|
6
6
|
* Option component: a styled child option of a Combobox
|
|
7
7
|
*/
|
|
8
|
-
|
|
9
8
|
export const Option = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
10
9
|
const state = useOption_unstable(props, ref);
|
|
11
10
|
useOptionStyles_unstable(state);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SAASC,kBAAkB,QAAQ,aAAa;AAChD,SAASC,qBAAqB,QAAQ,gBAAgB;AACtD,SAASC,wBAAwB,QAAQ,mBAAmB;AAI5D;;;AAGA,OAAO,MAAMC,MAAM,gBAAqCJ,KAAK,CAACK,UAAU,CAAC,CAACC,KAAK,EAAEC,GAAG,KAAI;EACtF,MAAMC,KAAK,GAAGP,kBAAkB,CAACK,KAAK,EAAEC,GAAG,CAAC;EAE5CJ,wBAAwB,CAACK,KAAK,CAAC;EAC/B,OAAON,qBAAqB,CAACM,KAAK,CAAC;AACrC,CAAC,CAAC;AAEFJ,MAAM,CAACK,WAAW,GAAG,QAAQ","names":["React","useOption_unstable","renderOption_unstable","useOptionStyles_unstable","Option","forwardRef","props","ref","state","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"]}
|
|
@@ -3,14 +3,15 @@ import { getSlots } from '@fluentui/react-utilities';
|
|
|
3
3
|
/**
|
|
4
4
|
* Render the final JSX of Option
|
|
5
5
|
*/
|
|
6
|
-
|
|
7
6
|
export const renderOption_unstable = state => {
|
|
8
7
|
const {
|
|
9
8
|
slots,
|
|
10
9
|
slotProps
|
|
11
10
|
} = getSlots(state);
|
|
12
|
-
return /*#__PURE__*/React.createElement(slots.root, {
|
|
13
|
-
|
|
11
|
+
return /*#__PURE__*/React.createElement(slots.root, {
|
|
12
|
+
...slotProps.root
|
|
13
|
+
}, /*#__PURE__*/React.createElement(slots.checkIcon, {
|
|
14
|
+
...slotProps.checkIcon
|
|
14
15
|
}), slotProps.root.children);
|
|
15
16
|
};
|
|
16
17
|
//# sourceMappingURL=renderOption.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SAASC,QAAQ,QAAQ,2BAA2B;AAGpD;;;AAGA,OAAO,MAAMC,qBAAqB,GAAIC,KAAkB,IAAI;EAC1D,MAAM;IAAEC,KAAK;IAAEC;EAAS,CAAE,GAAGJ,QAAQ,CAAcE,KAAK,CAAC;EAEzD,oBACEH,oBAACI,KAAK,CAACE,IAAI;IAAA,GAAKD,SAAS,CAACC;EAAI,gBAC5BN,oBAACI,KAAK,CAACG,SAAS;IAAA,GAAKF,SAAS,CAACE;EAAS,EAAI,EAC3CF,SAAS,CAACC,IAAI,CAACE,QAAQ,CACb;AAEjB,CAAC","names":["React","getSlots","renderOption_unstable","state","slots","slotProps","root","checkIcon","children"],"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,12 +4,10 @@ import { useContextSelector } from '@fluentui/react-context-selector';
|
|
|
4
4
|
import { CheckmarkFilled, CheckboxUncheckedFilled, CheckboxCheckedFilled } from '@fluentui/react-icons';
|
|
5
5
|
import { ComboboxContext } from '../../contexts/ComboboxContext';
|
|
6
6
|
import { ListboxContext } from '../../contexts/ListboxContext';
|
|
7
|
-
|
|
8
7
|
function getTextString(text, children) {
|
|
9
8
|
if (text !== undefined) {
|
|
10
9
|
return text;
|
|
11
10
|
}
|
|
12
|
-
|
|
13
11
|
let textString = '';
|
|
14
12
|
let hasNonStringChild = false;
|
|
15
13
|
React.Children.forEach(children, child => {
|
|
@@ -18,13 +16,12 @@ function getTextString(text, children) {
|
|
|
18
16
|
} else {
|
|
19
17
|
hasNonStringChild = true;
|
|
20
18
|
}
|
|
21
|
-
});
|
|
22
|
-
|
|
19
|
+
});
|
|
20
|
+
// warn if an Option has non-string children and no text prop
|
|
23
21
|
if (hasNonStringChild) {
|
|
24
22
|
// eslint-disable-next-line no-console
|
|
25
23
|
console.warn('Provide a `text` prop to Option components when they contain non-string children.');
|
|
26
24
|
}
|
|
27
|
-
|
|
28
25
|
return textString;
|
|
29
26
|
}
|
|
30
27
|
/**
|
|
@@ -36,8 +33,6 @@ function getTextString(text, children) {
|
|
|
36
33
|
* @param props - props from this instance of Option
|
|
37
34
|
* @param ref - reference to root HTMLElement of Option
|
|
38
35
|
*/
|
|
39
|
-
|
|
40
|
-
|
|
41
36
|
export const useOption_unstable = (props, ref) => {
|
|
42
37
|
const {
|
|
43
38
|
children,
|
|
@@ -47,17 +42,17 @@ export const useOption_unstable = (props, ref) => {
|
|
|
47
42
|
} = props;
|
|
48
43
|
const optionRef = React.useRef(null);
|
|
49
44
|
const optionText = getTextString(text, children);
|
|
50
|
-
const optionValue = value !== null && value !== void 0 ? value : optionText;
|
|
51
|
-
|
|
52
|
-
const id = useId('fluent-option', props.id);
|
|
53
|
-
|
|
45
|
+
const optionValue = value !== null && value !== void 0 ? value : optionText;
|
|
46
|
+
// use the id if provided, otherwise use a generated id
|
|
47
|
+
const id = useId('fluent-option', props.id);
|
|
48
|
+
// data used for context registration & events
|
|
54
49
|
const optionData = React.useMemo(() => ({
|
|
55
50
|
id,
|
|
56
51
|
disabled,
|
|
57
52
|
text: optionText,
|
|
58
53
|
value: optionValue
|
|
59
|
-
}), [id, disabled, optionText, optionValue]);
|
|
60
|
-
|
|
54
|
+
}), [id, disabled, optionText, optionValue]);
|
|
55
|
+
// context values
|
|
61
56
|
const focusVisible = useContextSelector(ListboxContext, ctx => ctx.focusVisible);
|
|
62
57
|
const multiselect = useContextSelector(ListboxContext, ctx => ctx.multiselect);
|
|
63
58
|
const registerOption = useContextSelector(ListboxContext, ctx => ctx.registerOption);
|
|
@@ -67,41 +62,34 @@ export const useOption_unstable = (props, ref) => {
|
|
|
67
62
|
});
|
|
68
63
|
const selectOption = useContextSelector(ListboxContext, ctx => ctx.selectOption);
|
|
69
64
|
const setActiveOption = useContextSelector(ListboxContext, ctx => ctx.setActiveOption);
|
|
70
|
-
const setOpen = useContextSelector(ComboboxContext, ctx => ctx.setOpen);
|
|
71
|
-
|
|
65
|
+
const setOpen = useContextSelector(ComboboxContext, ctx => ctx.setOpen);
|
|
66
|
+
// current active option?
|
|
72
67
|
const active = useContextSelector(ListboxContext, ctx => {
|
|
73
68
|
var _a, _b;
|
|
74
|
-
|
|
75
69
|
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;
|
|
76
|
-
});
|
|
77
|
-
|
|
70
|
+
});
|
|
71
|
+
// check icon
|
|
78
72
|
let CheckIcon = /*#__PURE__*/React.createElement(CheckmarkFilled, null);
|
|
79
|
-
|
|
80
73
|
if (multiselect) {
|
|
81
74
|
CheckIcon = selected ? /*#__PURE__*/React.createElement(CheckboxCheckedFilled, null) : /*#__PURE__*/React.createElement(CheckboxUncheckedFilled, null);
|
|
82
75
|
}
|
|
83
|
-
|
|
84
76
|
const onClick = event => {
|
|
85
77
|
var _a;
|
|
86
|
-
|
|
87
78
|
if (disabled) {
|
|
88
79
|
event.preventDefault();
|
|
89
80
|
return;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
81
|
+
}
|
|
82
|
+
// clicked option should always become active option
|
|
83
|
+
setActiveOption(optionData);
|
|
84
|
+
// close on option click for single-select options in a combobox
|
|
95
85
|
if (!multiselect) {
|
|
96
86
|
setOpen === null || setOpen === void 0 ? void 0 : setOpen(event, false);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
|
|
87
|
+
}
|
|
88
|
+
// handle selection change
|
|
100
89
|
selectOption(event, optionData);
|
|
101
90
|
(_a = props.onClick) === null || _a === void 0 ? void 0 : _a.call(props, event);
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
|
|
91
|
+
};
|
|
92
|
+
// register option data with context
|
|
105
93
|
React.useEffect(() => {
|
|
106
94
|
if (id && optionRef.current) {
|
|
107
95
|
return registerOption(optionData, optionRef.current);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SAASC,qBAAqB,EAAEC,gBAAgB,EAAEC,KAAK,EAAEC,aAAa,QAAQ,2BAA2B;AACzG,SAASC,kBAAkB,QAAQ,kCAAkC;AACrE,SAASC,eAAe,EAAEC,uBAAuB,EAAEC,qBAAqB,QAAQ,uBAAuB;AACvG,SAASC,eAAe,QAAQ,gCAAgC;AAChE,SAASC,cAAc,QAAQ,+BAA+B;AAI9D,SAASC,aAAa,CAACC,IA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","resolveShorthand","useId","useMergedRefs","useContextSelector","CheckmarkFilled","CheckboxUncheckedFilled","CheckboxCheckedFilled","ComboboxContext","ListboxContext","getTextString","text","children","undefined","textString","hasNonStringChild","Children","forEach","child","console","warn","useOption_unstable","props","ref","disabled","value","optionRef","useRef","optionText","optionValue","id","optionData","useMemo","focusVisible","ctx","multiselect","registerOption","selected","selectedOptions","find","o","selectOption","setActiveOption","setOpen","active","activeOption","CheckIcon","onClick","event","preventDefault","useEffect","current","semanticProps","role","components","root","checkIcon","required","defaultProps"],"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"]}
|