@fluentui/react-combobox 9.2.6 → 9.2.8

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 CHANGED
@@ -2,34 +2,88 @@
2
2
  "name": "@fluentui/react-combobox",
3
3
  "entries": [
4
4
  {
5
- "date": "Thu, 23 Mar 2023 12:28:45 GMT",
6
- "tag": "@fluentui/react-combobox_v9.2.6",
7
- "version": "9.2.6",
5
+ "date": "Thu, 06 Apr 2023 23:59:46 GMT",
6
+ "tag": "@fluentui/react-combobox_v9.2.8",
7
+ "version": "9.2.8",
8
8
  "comments": {
9
9
  "patch": [
10
+ {
11
+ "author": "behowell@microsoft.com",
12
+ "package": "@fluentui/react-combobox",
13
+ "commit": "eee5716e76dc6a5bef9316546a352694bbe5750a",
14
+ "comment": "chore: Update package version of react-field"
15
+ },
16
+ {
17
+ "author": "behowell@microsoft.com",
18
+ "package": "@fluentui/react-combobox",
19
+ "commit": "5a8d7a29645b3b500eb7145d2e42ac34fcafc4c6",
20
+ "comment": "chore: Hook up FieldContext for use inside a Field"
21
+ },
10
22
  {
11
23
  "author": "beachball",
12
24
  "package": "@fluentui/react-combobox",
13
- "comment": "Bump @fluentui/react-field to v9.0.0-alpha.28",
14
- "commit": "be0ca69899300abe3c8478c435e0f6837138479b"
25
+ "comment": "Bump @fluentui/react-field to v9.0.0-beta.1",
26
+ "commit": "7a46cab3d31a233b89b7188e994b24712af5393c"
27
+ }
28
+ ]
29
+ }
30
+ },
31
+ {
32
+ "date": "Tue, 04 Apr 2023 18:44:48 GMT",
33
+ "tag": "@fluentui/react-combobox_v9.2.7",
34
+ "version": "9.2.7",
35
+ "comments": {
36
+ "patch": [
37
+ {
38
+ "author": "seanmonahan@microsoft.com",
39
+ "package": "@fluentui/react-combobox",
40
+ "commit": "83c18ac81b068a45f6ea4d3b7912d5d6873e9d06",
41
+ "comment": "fix: make Option's checkIcon slot render conditionally"
15
42
  },
16
43
  {
17
44
  "author": "beachball",
18
45
  "package": "@fluentui/react-combobox",
19
- "comment": "Bump @fluentui/react-portal to v9.2.3",
20
- "commit": "be0ca69899300abe3c8478c435e0f6837138479b"
46
+ "comment": "Bump @fluentui/react-context-selector to v9.1.16",
47
+ "commit": "6778d76bbbad7e1975c151c797f28c2708cde2ce"
21
48
  },
22
49
  {
23
50
  "author": "beachball",
24
51
  "package": "@fluentui/react-combobox",
25
- "comment": "Bump @fluentui/react-positioning to v9.5.7",
26
- "commit": "be0ca69899300abe3c8478c435e0f6837138479b"
52
+ "comment": "Bump @fluentui/react-field to v9.0.0-alpha.29",
53
+ "commit": "6778d76bbbad7e1975c151c797f28c2708cde2ce"
27
54
  },
28
55
  {
29
56
  "author": "beachball",
30
57
  "package": "@fluentui/react-combobox",
31
- "comment": "Bump @fluentui/react-shared-contexts to v9.3.3",
32
- "commit": "be0ca69899300abe3c8478c435e0f6837138479b"
58
+ "comment": "Bump @fluentui/react-portal to v9.2.4",
59
+ "commit": "6778d76bbbad7e1975c151c797f28c2708cde2ce"
60
+ },
61
+ {
62
+ "author": "beachball",
63
+ "package": "@fluentui/react-combobox",
64
+ "comment": "Bump @fluentui/react-positioning to v9.5.8",
65
+ "commit": "6778d76bbbad7e1975c151c797f28c2708cde2ce"
66
+ },
67
+ {
68
+ "author": "beachball",
69
+ "package": "@fluentui/react-combobox",
70
+ "comment": "Bump @fluentui/react-utilities to v9.7.3",
71
+ "commit": "6778d76bbbad7e1975c151c797f28c2708cde2ce"
72
+ }
73
+ ]
74
+ }
75
+ },
76
+ {
77
+ "date": "Fri, 24 Mar 2023 14:58:55 GMT",
78
+ "tag": "@fluentui/react-combobox_v9.2.6",
79
+ "version": "9.2.6",
80
+ "comments": {
81
+ "none": [
82
+ {
83
+ "author": "lingfangao@hotmail.com",
84
+ "package": "@fluentui/react-combobox",
85
+ "commit": "0f198d87130e4f9fcacdaa187b850e507e0b1ec8",
86
+ "comment": "Sync with latest released version on npm"
33
87
  }
34
88
  ]
35
89
  }
package/CHANGELOG.md CHANGED
@@ -1,20 +1,33 @@
1
1
  # Change Log - @fluentui/react-combobox
2
2
 
3
- This log was last generated on Thu, 23 Mar 2023 12:28:45 GMT and should not be manually modified.
3
+ This log was last generated on Thu, 06 Apr 2023 23:59:46 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
- ## [9.2.6](https://github.com/microsoft/fluentui/tree/@fluentui/react-combobox_v9.2.6)
7
+ ## [9.2.8](https://github.com/microsoft/fluentui/tree/@fluentui/react-combobox_v9.2.8)
8
8
 
9
- Thu, 23 Mar 2023 12:28:45 GMT
10
- [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-combobox_v9.2.5..@fluentui/react-combobox_v9.2.6)
9
+ Thu, 06 Apr 2023 23:59:46 GMT
10
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-combobox_v9.2.7..@fluentui/react-combobox_v9.2.8)
11
11
 
12
12
  ### Patches
13
13
 
14
- - Bump @fluentui/react-field to v9.0.0-alpha.28 ([PR #27286](https://github.com/microsoft/fluentui/pull/27286) by beachball)
15
- - Bump @fluentui/react-portal to v9.2.3 ([PR #27286](https://github.com/microsoft/fluentui/pull/27286) by beachball)
16
- - Bump @fluentui/react-positioning to v9.5.7 ([PR #27286](https://github.com/microsoft/fluentui/pull/27286) by beachball)
17
- - Bump @fluentui/react-shared-contexts to v9.3.3 ([PR #27286](https://github.com/microsoft/fluentui/pull/27286) by beachball)
14
+ - chore: Update package version of react-field ([PR #27458](https://github.com/microsoft/fluentui/pull/27458) by behowell@microsoft.com)
15
+ - chore: Hook up FieldContext for use inside a Field ([PR #27399](https://github.com/microsoft/fluentui/pull/27399) by behowell@microsoft.com)
16
+ - Bump @fluentui/react-field to v9.0.0-beta.1 ([PR #27420](https://github.com/microsoft/fluentui/pull/27420) by beachball)
17
+
18
+ ## [9.2.7](https://github.com/microsoft/fluentui/tree/@fluentui/react-combobox_v9.2.7)
19
+
20
+ Tue, 04 Apr 2023 18:44:48 GMT
21
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-combobox_v9.2.6..@fluentui/react-combobox_v9.2.7)
22
+
23
+ ### Patches
24
+
25
+ - fix: make Option's checkIcon slot render conditionally ([PR #27409](https://github.com/microsoft/fluentui/pull/27409) by seanmonahan@microsoft.com)
26
+ - Bump @fluentui/react-context-selector to v9.1.16 ([PR #27434](https://github.com/microsoft/fluentui/pull/27434) by beachball)
27
+ - Bump @fluentui/react-field to v9.0.0-alpha.29 ([PR #27434](https://github.com/microsoft/fluentui/pull/27434) by beachball)
28
+ - Bump @fluentui/react-portal to v9.2.4 ([PR #27434](https://github.com/microsoft/fluentui/pull/27434) by beachball)
29
+ - Bump @fluentui/react-positioning to v9.5.8 ([PR #27434](https://github.com/microsoft/fluentui/pull/27434) by beachball)
30
+ - Bump @fluentui/react-utilities to v9.7.3 ([PR #27434](https://github.com/microsoft/fluentui/pull/27434) by beachball)
18
31
 
19
32
  ## [9.2.5](https://github.com/microsoft/fluentui/tree/@fluentui/react-combobox_v9.2.5)
20
33
 
@@ -1,4 +1,5 @@
1
1
  import * as React from 'react';
2
+ import { useFieldControlProps_unstable } from '@fluentui/react-field';
2
3
  import { ArrowLeft, ArrowRight } from '@fluentui/keyboard-keys';
3
4
  import { ChevronDownRegular as ChevronDownIcon } from '@fluentui/react-icons';
4
5
  import { getPartitionedNativeProps, resolveShorthand, mergeCallbacks, useEventCallback, useId, useMergedRefs } from '@fluentui/react-utilities';
@@ -18,6 +19,12 @@ import { Listbox } from '../Listbox/Listbox';
18
19
  */
19
20
  export const useCombobox_unstable = (props, ref) => {
20
21
  var _props_input;
22
+ // Merge props from surrounding <Field>, if any
23
+ props = useFieldControlProps_unstable(props, {
24
+ supportsLabelFor: true,
25
+ supportsRequired: true,
26
+ supportsSize: true
27
+ });
21
28
  const baseState = useComboboxBaseState({
22
29
  ...props,
23
30
  editable: true
@@ -1 +1 @@
1
- {"version":3,"names":["React","ArrowLeft","ArrowRight","ChevronDownRegular","ChevronDownIcon","getPartitionedNativeProps","resolveShorthand","mergeCallbacks","useEventCallback","useId","useMergedRefs","getDropdownActionFromKey","useComboboxBaseState","useComboboxPopup","useTriggerListboxSlots","Listbox","useCombobox_unstable","props","ref","_props_input","baseState","editable","activeOption","clearSelection","getIndexOfId","getOptionsMatchingText","hasFocus","open","selectOption","selectedOptions","setActiveOption","setFocusVisible","setOpen","setValue","value","disabled","freeform","inlinePopup","multiselect","comboId","primary","triggerNativeProps","root","rootNativeProps","primarySlotTagName","excludedPropNames","rootRef","useRef","triggerRef","hideActiveDescendant","setHideActiveDescendant","useState","popupDimensions","setPopupDimensions","useEffect","_rootRef_current","width","current","clientWidth","getOptionFromInput","inputValue","searchString","trim","toLowerCase","length","matcher","optionText","indexOf","matches","startIndex","id","nextMatch","find","option","_matches_","undefined","ev","onTriggerBlur","text","newState","onTriggerChange","target","matchingOption","onTriggerKeyDown","key","triggerSlot","listboxSlot","input","required","defaultProps","type","onChange","onBlur","onKeyDown","listbox","children","style","state","components","expandIcon","createElement","role","onMouseDown","onIconMouseDown","onClick","onIconClick","onExpandIconMouseDown","ignoreNextBlur","onExpandIconClick","event","_triggerRef_current","focus","hasExpandLabel","defaultOpenString","_state_expandIcon_id","chevronId","chevronLabelledBy"],"sources":["../../../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?.text.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 (!multiselect && selectedOptions.length === 1 && (inputValue.length < 1 || !matchingOption)) {\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"],"mappings":"AAAA,YAAYA,KAAA,MAAW;AACvB,SAASC,SAAS,EAAEC,UAAU,QAAQ;AACtC,SAASC,kBAAA,IAAsBC,eAAe,QAAQ;AACtD,SACEC,yBAAyB,EACzBC,gBAAgB,EAChBC,cAAc,EACdC,gBAAgB,EAChBC,KAAK,EACLC,aAAa,QACR;AACP,SAASC,wBAAwB,QAAQ;AACzC,SAASC,oBAAoB,QAAQ;AACrC,SAASC,gBAAgB,QAAQ;AACjC,SAASC,sBAAsB,QAAQ;AACvC,SAASC,OAAO,QAAQ;AAMxB;;;;;;;;;AASA,OAAO,MAAMC,oBAAA,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A,mBAAA,CAAoBC,KAAA;IAEpB;IACAhF,eAAA,CAAgB,KAAK;EACvB;EAGF,IAAIkE,KAAA,CAAME,UAAU,EAAE;IACpBF,KAAA,CAAME,UAAU,CAACG,WAAW,GAAGI,qBAAA;IAC/BT,KAAA,CAAME,UAAU,CAACK,OAAO,GAAGI,iBAAA;IAE3B;IACA;IACA;IACA;IACA;IACA;IACA,MAAMI,cAAA,GAAiBf,KAAA,CAAME,UAAU,CAAC,aAAa,IAAIF,KAAA,CAAME,UAAU,CAAC,kBAAkB;IAC5F,MAAMc,iBAAA,GAAoB,QAAQ;IAClC,IAAI,CAACD,cAAA,EAAgB;MACnB,IAAI/F,KAAK,CAAC,kBAAkB,EAAE;YACViG,oBAAA;QAAlB,MAAMC,SAAA,GAAY,CAAAD,oBAAA,GAAAjB,KAAA,CAAME,UAAU,CAAC7B,EAAE,cAAnB4C,oBAAA,cAAAA,oBAAA,GAAwB,GAAE3E,OAAQ,UAAS;QAC7D,MAAM6E,iBAAA,GAAqB,GAAED,SAAU,IAAGlB,KAAA,CAAMV,KAAK,CAAC,kBAAmB,EAAC;QAE1EU,KAAA,CAAME,UAAU,CAAC,aAAa,GAAGc,iBAAA;QACjChB,KAAA,CAAME,UAAU,CAAC7B,EAAE,GAAG6C,SAAA;QACtBlB,KAAA,CAAME,UAAU,CAAC,kBAAkB,GAAGiB,iBAAA;MACxC,OAAO,IAAInG,KAAK,CAAC,aAAa,EAAE;QAC9BgF,KAAA,CAAME,UAAU,CAAC,aAAa,GAAI,GAAEc,iBAAkB,IAAGhG,KAAK,CAAC,aAAc,EAAC;MAChF,OAAO;QACLgF,KAAA,CAAME,UAAU,CAAC,aAAa,GAAGc,iBAAA;MACnC;IACF;EACF;EAEA,OAAOhB,KAAA;AACT"}
1
+ {"version":3,"names":["React","useFieldControlProps_unstable","ArrowLeft","ArrowRight","ChevronDownRegular","ChevronDownIcon","getPartitionedNativeProps","resolveShorthand","mergeCallbacks","useEventCallback","useId","useMergedRefs","getDropdownActionFromKey","useComboboxBaseState","useComboboxPopup","useTriggerListboxSlots","Listbox","useCombobox_unstable","props","ref","_props_input","supportsLabelFor","supportsRequired","supportsSize","baseState","editable","activeOption","clearSelection","getIndexOfId","getOptionsMatchingText","hasFocus","open","selectOption","selectedOptions","setActiveOption","setFocusVisible","setOpen","setValue","value","disabled","freeform","inlinePopup","multiselect","comboId","primary","triggerNativeProps","root","rootNativeProps","primarySlotTagName","excludedPropNames","rootRef","useRef","triggerRef","hideActiveDescendant","setHideActiveDescendant","useState","popupDimensions","setPopupDimensions","useEffect","_rootRef_current","width","current","clientWidth","getOptionFromInput","inputValue","searchString","trim","toLowerCase","length","matcher","optionText","indexOf","matches","startIndex","id","nextMatch","find","option","_matches_","undefined","ev","onTriggerBlur","text","newState","onTriggerChange","target","matchingOption","onTriggerKeyDown","key","triggerSlot","listboxSlot","input","required","defaultProps","type","onChange","onBlur","onKeyDown","listbox","children","style","state","components","expandIcon","createElement","role","onMouseDown","onIconMouseDown","onClick","onIconClick","onExpandIconMouseDown","ignoreNextBlur","onExpandIconClick","event","_triggerRef_current","focus","hasExpandLabel","defaultOpenString","_state_expandIcon_id","chevronId","chevronLabelledBy"],"sources":["../../../src/components/Combobox/useCombobox.tsx"],"sourcesContent":["import * as React from 'react';\nimport { useFieldControlProps_unstable } from '@fluentui/react-field';\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 // Merge props from surrounding <Field>, if any\n props = useFieldControlProps_unstable(props, { supportsLabelFor: true, supportsRequired: true, supportsSize: true });\n\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?.text.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 (!multiselect && selectedOptions.length === 1 && (inputValue.length < 1 || !matchingOption)) {\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"],"mappings":"AAAA,YAAYA,KAAA,MAAW;AACvB,SAASC,6BAA6B,QAAQ;AAC9C,SAASC,SAAS,EAAEC,UAAU,QAAQ;AACtC,SAASC,kBAAA,IAAsBC,eAAe,QAAQ;AACtD,SACEC,yBAAyB,EACzBC,gBAAgB,EAChBC,cAAc,EACdC,gBAAgB,EAChBC,KAAK,EACLC,aAAa,QACR;AACP,SAASC,wBAAwB,QAAQ;AACzC,SAASC,oBAAoB,QAAQ;AACrC,SAASC,gBAAgB,QAAQ;A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O;QACLmF,KAAA,CAAME,UAAU,CAAC,aAAa,GAAGc,iBAAA;MACnC;IACF;EACF;EAEA,OAAOhB,KAAA;AACT"}
@@ -1,4 +1,5 @@
1
1
  import * as React from 'react';
2
+ import { useFieldControlProps_unstable } from '@fluentui/react-field';
2
3
  import { ChevronDownRegular as ChevronDownIcon } from '@fluentui/react-icons';
3
4
  import { getPartitionedNativeProps, mergeCallbacks, resolveShorthand, useTimeout } from '@fluentui/react-utilities';
4
5
  import { getDropdownActionFromKey } from '../../utils/dropdownKeyActions';
@@ -17,6 +18,11 @@ import { useMergedRefs } from '@fluentui/react-utilities';
17
18
  * @param ref - reference to root HTMLElement of Dropdown
18
19
  */
19
20
  export const useDropdown_unstable = (props, ref) => {
21
+ // Merge props from surrounding <Field>, if any
22
+ props = useFieldControlProps_unstable(props, {
23
+ supportsLabelFor: true,
24
+ supportsSize: true
25
+ });
20
26
  const baseState = useComboboxBaseState(props);
21
27
  const {
22
28
  activeOption,
@@ -1 +1 @@
1
- {"version":3,"names":["React","ChevronDownRegular","ChevronDownIcon","getPartitionedNativeProps","mergeCallbacks","resolveShorthand","useTimeout","getDropdownActionFromKey","useComboboxBaseState","useComboboxPopup","useTriggerListboxSlots","Listbox","useMergedRefs","useDropdown_unstable","props","ref","baseState","activeOption","getIndexOfId","getOptionsMatchingText","open","setActiveOption","setFocusVisible","setOpen","primary","triggerNativeProps","root","rootNativeProps","primarySlotTagName","excludedPropNames","rootRef","useRef","popupWidth","setPopupWidth","useState","useEffect","_rootRef_current","width","current","clientWidth","undefined","searchString","setKeyTimeout","clearKeyTimeout","getNextMatchingOption","matcher","optionText","toLowerCase","indexOf","matches","startIndex","id","length","letters","split","allSameLetter","every","letter","nextMatch","find","option","_matches_","onTriggerKeyDown","ev","key","nextOption","triggerSlot","listboxSlot","button","required","defaultProps","type","children","value","placeholder","onKeyDown","hasFocus","listbox","style","state","components","expandIcon","inlinePopup","createElement","placeholderVisible"],"sources":["../../../src/components/Dropdown/useDropdown.tsx"],"sourcesContent":["import * as React from 'react';\nimport { ChevronDownRegular as ChevronDownIcon } from '@fluentui/react-icons';\nimport { getPartitionedNativeProps, mergeCallbacks, resolveShorthand, useTimeout } 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 { OptionValue } from '../../utils/OptionCollection.types';\nimport type { DropdownProps, DropdownState } from './Dropdown.types';\nimport { useMergedRefs } from '@fluentui/react-utilities';\n\n/**\n * Create the state required to render Dropdown.\n *\n * The returned state can be modified with hooks such as useDropdownStyles_unstable,\n * before being passed to renderDropdown_unstable.\n *\n * @param props - props from this instance of Dropdown\n * @param ref - reference to root HTMLElement of Dropdown\n */\nexport const useDropdown_unstable = (props: DropdownProps, ref: React.Ref<HTMLButtonElement>): DropdownState => {\n const baseState = useComboboxBaseState(props);\n const { activeOption, getIndexOfId, getOptionsMatchingText, open, setActiveOption, setFocusVisible, setOpen } =\n baseState;\n\n const { primary: triggerNativeProps, root: rootNativeProps } = getPartitionedNativeProps({\n props,\n primarySlotTagName: 'button',\n excludedPropNames: ['children'],\n });\n\n // set listbox popup width based off the root/trigger width\n const rootRef = React.useRef<HTMLDivElement>(null);\n const [popupWidth, setPopupWidth] = React.useState<string>();\n React.useEffect(() => {\n const width = open ? `${rootRef.current?.clientWidth}px` : undefined;\n setPopupWidth(width);\n }, [open]);\n\n // jump to matching option based on typing\n const searchString = React.useRef('');\n const [setKeyTimeout, clearKeyTimeout] = useTimeout();\n\n const getNextMatchingOption = (): OptionValue | undefined => {\n // first check for matches for the full searchString\n let matcher = (optionText: string) => optionText.toLowerCase().indexOf(searchString.current) === 0;\n let matches = getOptionsMatchingText(matcher);\n let startIndex = activeOption ? getIndexOfId(activeOption.id) : 0;\n\n // if the dropdown is already open and the searchstring is a single character,\n // then look after the current activeOption for letters\n // this is so slowly typing the same letter will cycle through matches\n if (open && searchString.current.length === 1) {\n startIndex++;\n }\n\n // if there are no direct matches, check if the search is all the same letter, e.g. \"aaa\"\n if (!matches.length) {\n const letters = searchString.current.split('');\n const allSameLetter = letters.length && letters.every(letter => letter === letters[0]);\n\n // if the search is all the same letter, cycle through options starting with that letter\n if (allSameLetter) {\n startIndex++;\n matcher = (optionText: string) => optionText.toLowerCase().indexOf(letters[0]) === 0;\n matches = getOptionsMatchingText(matcher);\n }\n }\n\n // if there is an active option and multiple matches,\n // return first matching option after the current active option, looping back to the top\n if (matches.length > 1 && activeOption) {\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 const onTriggerKeyDown = (ev: React.KeyboardEvent<HTMLButtonElement>) => {\n // clear timeout, if it exists\n clearKeyTimeout();\n\n // if the key was a char key, update search string\n if (getDropdownActionFromKey(ev) === 'Type') {\n // update search string\n searchString.current += ev.key.toLowerCase();\n setKeyTimeout(() => {\n searchString.current = '';\n }, 500);\n\n // update state\n !open && setOpen(ev, true);\n\n const nextOption = getNextMatchingOption();\n setActiveOption(nextOption);\n setFocusVisible(true);\n }\n };\n\n // resolve button and listbox slot props\n let triggerSlot: Slot<'button'>;\n let listboxSlot: Slot<typeof Listbox> | undefined;\n\n triggerSlot = resolveShorthand(props.button, {\n required: true,\n defaultProps: {\n type: 'button',\n children: baseState.value || props.placeholder,\n ...triggerNativeProps,\n },\n });\n\n triggerSlot.onKeyDown = mergeCallbacks(onTriggerKeyDown, triggerSlot.onKeyDown);\n\n listboxSlot =\n baseState.open || baseState.hasFocus\n ? resolveShorthand(props.listbox, {\n required: true,\n defaultProps: {\n children: props.children,\n style: { width: popupWidth },\n },\n })\n : undefined;\n\n [triggerSlot, listboxSlot] = useComboboxPopup(props, triggerSlot, listboxSlot);\n [triggerSlot, listboxSlot] = useTriggerListboxSlots(props, baseState, ref, triggerSlot, listboxSlot);\n\n const state: DropdownState = {\n components: {\n root: 'div',\n button: 'button',\n expandIcon: 'span',\n listbox: Listbox,\n },\n root: resolveShorthand(props.root, {\n required: true,\n defaultProps: {\n 'aria-owns': !props.inlinePopup ? listboxSlot?.id : undefined,\n children: props.children,\n ...rootNativeProps,\n },\n }),\n button: triggerSlot,\n listbox: listboxSlot,\n expandIcon: resolveShorthand(props.expandIcon, {\n required: true,\n defaultProps: {\n children: <ChevronDownIcon />,\n },\n }),\n placeholderVisible: !baseState.value && !!props.placeholder,\n ...baseState,\n };\n\n state.root.ref = useMergedRefs(state.root.ref, rootRef);\n\n return state;\n};\n"],"mappings":"AAAA,YAAYA,KAAA,MAAW;AACvB,SAASC,kBAAA,IAAsBC,eAAe,QAAQ;AACtD,SAASC,yBAAyB,EAAEC,cAAc,EAAEC,gBAAgB,EAAEC,UAAU,QAAQ;AACxF,SAASC,wBAAwB,QAAQ;AACzC,SAASC,oBAAoB,QAAQ;AACrC,SAASC,gBAAgB,QAAQ;AACjC,SAASC,sBAAsB,QAAQ;AACvC,SAASC,OAAO,QAAQ;AAIxB,SAASC,aAAa,QAAQ;AAE9B;;;;;;;;;AASA,OAAO,MAAMC,oBAAA,GAAuBA,CAACC,KAAA,EAAsBC,GAAA,KAAqD;EAC9G,MAAMC,SAAA,GAAYR,oBAAA,CAAqBM,KAAA;EACvC,MAAM;IAAEG,YAAA;IAAcC,YAAA;IAAcC,sBAAA;IAAwBC,IAAA;IAAMC,eAAA;IAAiBC,eAAA;IAAiBC;EAAO,CAAE,GAC3GP,SAAA;EAEF,MAAM;IAAEQ,OAAA,EAASC,kBAAA;IAAoBC,IAAA,EAAMC;EAAe,CAAE,GAAGxB,yBAAA,CAA0B;IACvFW,KAAA;IACAc,kBAAA,EAAoB;IACpBC,iBAAA,EAAmB,CAAC;EACtB;EAEA;EACA,MAAMC,OAAA,GAAU9B,KAAA,CAAM+B,M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AG1D;EACL;EAEA+D,KAAA,CAAMrD,IAAI,CAACX,GAAG,GAAGH,aAAA,CAAcmE,KAAA,CAAMrD,IAAI,CAACX,GAAG,EAAEe,OAAA;EAE/C,OAAOiD,KAAA;AACT"}
1
+ {"version":3,"names":["React","useFieldControlProps_unstable","ChevronDownRegular","ChevronDownIcon","getPartitionedNativeProps","mergeCallbacks","resolveShorthand","useTimeout","getDropdownActionFromKey","useComboboxBaseState","useComboboxPopup","useTriggerListboxSlots","Listbox","useMergedRefs","useDropdown_unstable","props","ref","supportsLabelFor","supportsSize","baseState","activeOption","getIndexOfId","getOptionsMatchingText","open","setActiveOption","setFocusVisible","setOpen","primary","triggerNativeProps","root","rootNativeProps","primarySlotTagName","excludedPropNames","rootRef","useRef","popupWidth","setPopupWidth","useState","useEffect","_rootRef_current","width","current","clientWidth","undefined","searchString","setKeyTimeout","clearKeyTimeout","getNextMatchingOption","matcher","optionText","toLowerCase","indexOf","matches","startIndex","id","length","letters","split","allSameLetter","every","letter","nextMatch","find","option","_matches_","onTriggerKeyDown","ev","key","nextOption","triggerSlot","listboxSlot","button","required","defaultProps","type","children","value","placeholder","onKeyDown","hasFocus","listbox","style","state","components","expandIcon","inlinePopup","createElement","placeholderVisible"],"sources":["../../../src/components/Dropdown/useDropdown.tsx"],"sourcesContent":["import * as React from 'react';\nimport { useFieldControlProps_unstable } from '@fluentui/react-field';\nimport { ChevronDownRegular as ChevronDownIcon } from '@fluentui/react-icons';\nimport { getPartitionedNativeProps, mergeCallbacks, resolveShorthand, useTimeout } 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 { OptionValue } from '../../utils/OptionCollection.types';\nimport type { DropdownProps, DropdownState } from './Dropdown.types';\nimport { useMergedRefs } from '@fluentui/react-utilities';\n\n/**\n * Create the state required to render Dropdown.\n *\n * The returned state can be modified with hooks such as useDropdownStyles_unstable,\n * before being passed to renderDropdown_unstable.\n *\n * @param props - props from this instance of Dropdown\n * @param ref - reference to root HTMLElement of Dropdown\n */\nexport const useDropdown_unstable = (props: DropdownProps, ref: React.Ref<HTMLButtonElement>): DropdownState => {\n // Merge props from surrounding <Field>, if any\n props = useFieldControlProps_unstable(props, { supportsLabelFor: true, supportsSize: true });\n\n const baseState = useComboboxBaseState(props);\n const { activeOption, getIndexOfId, getOptionsMatchingText, open, setActiveOption, setFocusVisible, setOpen } =\n baseState;\n\n const { primary: triggerNativeProps, root: rootNativeProps } = getPartitionedNativeProps({\n props,\n primarySlotTagName: 'button',\n excludedPropNames: ['children'],\n });\n\n // set listbox popup width based off the root/trigger width\n const rootRef = React.useRef<HTMLDivElement>(null);\n const [popupWidth, setPopupWidth] = React.useState<string>();\n React.useEffect(() => {\n const width = open ? `${rootRef.current?.clientWidth}px` : undefined;\n setPopupWidth(width);\n }, [open]);\n\n // jump to matching option based on typing\n const searchString = React.useRef('');\n const [setKeyTimeout, clearKeyTimeout] = useTimeout();\n\n const getNextMatchingOption = (): OptionValue | undefined => {\n // first check for matches for the full searchString\n let matcher = (optionText: string) => optionText.toLowerCase().indexOf(searchString.current) === 0;\n let matches = getOptionsMatchingText(matcher);\n let startIndex = activeOption ? getIndexOfId(activeOption.id) : 0;\n\n // if the dropdown is already open and the searchstring is a single character,\n // then look after the current activeOption for letters\n // this is so slowly typing the same letter will cycle through matches\n if (open && searchString.current.length === 1) {\n startIndex++;\n }\n\n // if there are no direct matches, check if the search is all the same letter, e.g. \"aaa\"\n if (!matches.length) {\n const letters = searchString.current.split('');\n const allSameLetter = letters.length && letters.every(letter => letter === letters[0]);\n\n // if the search is all the same letter, cycle through options starting with that letter\n if (allSameLetter) {\n startIndex++;\n matcher = (optionText: string) => optionText.toLowerCase().indexOf(letters[0]) === 0;\n matches = getOptionsMatchingText(matcher);\n }\n }\n\n // if there is an active option and multiple matches,\n // return first matching option after the current active option, looping back to the top\n if (matches.length > 1 && activeOption) {\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 const onTriggerKeyDown = (ev: React.KeyboardEvent<HTMLButtonElement>) => {\n // clear timeout, if it exists\n clearKeyTimeout();\n\n // if the key was a char key, update search string\n if (getDropdownActionFromKey(ev) === 'Type') {\n // update search string\n searchString.current += ev.key.toLowerCase();\n setKeyTimeout(() => {\n searchString.current = '';\n }, 500);\n\n // update state\n !open && setOpen(ev, true);\n\n const nextOption = getNextMatchingOption();\n setActiveOption(nextOption);\n setFocusVisible(true);\n }\n };\n\n // resolve button and listbox slot props\n let triggerSlot: Slot<'button'>;\n let listboxSlot: Slot<typeof Listbox> | undefined;\n\n triggerSlot = resolveShorthand(props.button, {\n required: true,\n defaultProps: {\n type: 'button',\n children: baseState.value || props.placeholder,\n ...triggerNativeProps,\n },\n });\n\n triggerSlot.onKeyDown = mergeCallbacks(onTriggerKeyDown, triggerSlot.onKeyDown);\n\n listboxSlot =\n baseState.open || baseState.hasFocus\n ? resolveShorthand(props.listbox, {\n required: true,\n defaultProps: {\n children: props.children,\n style: { width: popupWidth },\n },\n })\n : undefined;\n\n [triggerSlot, listboxSlot] = useComboboxPopup(props, triggerSlot, listboxSlot);\n [triggerSlot, listboxSlot] = useTriggerListboxSlots(props, baseState, ref, triggerSlot, listboxSlot);\n\n const state: DropdownState = {\n components: {\n root: 'div',\n button: 'button',\n expandIcon: 'span',\n listbox: Listbox,\n },\n root: resolveShorthand(props.root, {\n required: true,\n defaultProps: {\n 'aria-owns': !props.inlinePopup ? listboxSlot?.id : undefined,\n children: props.children,\n ...rootNativeProps,\n },\n }),\n button: triggerSlot,\n listbox: listboxSlot,\n expandIcon: resolveShorthand(props.expandIcon, {\n required: true,\n defaultProps: {\n children: <ChevronDownIcon />,\n },\n }),\n placeholderVisible: !baseState.value && !!props.placeholder,\n ...baseState,\n };\n\n state.root.ref = useMergedRefs(state.root.ref, rootRef);\n\n return state;\n};\n"],"mappings":"AAAA,YAAYA,KAAA,MAAW;AACvB,SAASC,6BAA6B,QAAQ;AAC9C,SAASC,kBAAA,IAAsBC,eAAe,QAAQ;AACtD,SAASC,yBAAyB,EAAEC,cAAc,EAAEC,gBAAgB,EAAEC,UAAU,QAAQ;AACxF,SAASC,wBAAwB,QAAQ;AACzC,SAASC,oBAAoB,QAAQ;AACrC,SAASC,gBAAgB,QAAQ;AACjC,SAASC,sBAAsB,QAAQ;AACvC,SAASC,OAAO,QAAQ;AAIxB,SAASC,aAAa,QAAQ;AAE9B;;;;;;;;;AASA,OAAO,MAAMC,oBAAA,GAAuBA,CAACC,KAAA,EAAsBC,GAAA,KAAqD;EAC9G;EACAD,KAAA,GAAQd,6BAAA,CAA8Bc,KAAA,EAAO;IAAEE,gBAAA,EAAkB,IAAI;IAAEC,YAAA,EAAc;EAAK;EAE1F,MAAMC,SAAA,GAAYV,oBAAA,CAAqBM,KAAA;EACvC,MAAM;IAAEK,YAAA;IAAcC,YAAA;IAAcC,sBAAA;IAAwBC,IAAA;IAAMC,eAAA;IAAiBC,eAAA;IAAiBC;EAAO,CAAE,GAC3GP,SAAA;EAEF,MAAM;IAAEQ,OAAA,EAASC,kBAAA;IAAoBC,IAAA,EAAMC;EAAe,CAAE,GAAG1B,yBAAA,CAA0B;IACvFW,KAAA;IACAgB,kBAAA,EAAoB;IACpBC,iBAAA,EAAmB,CAAC;EACtB;EAEA;EACA,MAAMC,OAAA,GAAUjC,KAAA,CAAMkC,MAAM,CAAiB,IAAI;EACjD,MAAM,CAACC,UAAA,EAAYC,aAAA,CAAc,GAAGpC,KAAA,CAAMqC,QAAQ;EAClDrC,KAAA,CAAMsC,SAAS,CAAC,MAAM;QACIC,gBAAA;IAAxB,MAAMC,KAAA,GAAQjB,IAAA,GAAQ,G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8
8
  slots,
9
9
  slotProps
10
10
  } = getSlots(state);
11
- return /*#__PURE__*/React.createElement(slots.root, slotProps.root, /*#__PURE__*/React.createElement(slots.checkIcon, slotProps.checkIcon), slotProps.root.children);
11
+ return /*#__PURE__*/React.createElement(slots.root, slotProps.root, slots.checkIcon && /*#__PURE__*/React.createElement(slots.checkIcon, slotProps.checkIcon), slotProps.root.children);
12
12
  };
13
13
  //# sourceMappingURL=renderOption.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["React","getSlots","renderOption_unstable","state","slots","slotProps","createElement","root","checkIcon","children"],"sources":["../../../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"],"mappings":"AAAA,YAAYA,KAAA,MAAW;AACvB,SAASC,QAAQ,QAAQ;AAGzB;;;AAGA,OAAO,MAAMC,qBAAA,GAAyBC,KAAA,IAAuB;EAC3D,MAAM;IAAEC,KAAA;IAAOC;EAAS,CAAE,GAAGJ,QAAA,CAAsBE,KAAA;EAEnD,oBACEH,KAAA,CAAAM,aAAA,CAACF,KAAA,CAAMG,IAAI,EAAKF,SAAA,CAAUE,IAAI,eAC5BP,KAAA,CAAAM,aAAA,CAACF,KAAA,CAAMI,SAAS,EAAKH,SAAA,CAAUG,SAAS,GACvCH,SAAA,CAAUE,IAAI,CAACE,QAAQ;AAG9B"}
1
+ {"version":3,"names":["React","getSlots","renderOption_unstable","state","slots","slotProps","createElement","root","checkIcon","children"],"sources":["../../../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 && <slots.checkIcon {...slotProps.checkIcon} />}\n {slotProps.root.children}\n </slots.root>\n );\n};\n"],"mappings":"AAAA,YAAYA,KAAA,MAAW;AACvB,SAASC,QAAQ,QAAQ;AAGzB;;;AAGA,OAAO,MAAMC,qBAAA,GAAyBC,KAAA,IAAuB;EAC3D,MAAM;IAAEC,KAAA;IAAOC;EAAS,CAAE,GAAGJ,QAAA,CAAsBE,KAAA;EAEnD,oBACEH,KAAA,CAAAM,aAAA,CAACF,KAAA,CAAMG,IAAI,EAAKF,SAAA,CAAUE,IAAI,EAC3BH,KAAA,CAAMI,SAAS,iBAAIR,KAAA,CAAAM,aAAA,CAACF,KAAA,CAAMI,SAAS,EAAKH,SAAA,CAAUG,SAAS,GAC3DH,SAAA,CAAUE,IAAI,CAACE,QAAQ;AAG9B"}
@@ -8,6 +8,7 @@ Object.defineProperty(exports, "useCombobox_unstable", {
8
8
  });
9
9
  const _interopRequireWildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default;
10
10
  const _react = /*#__PURE__*/ _interopRequireWildcard(require("react"));
11
+ const _reactField = require("@fluentui/react-field");
11
12
  const _keyboardKeys = require("@fluentui/keyboard-keys");
12
13
  const _reactIcons = require("@fluentui/react-icons");
13
14
  const _reactUtilities = require("@fluentui/react-utilities");
@@ -18,6 +19,12 @@ const _useTriggerListboxSlots = require("../../utils/useTriggerListboxSlots");
18
19
  const _listbox = require("../Listbox/Listbox");
19
20
  const useCombobox_unstable = (props, ref)=>{
20
21
  var _props_input;
22
+ // Merge props from surrounding <Field>, if any
23
+ props = (0, _reactField.useFieldControlProps_unstable)(props, {
24
+ supportsLabelFor: true,
25
+ supportsRequired: true,
26
+ supportsSize: true
27
+ });
21
28
  const baseState = (0, _useComboboxBaseState.useComboboxBaseState)({
22
29
  ...props,
23
30
  editable: true
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../lib/components/Combobox/useCombobox.js"],"sourcesContent":["import * as React from 'react';\nimport { ArrowLeft, ArrowRight } from '@fluentui/keyboard-keys';\nimport { ChevronDownRegular as ChevronDownIcon } from '@fluentui/react-icons';\nimport { getPartitionedNativeProps, resolveShorthand, mergeCallbacks, useEventCallback, useId, useMergedRefs } 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';\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, ref) => {\n var _props_input;\n const baseState = useComboboxBaseState({\n ...props,\n editable: true\n });\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 {\n disabled,\n freeform,\n inlinePopup,\n multiselect\n } = props;\n const comboId = useId('combobox-');\n const {\n primary: triggerNativeProps,\n root: rootNativeProps\n } = getPartitionedNativeProps({\n props,\n primarySlotTagName: 'input',\n excludedPropNames: ['children', 'size']\n });\n const rootRef = React.useRef(null);\n const triggerRef = React.useRef(null);\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 // calculate listbox width style based on trigger width\n const [popupDimensions, setPopupDimensions] = React.useState();\n React.useEffect(() => {\n // only recalculate width when opening\n if (open) {\n var _rootRef_current;\n const width = `${(_rootRef_current = rootRef.current) === null || _rootRef_current === void 0 ? void 0 : _rootRef_current.clientWidth}px`;\n if (width !== (popupDimensions === null || popupDimensions === void 0 ? void 0 : popupDimensions.width)) {\n setPopupDimensions({\n width\n });\n }\n }\n }, [open, popupDimensions]);\n // set active option and selection based on typing\n const getOptionFromInput = inputValue => {\n const searchString = inputValue === null || inputValue === void 0 ? void 0 : inputValue.trim().toLowerCase();\n if (!searchString || searchString.length === 0) {\n return;\n }\n const matcher = optionText => optionText.toLowerCase().indexOf(searchString) === 0;\n const matches = getOptionsMatchingText(matcher);\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 !== null && nextMatch !== void 0 ? nextMatch : matches[0];\n }\n var _matches_;\n return (_matches_ = matches[0]) !== null && _matches_ !== void 0 ? _matches_ : undefined;\n };\n /* Handle typed input */ // reset any typed value when an option is selected\n baseState.selectOption = (ev, option) => {\n setValue(undefined);\n selectOption(ev, option);\n };\n const onTriggerBlur = ev => {\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 === null || activeOption === void 0 ? void 0 : activeOption.text.toLowerCase())) {\n baseState.selectOption(ev, activeOption);\n }\n // reset typed value when the input loses focus while collapsed, unless freeform is true\n setValue(undefined);\n }\n };\n baseState.setOpen = (ev, newState) => {\n if (disabled) {\n return;\n }\n if (!newState && !freeform) {\n setValue(undefined);\n }\n setOpen(ev, newState);\n };\n // update value and active option based on input\n const onTriggerChange = ev => {\n const inputValue = ev.target.value;\n // update uncontrolled value\n baseState.setValue(inputValue);\n // handle updating active option based on input\n const matchingOption = getOptionFromInput(inputValue);\n setActiveOption(matchingOption);\n setFocusVisible(true);\n // clear selection for single-select if the input value no longer matches the selection\n if (!multiselect && selectedOptions.length === 1 && (inputValue.length < 1 || !matchingOption)) {\n clearSelection(ev);\n }\n };\n // open Combobox when typing\n const onTriggerKeyDown = ev => {\n if (!open && getDropdownActionFromKey(ev) === 'Type') {\n baseState.setOpen(ev, true);\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 // resolve input and listbox slot props\n let triggerSlot;\n let listboxSlot;\n triggerSlot = resolveShorthand(props.input, {\n required: true,\n defaultProps: {\n ref: useMergedRefs((_props_input = props.input) === null || _props_input === void 0 ? void 0 : _props_input.ref, triggerRef),\n type: 'text',\n value: value !== null && value !== void 0 ? value : '',\n ...triggerNativeProps\n }\n });\n triggerSlot.onChange = mergeCallbacks(triggerSlot.onChange, onTriggerChange);\n triggerSlot.onBlur = mergeCallbacks(triggerSlot.onBlur, onTriggerBlur);\n triggerSlot.onKeyDown = mergeCallbacks(triggerSlot.onKeyDown, onTriggerKeyDown);\n // only resolve listbox slot if needed\n listboxSlot = open || hasFocus ? resolveShorthand(props.listbox, {\n required: true,\n defaultProps: {\n children: props.children,\n style: popupDimensions\n }\n }) : undefined;\n [triggerSlot, listboxSlot] = useComboboxPopup(props, triggerSlot, listboxSlot);\n [triggerSlot, listboxSlot] = useTriggerListboxSlots(props, baseState, ref, triggerSlot, listboxSlot);\n if (hideActiveDescendant) {\n triggerSlot['aria-activedescendant'] = undefined;\n }\n const state = {\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 === null || listboxSlot === void 0 ? void 0 : 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: /*#__PURE__*/React.createElement(ChevronDownIcon, null),\n role: 'button'\n }\n }),\n ...baseState\n };\n state.root.ref = useMergedRefs(state.root.ref, rootRef);\n /* handle open/close + focus change when clicking expandIcon */\n const {\n onMouseDown: onIconMouseDown,\n onClick: onIconClick\n } = state.expandIcon || {};\n const onExpandIconMouseDown = useEventCallback(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 const onExpandIconClick = useEventCallback(mergeCallbacks(onIconClick, event => {\n var _triggerRef_current;\n // open and set focus\n state.setOpen(event, !state.open);\n (_triggerRef_current = triggerRef.current) === null || _triggerRef_current === void 0 ? void 0 : _triggerRef_current.focus();\n // set focus visible=false, since this can only be done with the mouse/pointer\n setFocusVisible(false);\n }));\n if (state.expandIcon) {\n state.expandIcon.onMouseDown = onExpandIconMouseDown;\n state.expandIcon.onClick = onExpandIconClick;\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 var _state_expandIcon_id;\n const chevronId = (_state_expandIcon_id = state.expandIcon.id) !== null && _state_expandIcon_id !== void 0 ? _state_expandIcon_id : `${comboId}-chevron`;\n const chevronLabelledBy = `${chevronId} ${state.input['aria-labelledby']}`;\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 return state;\n};\n//# sourceMappingURL=useCombobox.js.map"],"names":["useCombobox_unstable","props","ref","_props_input","baseState","useComboboxBaseState","editable","activeOption","clearSelection","getIndexOfId","getOptionsMatchingText","hasFocus","open","selectOption","selectedOptions","setActiveOption","setFocusVisible","setOpen","setValue","value","disabled","freeform","inlinePopup","multiselect","comboId","useId","primary","triggerNativeProps","root","rootNativeProps","getPartitionedNativeProps","primarySlotTagName","excludedPropNames","rootRef","React","useRef","triggerRef","hideActiveDescendant","setHideActiveDescendant","useState","popupDimensions","setPopupDimensions","useEffect","_rootRef_current","width","current","clientWidth","getOptionFromInput","inputValue","searchString","trim","toLowerCase","length","matcher","optionText","indexOf","matches","startIndex","id","nextMatch","find","option","_matches_","undefined","ev","onTriggerBlur","text","newState","onTriggerChange","target","matchingOption","onTriggerKeyDown","getDropdownActionFromKey","key","ArrowLeft","ArrowRight","triggerSlot","listboxSlot","resolveShorthand","input","required","defaultProps","useMergedRefs","type","onChange","mergeCallbacks","onBlur","onKeyDown","listbox","children","style","useComboboxPopup","useTriggerListboxSlots","state","components","expandIcon","Listbox","createElement","ChevronDownIcon","role","onMouseDown","onIconMouseDown","onClick","onIconClick","onExpandIconMouseDown","useEventCallback","ignoreNextBlur","onExpandIconClick","event","_triggerRef_current","focus","hasExpandLabel","defaultOpenString","_state_expandIcon_id","chevronId","chevronLabelledBy"],"mappings":";;;;+BAkBaA;;aAAAA;;;6DAlBU;8BACe;4BACgB;gCAC8D;oCAC3E;sCACJ;kCACJ;wCACM;yBACf;AAUjB,MAAMA,uBAAuB,CAACC,OAAOC,MAAQ;IAClD,IAAIC;IACJ,MAAMC,YAAYC,IAAAA,0CAAoB,EAAC;QACrC,GAAGJ,KAAK;QACRK,UAAU,IAAI;IAChB;IACA,MAAM,EACJC,aAAY,EACZC,eAAc,EACdC,aAAY,EACZC,uBAAsB,EACtBC,SAAQ,EACRC,KAAI,EACJC,aA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AAuB,CAAC,EAAEzF,QAAQ,QAAQ,CAAC;gBACxJ,MAAM2F,oBAAoB,CAAC,EAAED,UAAU,CAAC,EAAErB,MAAMd,KAAK,CAAC,kBAAkB,CAAC,CAAC;gBAC1Ec,MAAME,UAAU,CAAC,aAAa,GAAGiB;gBACjCnB,MAAME,UAAU,CAACrC,EAAE,GAAGwD;gBACtBrB,MAAME,UAAU,CAAC,kBAAkB,GAAGoB;YACxC,OAAO,IAAIlH,KAAK,CAAC,aAAa,EAAE;gBAC9B4F,MAAME,UAAU,CAAC,aAAa,GAAG,CAAC,EAAEiB,kBAAkB,CAAC,EAAE/G,KAAK,CAAC,aAAa,CAAC,CAAC;YAChF,OAAO;gBACL4F,MAAME,UAAU,CAAC,aAAa,GAAGiB;YACnC,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAOnB;AACT,GACA,uCAAuC"}
1
+ {"version":3,"sources":["../../../lib/components/Combobox/useCombobox.js"],"sourcesContent":["import * as React from 'react';\nimport { useFieldControlProps_unstable } from '@fluentui/react-field';\nimport { ArrowLeft, ArrowRight } from '@fluentui/keyboard-keys';\nimport { ChevronDownRegular as ChevronDownIcon } from '@fluentui/react-icons';\nimport { getPartitionedNativeProps, resolveShorthand, mergeCallbacks, useEventCallback, useId, useMergedRefs } 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';\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, ref) => {\n var _props_input;\n // Merge props from surrounding <Field>, if any\n props = useFieldControlProps_unstable(props, {\n supportsLabelFor: true,\n supportsRequired: true,\n supportsSize: true\n });\n const baseState = useComboboxBaseState({\n ...props,\n editable: true\n });\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 {\n disabled,\n freeform,\n inlinePopup,\n multiselect\n } = props;\n const comboId = useId('combobox-');\n const {\n primary: triggerNativeProps,\n root: rootNativeProps\n } = getPartitionedNativeProps({\n props,\n primarySlotTagName: 'input',\n excludedPropNames: ['children', 'size']\n });\n const rootRef = React.useRef(null);\n const triggerRef = React.useRef(null);\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 // calculate listbox width style based on trigger width\n const [popupDimensions, setPopupDimensions] = React.useState();\n React.useEffect(() => {\n // only recalculate width when opening\n if (open) {\n var _rootRef_current;\n const width = `${(_rootRef_current = rootRef.current) === null || _rootRef_current === void 0 ? void 0 : _rootRef_current.clientWidth}px`;\n if (width !== (popupDimensions === null || popupDimensions === void 0 ? void 0 : popupDimensions.width)) {\n setPopupDimensions({\n width\n });\n }\n }\n }, [open, popupDimensions]);\n // set active option and selection based on typing\n const getOptionFromInput = inputValue => {\n const searchString = inputValue === null || inputValue === void 0 ? void 0 : inputValue.trim().toLowerCase();\n if (!searchString || searchString.length === 0) {\n return;\n }\n const matcher = optionText => optionText.toLowerCase().indexOf(searchString) === 0;\n const matches = getOptionsMatchingText(matcher);\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 !== null && nextMatch !== void 0 ? nextMatch : matches[0];\n }\n var _matches_;\n return (_matches_ = matches[0]) !== null && _matches_ !== void 0 ? _matches_ : undefined;\n };\n /* Handle typed input */ // reset any typed value when an option is selected\n baseState.selectOption = (ev, option) => {\n setValue(undefined);\n selectOption(ev, option);\n };\n const onTriggerBlur = ev => {\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 === null || activeOption === void 0 ? void 0 : activeOption.text.toLowerCase())) {\n baseState.selectOption(ev, activeOption);\n }\n // reset typed value when the input loses focus while collapsed, unless freeform is true\n setValue(undefined);\n }\n };\n baseState.setOpen = (ev, newState) => {\n if (disabled) {\n return;\n }\n if (!newState && !freeform) {\n setValue(undefined);\n }\n setOpen(ev, newState);\n };\n // update value and active option based on input\n const onTriggerChange = ev => {\n const inputValue = ev.target.value;\n // update uncontrolled value\n baseState.setValue(inputValue);\n // handle updating active option based on input\n const matchingOption = getOptionFromInput(inputValue);\n setActiveOption(matchingOption);\n setFocusVisible(true);\n // clear selection for single-select if the input value no longer matches the selection\n if (!multiselect && selectedOptions.length === 1 && (inputValue.length < 1 || !matchingOption)) {\n clearSelection(ev);\n }\n };\n // open Combobox when typing\n const onTriggerKeyDown = ev => {\n if (!open && getDropdownActionFromKey(ev) === 'Type') {\n baseState.setOpen(ev, true);\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 // resolve input and listbox slot props\n let triggerSlot;\n let listboxSlot;\n triggerSlot = resolveShorthand(props.input, {\n required: true,\n defaultProps: {\n ref: useMergedRefs((_props_input = props.input) === null || _props_input === void 0 ? void 0 : _props_input.ref, triggerRef),\n type: 'text',\n value: value !== null && value !== void 0 ? value : '',\n ...triggerNativeProps\n }\n });\n triggerSlot.onChange = mergeCallbacks(triggerSlot.onChange, onTriggerChange);\n triggerSlot.onBlur = mergeCallbacks(triggerSlot.onBlur, onTriggerBlur);\n triggerSlot.onKeyDown = mergeCallbacks(triggerSlot.onKeyDown, onTriggerKeyDown);\n // only resolve listbox slot if needed\n listboxSlot = open || hasFocus ? resolveShorthand(props.listbox, {\n required: true,\n defaultProps: {\n children: props.children,\n style: popupDimensions\n }\n }) : undefined;\n [triggerSlot, listboxSlot] = useComboboxPopup(props, triggerSlot, listboxSlot);\n [triggerSlot, listboxSlot] = useTriggerListboxSlots(props, baseState, ref, triggerSlot, listboxSlot);\n if (hideActiveDescendant) {\n triggerSlot['aria-activedescendant'] = undefined;\n }\n const state = {\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 === null || listboxSlot === void 0 ? void 0 : 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: /*#__PURE__*/React.createElement(ChevronDownIcon, null),\n role: 'button'\n }\n }),\n ...baseState\n };\n state.root.ref = useMergedRefs(state.root.ref, rootRef);\n /* handle open/close + focus change when clicking expandIcon */\n const {\n onMouseDown: onIconMouseDown,\n onClick: onIconClick\n } = state.expandIcon || {};\n const onExpandIconMouseDown = useEventCallback(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 const onExpandIconClick = useEventCallback(mergeCallbacks(onIconClick, event => {\n var _triggerRef_current;\n // open and set focus\n state.setOpen(event, !state.open);\n (_triggerRef_current = triggerRef.current) === null || _triggerRef_current === void 0 ? void 0 : _triggerRef_current.focus();\n // set focus visible=false, since this can only be done with the mouse/pointer\n setFocusVisible(false);\n }));\n if (state.expandIcon) {\n state.expandIcon.onMouseDown = onExpandIconMouseDown;\n state.expandIcon.onClick = onExpandIconClick;\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 var _state_expandIcon_id;\n const chevronId = (_state_expandIcon_id = state.expandIcon.id) !== null && _state_expandIcon_id !== void 0 ? _state_expandIcon_id : `${comboId}-chevron`;\n const chevronLabelledBy = `${chevronId} ${state.input['aria-labelledby']}`;\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 return state;\n};\n//# sourceMappingURL=useCombobox.js.map"],"names":["useCombobox_unstable","props","ref","_props_input","useFieldControlProps_unstable","supportsLabelFor","supportsRequired","supportsSize","baseState","useComboboxBaseState","editable","activeOption","clearSelection","getIndexOfId","getOptionsMatchingText","hasFocus","open","selectOption","selectedOptions","setActiveOption","setFocusVisible","setOpen","setValue","value","disabled","freeform","inlinePopup","multiselect","comboId","useId","primary","triggerNativeProps","root","rootNativeProps","getPartitionedNativeProps","primarySlotTagName","excludedPropNames","rootRef","React","useRef","triggerRef","hideActiveDescendant","setHideActiveDescendant","useState","popupDimensions","setPopupDimensions","useEffect","_rootRef_current","width","current","clientWidth","getOptionFromInput","inputValue","searchString","trim","toLowerCase","length","matcher","optionText","indexOf","matches","startIndex","id","nextMatch","find","option","_matches_","undefined","ev","onTriggerBlur","text","newState","onTriggerChange","target","matchingOption","onTriggerKeyDown","getDropdownActionFromKey","key","ArrowLeft","ArrowRight","triggerSlot","listboxSlot","resolveShorthand","input","required","defaultProps","useMergedRefs","type","onChange","mergeCallbacks","onBlur","onKeyDown","listbox","children","style","useComboboxPopup","useTriggerListboxSlots","state","components","expandIcon","Listbox","createElement","ChevronDownIcon","role","onMouseDown","onIconMouseDown","onClick","onIconClick","onExpandIconMouseDown","useEventCallback","ignoreNextBlur","onExpandIconClick","event","_triggerRef_current","focus","hasExpandLabel","defaultOpenString","_state_expandIcon_id","chevronId","chevronLabelledBy"],"mappings":";;;;+BAmBaA;;aAAAA;;;6DAnBU;4BACuB;8BACR;4BACgB;gCAC8D;oCAC3E;sCACJ;kCACJ;wCACM;yBACf;AAUjB,MAAMA,uBAAuB,CAACC,OAAOC,MAAQ;IAClD,IAAIC;IACJ,+CAA+C;IAC/CF,QAAQG,IAAAA,yCAA6B,EAACH,OAAO;QAC3CI,kBAAkB,IAAI;QACtBC,kBAAkB,IAAI;QACtBC,cAAc,IAAI;IACpB;IACA,MAAMC,YAAYC,IAAAA,0CAAoB,EAAC;QACrC,GAAGR,KAAK;QACRS,UAAU,IAAI;IAChB;IACA,MAAM,EACJC,aAAY,EACZC,eAAc,EACdC,aAAY,EACZC,uBAAsB,EACtBC,SAAQ,EACRC,KAAI,EACJC,aAAY,EACZC,gBAAe,EACfC,gBAAe,EACfC,gBAAe,EACfC,QAAO,EACPC,SAAQ,EACRC,MAAK,EACN,GAAGf;IACJ,MAAM,EACJgB,SAAQ,EACRC,SAAQ,EACRC,YAAW,EACXC,YAAW,EACZ,GAAG1B;IACJ,MAAM2B,UAAUC,IAAAA,qBAAK,EAAC;IACtB,MAAM,EACJC,SAASC,mBAAkB,EAC3BC,MAAMC,gBAAe,EACtB,GAAGC,IAAAA,yCAAyB,EAAC;QAC5BjC;QACAkC,oBAAoB;QACpBC,mBAAmB;YAAC;YAAY;SAAO;IACzC;IACA,MAAMC,UAAUC,OAAMC,MAAM,CAAC,IAAI;IACjC,MA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AO;gBACLgG,MAAME,UAAU,CAAC,aAAa,GAAGiB;YACnC,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAOnB;AACT,GACA,uCAAuC"}
@@ -8,6 +8,7 @@ Object.defineProperty(exports, "useDropdown_unstable", {
8
8
  });
9
9
  const _interopRequireWildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default;
10
10
  const _react = /*#__PURE__*/ _interopRequireWildcard(require("react"));
11
+ const _reactField = require("@fluentui/react-field");
11
12
  const _reactIcons = require("@fluentui/react-icons");
12
13
  const _reactUtilities = require("@fluentui/react-utilities");
13
14
  const _dropdownKeyActions = require("../../utils/dropdownKeyActions");
@@ -16,6 +17,11 @@ const _useComboboxPopup = require("../../utils/useComboboxPopup");
16
17
  const _useTriggerListboxSlots = require("../../utils/useTriggerListboxSlots");
17
18
  const _listbox = require("../Listbox/Listbox");
18
19
  const useDropdown_unstable = (props, ref)=>{
20
+ // Merge props from surrounding <Field>, if any
21
+ props = (0, _reactField.useFieldControlProps_unstable)(props, {
22
+ supportsLabelFor: true,
23
+ supportsSize: true
24
+ });
19
25
  const baseState = (0, _useComboboxBaseState.useComboboxBaseState)(props);
20
26
  const { activeOption , getIndexOfId , getOptionsMatchingText , open , setActiveOption , setFocusVisible , setOpen } = baseState;
21
27
  const { primary: triggerNativeProps , root: rootNativeProps } = (0, _reactUtilities.getPartitionedNativeProps)({
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../lib/components/Dropdown/useDropdown.js"],"sourcesContent":["import * as React from 'react';\nimport { ChevronDownRegular as ChevronDownIcon } from '@fluentui/react-icons';\nimport { getPartitionedNativeProps, mergeCallbacks, resolveShorthand, useTimeout } 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 { useMergedRefs } from '@fluentui/react-utilities';\n/**\n * Create the state required to render Dropdown.\n *\n * The returned state can be modified with hooks such as useDropdownStyles_unstable,\n * before being passed to renderDropdown_unstable.\n *\n * @param props - props from this instance of Dropdown\n * @param ref - reference to root HTMLElement of Dropdown\n */\nexport const useDropdown_unstable = (props, ref) => {\n const baseState = useComboboxBaseState(props);\n const {\n activeOption,\n getIndexOfId,\n getOptionsMatchingText,\n open,\n setActiveOption,\n setFocusVisible,\n setOpen\n } = baseState;\n const {\n primary: triggerNativeProps,\n root: rootNativeProps\n } = getPartitionedNativeProps({\n props,\n primarySlotTagName: 'button',\n excludedPropNames: ['children']\n });\n // set listbox popup width based off the root/trigger width\n const rootRef = React.useRef(null);\n const [popupWidth, setPopupWidth] = React.useState();\n React.useEffect(() => {\n var _rootRef_current;\n const width = open ? `${(_rootRef_current = rootRef.current) === null || _rootRef_current === void 0 ? void 0 : _rootRef_current.clientWidth}px` : undefined;\n setPopupWidth(width);\n }, [open]);\n // jump to matching option based on typing\n const searchString = React.useRef('');\n const [setKeyTimeout, clearKeyTimeout] = useTimeout();\n const getNextMatchingOption = () => {\n // first check for matches for the full searchString\n let matcher = optionText => optionText.toLowerCase().indexOf(searchString.current) === 0;\n let matches = getOptionsMatchingText(matcher);\n let startIndex = activeOption ? getIndexOfId(activeOption.id) : 0;\n // if the dropdown is already open and the searchstring is a single character,\n // then look after the current activeOption for letters\n // this is so slowly typing the same letter will cycle through matches\n if (open && searchString.current.length === 1) {\n startIndex++;\n }\n // if there are no direct matches, check if the search is all the same letter, e.g. \"aaa\"\n if (!matches.length) {\n const letters = searchString.current.split('');\n const allSameLetter = letters.length && letters.every(letter => letter === letters[0]);\n // if the search is all the same letter, cycle through options starting with that letter\n if (allSameLetter) {\n startIndex++;\n matcher = optionText => optionText.toLowerCase().indexOf(letters[0]) === 0;\n matches = getOptionsMatchingText(matcher);\n }\n }\n // if there is an active option and multiple matches,\n // return first matching option after the current active option, looping back to the top\n if (matches.length > 1 && activeOption) {\n const nextMatch = matches.find(option => getIndexOfId(option.id) >= startIndex);\n return nextMatch !== null && nextMatch !== void 0 ? nextMatch : matches[0];\n }\n var _matches_;\n return (_matches_ = matches[0]) !== null && _matches_ !== void 0 ? _matches_ : undefined;\n };\n const onTriggerKeyDown = ev => {\n // clear timeout, if it exists\n clearKeyTimeout();\n // if the key was a char key, update search string\n if (getDropdownActionFromKey(ev) === 'Type') {\n // update search string\n searchString.current += ev.key.toLowerCase();\n setKeyTimeout(() => {\n searchString.current = '';\n }, 500);\n // update state\n !open && setOpen(ev, true);\n const nextOption = getNextMatchingOption();\n setActiveOption(nextOption);\n setFocusVisible(true);\n }\n };\n // resolve button and listbox slot props\n let triggerSlot;\n let listboxSlot;\n triggerSlot = resolveShorthand(props.button, {\n required: true,\n defaultProps: {\n type: 'button',\n children: baseState.value || props.placeholder,\n ...triggerNativeProps\n }\n });\n triggerSlot.onKeyDown = mergeCallbacks(onTriggerKeyDown, triggerSlot.onKeyDown);\n listboxSlot = baseState.open || baseState.hasFocus ? resolveShorthand(props.listbox, {\n required: true,\n defaultProps: {\n children: props.children,\n style: {\n width: popupWidth\n }\n }\n }) : undefined;\n [triggerSlot, listboxSlot] = useComboboxPopup(props, triggerSlot, listboxSlot);\n [triggerSlot, listboxSlot] = useTriggerListboxSlots(props, baseState, ref, triggerSlot, listboxSlot);\n const state = {\n components: {\n root: 'div',\n button: 'button',\n expandIcon: 'span',\n listbox: Listbox\n },\n root: resolveShorthand(props.root, {\n required: true,\n defaultProps: {\n 'aria-owns': !props.inlinePopup ? listboxSlot === null || listboxSlot === void 0 ? void 0 : listboxSlot.id : undefined,\n children: props.children,\n ...rootNativeProps\n }\n }),\n button: triggerSlot,\n listbox: listboxSlot,\n expandIcon: resolveShorthand(props.expandIcon, {\n required: true,\n defaultProps: {\n children: /*#__PURE__*/React.createElement(ChevronDownIcon, null)\n }\n }),\n placeholderVisible: !baseState.value && !!props.placeholder,\n ...baseState\n };\n state.root.ref = useMergedRefs(state.root.ref, rootRef);\n return state;\n};\n//# sourceMappingURL=useDropdown.js.map"],"names":["useDropdown_unstable","props","ref","baseState","useComboboxBaseState","activeOption","getIndexOfId","getOptionsMatchingText","open","setActiveOption","setFocusVisible","setOpen","primary","triggerNativeProps","root","rootNativeProps","getPartitionedNativeProps","primarySlotTagName","excludedPropNames","rootRef","React","useRef","popupWidth","setPopupWidth","useState","useEffect","_rootRef_current","width","current","clientWidth","undefined","searchString","setKeyTimeout","clearKeyTimeout","useTimeout","getNextMatchingOption","matcher","optionText","toLowerCase","indexOf","matches","startIndex","id","length","letters","split","allSameLetter","every","letter","nextMatch","find","option","_matches_","onTriggerKeyDown","ev","getDropdownActionFromKey","key","nextOption","triggerSlot","listboxSlot","resolveShorthand","button","required","defaultProps","type","children","value","placeholder","onKeyDown","mergeCallbacks","hasFocus","listbox","style","useComboboxPopup","useTriggerListboxSlots","state","components","expandIcon","Listbox","inlinePopup","createElement","ChevronDownIcon","placeholderVisible","useMergedRefs"],"mappings":";;;;+BAkBaA;;aAAAA;;;6DAlBU;4BAC+B;gCACkC;oCAC/C;sCACJ;kCACJ;wCACM;yBACf;AAWjB,MAAMA,uBAAuB,CAACC,OAAOC,MAAQ;IAClD,MAAMC,YAAYC,IAAAA,0CAAoB,EAACH;IACvC,MAAM,EACJI,aAAY,EACZC,aAAY,EACZC,uBAAsB,EACtBC,KAAI,EACJC,gBAAe,EACfC,gBAAe,EACfC,QAAO,EACR,GAAGR;IACJ,MAAM,EACJS,SAASC,mBAAkB,EAC3BC,MAAMC,gBAAe,EACtB,GAAGC,IAAAA,yCAAyB,EAAC;QAC5Bf;QACAgB,oBAAoB;QACpBC,mBAAmB;YAAC;SAAW;IACjC;IACA,2DAA2D;IAC3D,MAAMC,UAAUC,OAAMC,MAAM,CAAC,IAAI;IACjC,MAAM,CAACC,YAAYC,cAAc,GAAGH,OAAMI,QAAQ;IAClDJ,OAAMK,SAAS,CAAC,IAAM;QACpB,IAAIC;QACJ,MAAMC,Q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AsB,EAACzE,OAAOE,WAAWD,KAAKwD,aAAaC;IACxF,MAAMgB,QAAQ;QACZC,YAAY;YACV9D,MAAM;YACN+C,QAAQ;YACRgB,YAAY;YACZN,SAASO,gBAAO;QAClB;QACAhE,MAAM8C,IAAAA,gCAAgB,EAAC3D,MAAMa,IAAI,EAAE;YACjCgD,UAAU,IAAI;YACdC,cAAc;gBACZ,aAAa,CAAC9D,MAAM8E,WAAW,GAAGpB,gBAAgB,IAAI,IAAIA,gBAAgB,KAAK,IAAI,KAAK,IAAIA,YAAYjB,EAAE,GAAGZ,SAAS;gBACtHmC,UAAUhE,MAAMgE,QAAQ;gBACxB,GAAGlD,eAAe;YACpB;QACF;QACA8C,QAAQH;QACRa,SAASZ;QACTkB,YAAYjB,IAAAA,gCAAgB,EAAC3D,MAAM4E,UAAU,EAAE;YAC7Cf,UAAU,IAAI;YACdC,cAAc;gBACZE,UAAU,WAAW,GAAE7C,OAAM4D,aAAa,CAACC,8BAAe,EAAE,IAAI;YAClE;QACF;QACAC,oBAAoB,CAAC/E,UAAU+D,KAAK,IAAI,CAAC,CAACjE,MAAMkE,WAAW;QAC3D,GAAGhE,SAAS;IACd;IACAwE,MAAM7D,IAAI,CAACZ,GAAG,GAAGiF,IAAAA,6BAAa,EAACR,MAAM7D,IAAI,CAACZ,GAAG,EAAEiB;IAC/C,OAAOwD;AACT,GACA,uCAAuC"}
1
+ {"version":3,"sources":["../../../lib/components/Dropdown/useDropdown.js"],"sourcesContent":["import * as React from 'react';\nimport { useFieldControlProps_unstable } from '@fluentui/react-field';\nimport { ChevronDownRegular as ChevronDownIcon } from '@fluentui/react-icons';\nimport { getPartitionedNativeProps, mergeCallbacks, resolveShorthand, useTimeout } 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 { useMergedRefs } from '@fluentui/react-utilities';\n/**\n * Create the state required to render Dropdown.\n *\n * The returned state can be modified with hooks such as useDropdownStyles_unstable,\n * before being passed to renderDropdown_unstable.\n *\n * @param props - props from this instance of Dropdown\n * @param ref - reference to root HTMLElement of Dropdown\n */\nexport const useDropdown_unstable = (props, ref) => {\n // Merge props from surrounding <Field>, if any\n props = useFieldControlProps_unstable(props, {\n supportsLabelFor: true,\n supportsSize: true\n });\n const baseState = useComboboxBaseState(props);\n const {\n activeOption,\n getIndexOfId,\n getOptionsMatchingText,\n open,\n setActiveOption,\n setFocusVisible,\n setOpen\n } = baseState;\n const {\n primary: triggerNativeProps,\n root: rootNativeProps\n } = getPartitionedNativeProps({\n props,\n primarySlotTagName: 'button',\n excludedPropNames: ['children']\n });\n // set listbox popup width based off the root/trigger width\n const rootRef = React.useRef(null);\n const [popupWidth, setPopupWidth] = React.useState();\n React.useEffect(() => {\n var _rootRef_current;\n const width = open ? `${(_rootRef_current = rootRef.current) === null || _rootRef_current === void 0 ? void 0 : _rootRef_current.clientWidth}px` : undefined;\n setPopupWidth(width);\n }, [open]);\n // jump to matching option based on typing\n const searchString = React.useRef('');\n const [setKeyTimeout, clearKeyTimeout] = useTimeout();\n const getNextMatchingOption = () => {\n // first check for matches for the full searchString\n let matcher = optionText => optionText.toLowerCase().indexOf(searchString.current) === 0;\n let matches = getOptionsMatchingText(matcher);\n let startIndex = activeOption ? getIndexOfId(activeOption.id) : 0;\n // if the dropdown is already open and the searchstring is a single character,\n // then look after the current activeOption for letters\n // this is so slowly typing the same letter will cycle through matches\n if (open && searchString.current.length === 1) {\n startIndex++;\n }\n // if there are no direct matches, check if the search is all the same letter, e.g. \"aaa\"\n if (!matches.length) {\n const letters = searchString.current.split('');\n const allSameLetter = letters.length && letters.every(letter => letter === letters[0]);\n // if the search is all the same letter, cycle through options starting with that letter\n if (allSameLetter) {\n startIndex++;\n matcher = optionText => optionText.toLowerCase().indexOf(letters[0]) === 0;\n matches = getOptionsMatchingText(matcher);\n }\n }\n // if there is an active option and multiple matches,\n // return first matching option after the current active option, looping back to the top\n if (matches.length > 1 && activeOption) {\n const nextMatch = matches.find(option => getIndexOfId(option.id) >= startIndex);\n return nextMatch !== null && nextMatch !== void 0 ? nextMatch : matches[0];\n }\n var _matches_;\n return (_matches_ = matches[0]) !== null && _matches_ !== void 0 ? _matches_ : undefined;\n };\n const onTriggerKeyDown = ev => {\n // clear timeout, if it exists\n clearKeyTimeout();\n // if the key was a char key, update search string\n if (getDropdownActionFromKey(ev) === 'Type') {\n // update search string\n searchString.current += ev.key.toLowerCase();\n setKeyTimeout(() => {\n searchString.current = '';\n }, 500);\n // update state\n !open && setOpen(ev, true);\n const nextOption = getNextMatchingOption();\n setActiveOption(nextOption);\n setFocusVisible(true);\n }\n };\n // resolve button and listbox slot props\n let triggerSlot;\n let listboxSlot;\n triggerSlot = resolveShorthand(props.button, {\n required: true,\n defaultProps: {\n type: 'button',\n children: baseState.value || props.placeholder,\n ...triggerNativeProps\n }\n });\n triggerSlot.onKeyDown = mergeCallbacks(onTriggerKeyDown, triggerSlot.onKeyDown);\n listboxSlot = baseState.open || baseState.hasFocus ? resolveShorthand(props.listbox, {\n required: true,\n defaultProps: {\n children: props.children,\n style: {\n width: popupWidth\n }\n }\n }) : undefined;\n [triggerSlot, listboxSlot] = useComboboxPopup(props, triggerSlot, listboxSlot);\n [triggerSlot, listboxSlot] = useTriggerListboxSlots(props, baseState, ref, triggerSlot, listboxSlot);\n const state = {\n components: {\n root: 'div',\n button: 'button',\n expandIcon: 'span',\n listbox: Listbox\n },\n root: resolveShorthand(props.root, {\n required: true,\n defaultProps: {\n 'aria-owns': !props.inlinePopup ? listboxSlot === null || listboxSlot === void 0 ? void 0 : listboxSlot.id : undefined,\n children: props.children,\n ...rootNativeProps\n }\n }),\n button: triggerSlot,\n listbox: listboxSlot,\n expandIcon: resolveShorthand(props.expandIcon, {\n required: true,\n defaultProps: {\n children: /*#__PURE__*/React.createElement(ChevronDownIcon, null)\n }\n }),\n placeholderVisible: !baseState.value && !!props.placeholder,\n ...baseState\n };\n state.root.ref = useMergedRefs(state.root.ref, rootRef);\n return state;\n};\n//# sourceMappingURL=useDropdown.js.map"],"names":["useDropdown_unstable","props","ref","useFieldControlProps_unstable","supportsLabelFor","supportsSize","baseState","useComboboxBaseState","activeOption","getIndexOfId","getOptionsMatchingText","open","setActiveOption","setFocusVisible","setOpen","primary","triggerNativeProps","root","rootNativeProps","getPartitionedNativeProps","primarySlotTagName","excludedPropNames","rootRef","React","useRef","popupWidth","setPopupWidth","useState","useEffect","_rootRef_current","width","current","clientWidth","undefined","searchString","setKeyTimeout","clearKeyTimeout","useTimeout","getNextMatchingOption","matcher","optionText","toLowerCase","indexOf","matches","startIndex","id","length","letters","split","allSameLetter","every","letter","nextMatch","find","option","_matches_","onTriggerKeyDown","ev","getDropdownActionFromKey","key","nextOption","triggerSlot","listboxSlot","resolveShorthand","button","required","defaultProps","type","children","value","placeholder","onKeyDown","mergeCallbacks","hasFocus","listbox","style","useComboboxPopup","useTriggerListboxSlots","state","components","expandIcon","Listbox","inlinePopup","createElement","ChevronDownIcon","placeholderVisible","useMergedRefs"],"mappings":";;;;+BAmBaA;;aAAAA;;;6DAnBU;4BACuB;4BACQ;gCACkC;oCAC/C;sCACJ;kCACJ;wCACM;yBACf;AAWjB,MAAMA,uBAAuB,CAACC,OAAOC,MAAQ;IAClD,+CAA+C;IAC/CD,QAAQE,IAAAA,yCAA6B,EAACF,OAAO;QAC3CG,kBAAkB,IAAI;QACtBC,cAAc,IAAI;IACpB;IACA,MAAMC,YAAYC,IAAAA,0CAAoB,EAACN;IACvC,MAAM,EACJO,aAAY,EACZC,aAAY,EACZC,uBAAsB,EACtBC,KAAI,EACJC,gBAAe,EACfC,gBAAe,EACfC,QAAO,EACR,GAAGR;IACJ,MAAM,EACJS,SAASC,mBAAkB,EAC3BC,MAAMC,gBAAe,EACtB,GAAGC,IAAAA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E,OAAO,EAAE;QACnFT,UAAU,IAAI;QACdC,cAAc;YACZE,UAAUnE,MAAMmE,QAAQ;YACxBO,OAAO;gBACL7C,OAAOL;YACT;QACF;IACF,KAAKQ,SAAS;IACd,CAAC4B,aAAaC,YAAY,GAAGc,IAAAA,kCAAgB,EAAC3E,OAAO4D,aAAaC;IAClE,CAACD,aAAaC,YAAY,GAAGe,IAAAA,8CAAsB,EAAC5E,OAAOK,WAAWJ,KAAK2D,aAAaC;IACxF,MAAMgB,QAAQ;QACZC,YAAY;YACV9D,MAAM;YACN+C,QAAQ;YACRgB,YAAY;YACZN,SAASO,gBAAO;QAClB;QACAhE,MAAM8C,IAAAA,gCAAgB,EAAC9D,MAAMgB,IAAI,EAAE;YACjCgD,UAAU,IAAI;YACdC,cAAc;gBACZ,aAAa,CAACjE,MAAMiF,WAAW,GAAGpB,gBAAgB,IAAI,IAAIA,gBAAgB,KAAK,IAAI,KAAK,IAAIA,YAAYjB,EAAE,GAAGZ,SAAS;gBACtHmC,UAAUnE,MAAMmE,QAAQ;gBACxB,GAAGlD,eAAe;YACpB;QACF;QACA8C,QAAQH;QACRa,SAASZ;QACTkB,YAAYjB,IAAAA,gCAAgB,EAAC9D,MAAM+E,UAAU,EAAE;YAC7Cf,UAAU,IAAI;YACdC,cAAc;gBACZE,UAAU,WAAW,GAAE7C,OAAM4D,aAAa,CAACC,8BAAe,EAAE,IAAI;YAClE;QACF;QACAC,oBAAoB,CAAC/E,UAAU+D,KAAK,IAAI,CAAC,CAACpE,MAAMqE,WAAW;QAC3D,GAAGhE,SAAS;IACd;IACAwE,MAAM7D,IAAI,CAACf,GAAG,GAAGoF,IAAAA,6BAAa,EAACR,MAAM7D,IAAI,CAACf,GAAG,EAAEoB;IAC/C,OAAOwD;AACT,GACA,uCAAuC"}
@@ -11,7 +11,7 @@ const _react = /*#__PURE__*/ _interopRequireWildcard(require("react"));
11
11
  const _reactUtilities = require("@fluentui/react-utilities");
12
12
  const renderOption_unstable = (state)=>{
13
13
  const { slots , slotProps } = (0, _reactUtilities.getSlots)(state);
14
- return /*#__PURE__*/ _react.createElement(slots.root, slotProps.root, /*#__PURE__*/ _react.createElement(slots.checkIcon, slotProps.checkIcon), slotProps.root.children);
14
+ return /*#__PURE__*/ _react.createElement(slots.root, slotProps.root, slots.checkIcon && /*#__PURE__*/ _react.createElement(slots.checkIcon, slotProps.checkIcon), slotProps.root.children);
15
15
  }; //# sourceMappingURL=renderOption.js.map
16
16
 
17
17
  //# sourceMappingURL=renderOption.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../lib/components/Option/renderOption.js"],"sourcesContent":["import * as React from 'react';\nimport { getSlots } from '@fluentui/react-utilities';\n/**\n * Render the final JSX of Option\n */\nexport const renderOption_unstable = state => {\n const {\n slots,\n slotProps\n } = getSlots(state);\n return /*#__PURE__*/React.createElement(slots.root, slotProps.root, /*#__PURE__*/React.createElement(slots.checkIcon, slotProps.checkIcon), slotProps.root.children);\n};\n//# sourceMappingURL=renderOption.js.map"],"names":["renderOption_unstable","state","slots","slotProps","getSlots","React","createElement","root","checkIcon","children"],"mappings":";;;;+BAKaA;;aAAAA;;;6DALU;gCACE;AAIlB,MAAMA,wBAAwBC,CAAAA,QAAS;IAC5C,MAAM,EACJC,MAAK,EACLC,UAAS,EACV,GAAGC,IAAAA,wBAAQ,EAACH;IACb,OAAO,WAAW,GAAEI,OAAMC,aAAa,CAACJ,MAAMK,IAAI,EAAEJ,UAAUI,IAAI,EAAE,WAAW,GAAEF,OAAMC,aAAa,CAACJ,MAAMM,SAAS,EAAEL,UAAUK,SAAS,GAAGL,UAAUI,IAAI,CAACE,QAAQ;AACrK,GACA,wCAAwC"}
1
+ {"version":3,"sources":["../../../lib/components/Option/renderOption.js"],"sourcesContent":["import * as React from 'react';\nimport { getSlots } from '@fluentui/react-utilities';\n/**\n * Render the final JSX of Option\n */\nexport const renderOption_unstable = state => {\n const {\n slots,\n slotProps\n } = getSlots(state);\n return /*#__PURE__*/React.createElement(slots.root, slotProps.root, slots.checkIcon && /*#__PURE__*/React.createElement(slots.checkIcon, slotProps.checkIcon), slotProps.root.children);\n};\n//# sourceMappingURL=renderOption.js.map"],"names":["renderOption_unstable","state","slots","slotProps","getSlots","React","createElement","root","checkIcon","children"],"mappings":";;;;+BAKaA;;aAAAA;;;6DALU;gCACE;AAIlB,MAAMA,wBAAwBC,CAAAA,QAAS;IAC5C,MAAM,EACJC,MAAK,EACLC,UAAS,EACV,GAAGC,IAAAA,wBAAQ,EAACH;IACb,OAAO,WAAW,GAAEI,OAAMC,aAAa,CAACJ,MAAMK,IAAI,EAAEJ,UAAUI,IAAI,EAAEL,MAAMM,SAAS,IAAI,WAAW,GAAEH,OAAMC,aAAa,CAACJ,MAAMM,SAAS,EAAEL,UAAUK,SAAS,GAAGL,UAAUI,IAAI,CAACE,QAAQ;AACxL,GACA,wCAAwC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluentui/react-combobox",
3
- "version": "9.2.6",
3
+ "version": "9.2.8",
4
4
  "description": "Fluent UI React Combobox component",
5
5
  "main": "lib-commonjs/index.js",
6
6
  "module": "lib/index.js",
@@ -33,14 +33,14 @@
33
33
  },
34
34
  "dependencies": {
35
35
  "@fluentui/keyboard-keys": "^9.0.2",
36
- "@fluentui/react-context-selector": "^9.1.15",
37
- "@fluentui/react-field": "9.0.0-alpha.28",
36
+ "@fluentui/react-context-selector": "^9.1.16",
37
+ "@fluentui/react-field": "9.0.0-beta.1",
38
38
  "@fluentui/react-icons": "^2.0.196",
39
- "@fluentui/react-portal": "^9.2.3",
40
- "@fluentui/react-positioning": "^9.5.7",
39
+ "@fluentui/react-portal": "^9.2.4",
40
+ "@fluentui/react-positioning": "^9.5.8",
41
41
  "@fluentui/react-shared-contexts": "^9.3.3",
42
42
  "@fluentui/react-theme": "^9.1.7",
43
- "@fluentui/react-utilities": "^9.7.2",
43
+ "@fluentui/react-utilities": "^9.7.3",
44
44
  "@griffel/react": "^1.5.2",
45
45
  "@swc/helpers": "^0.4.14"
46
46
  },
@@ -52,7 +52,6 @@
52
52
  "scheduler": "^0.19.0 || ^0.20.0"
53
53
  },
54
54
  "beachball": {
55
- "tag": "beta",
56
55
  "disallowedChangeTypes": [
57
56
  "major",
58
57
  "prerelease"