@fluentui/react-combobox 9.7.5 → 9.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/CHANGELOG.md +26 -5
  2. package/dist/index.d.ts +54 -11
  3. package/lib/components/Combobox/Combobox.types.js.map +1 -1
  4. package/lib/components/Combobox/renderCombobox.js +15 -11
  5. package/lib/components/Combobox/renderCombobox.js.map +1 -1
  6. package/lib/components/Combobox/useCombobox.js +12 -4
  7. package/lib/components/Combobox/useCombobox.js.map +1 -1
  8. package/lib/components/Combobox/useInputTriggerSlot.js +14 -12
  9. package/lib/components/Combobox/useInputTriggerSlot.js.map +1 -1
  10. package/lib/components/Dropdown/Dropdown.types.js.map +1 -1
  11. package/lib/components/Dropdown/renderDropdown.js +19 -15
  12. package/lib/components/Dropdown/renderDropdown.js.map +1 -1
  13. package/lib/components/Dropdown/useButtonTriggerSlot.js +51 -31
  14. package/lib/components/Dropdown/useButtonTriggerSlot.js.map +1 -1
  15. package/lib/components/Dropdown/useDropdown.js +14 -4
  16. package/lib/components/Dropdown/useDropdown.js.map +1 -1
  17. package/lib/components/Listbox/Listbox.types.js.map +1 -1
  18. package/lib/components/Listbox/renderListbox.js +7 -3
  19. package/lib/components/Listbox/renderListbox.js.map +1 -1
  20. package/lib/components/Listbox/useListbox.js +43 -35
  21. package/lib/components/Listbox/useListbox.js.map +1 -1
  22. package/lib/components/Option/Option.types.js.map +1 -1
  23. package/lib/components/Option/useOption.js +7 -11
  24. package/lib/components/Option/useOption.js.map +1 -1
  25. package/lib/components/Option/useOptionStyles.styles.js +27 -28
  26. package/lib/components/Option/useOptionStyles.styles.js.map +1 -1
  27. package/lib/contexts/useComboboxContextValues.js +14 -5
  28. package/lib/contexts/useComboboxContextValues.js.map +1 -1
  29. package/lib/contexts/useListboxContextValues.js +12 -5
  30. package/lib/contexts/useListboxContextValues.js.map +1 -1
  31. package/lib/utils/ComboboxBase.types.js.map +1 -1
  32. package/lib/utils/OptionCollection.types.js.map +1 -1
  33. package/lib/utils/Selection.types.js.map +1 -1
  34. package/lib/utils/dropdownKeyActions.js +0 -21
  35. package/lib/utils/dropdownKeyActions.js.map +1 -1
  36. package/lib/utils/useComboboxBaseState.js +52 -14
  37. package/lib/utils/useComboboxBaseState.js.map +1 -1
  38. package/lib/utils/useOptionCollection.js +18 -45
  39. package/lib/utils/useOptionCollection.js.map +1 -1
  40. package/lib/utils/useTriggerSlot.js +86 -33
  41. package/lib/utils/useTriggerSlot.js.map +1 -1
  42. package/lib-commonjs/components/Combobox/renderCombobox.js +15 -11
  43. package/lib-commonjs/components/Combobox/renderCombobox.js.map +1 -1
  44. package/lib-commonjs/components/Combobox/useCombobox.js +12 -4
  45. package/lib-commonjs/components/Combobox/useCombobox.js.map +1 -1
  46. package/lib-commonjs/components/Combobox/useInputTriggerSlot.js +14 -12
  47. package/lib-commonjs/components/Combobox/useInputTriggerSlot.js.map +1 -1
  48. package/lib-commonjs/components/Dropdown/renderDropdown.js +19 -15
  49. package/lib-commonjs/components/Dropdown/renderDropdown.js.map +1 -1
  50. package/lib-commonjs/components/Dropdown/useButtonTriggerSlot.js +51 -31
  51. package/lib-commonjs/components/Dropdown/useButtonTriggerSlot.js.map +1 -1
  52. package/lib-commonjs/components/Dropdown/useDropdown.js +14 -4
  53. package/lib-commonjs/components/Dropdown/useDropdown.js.map +1 -1
  54. package/lib-commonjs/components/Listbox/renderListbox.js +7 -3
  55. package/lib-commonjs/components/Listbox/renderListbox.js.map +1 -1
  56. package/lib-commonjs/components/Listbox/useListbox.js +42 -34
  57. package/lib-commonjs/components/Listbox/useListbox.js.map +1 -1
  58. package/lib-commonjs/components/Option/useOption.js +7 -11
  59. package/lib-commonjs/components/Option/useOption.js.map +1 -1
  60. package/lib-commonjs/components/Option/useOptionStyles.styles.js +85 -85
  61. package/lib-commonjs/components/Option/useOptionStyles.styles.js.map +1 -1
  62. package/lib-commonjs/contexts/useComboboxContextValues.js +13 -5
  63. package/lib-commonjs/contexts/useComboboxContextValues.js.map +1 -1
  64. package/lib-commonjs/contexts/useListboxContextValues.js +13 -5
  65. package/lib-commonjs/contexts/useListboxContextValues.js.map +1 -1
  66. package/lib-commonjs/utils/dropdownKeyActions.js +3 -30
  67. package/lib-commonjs/utils/dropdownKeyActions.js.map +1 -1
  68. package/lib-commonjs/utils/useComboboxBaseState.js +52 -14
  69. package/lib-commonjs/utils/useComboboxBaseState.js.map +1 -1
  70. package/lib-commonjs/utils/useOptionCollection.js +18 -45
  71. package/lib-commonjs/utils/useOptionCollection.js.map +1 -1
  72. package/lib-commonjs/utils/useTriggerSlot.js +84 -31
  73. package/lib-commonjs/utils/useTriggerSlot.js.map +1 -1
  74. package/package.json +9 -8
  75. package/lib/utils/useScrollOptionsIntoView.js +0 -29
  76. package/lib/utils/useScrollOptionsIntoView.js.map +0 -1
  77. package/lib-commonjs/utils/useScrollOptionsIntoView.js +0 -40
  78. package/lib-commonjs/utils/useScrollOptionsIntoView.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,19 +1,40 @@
1
1
  # Change Log - @fluentui/react-combobox
2
2
 
3
- This log was last generated on Tue, 06 Feb 2024 17:52:10 GMT and should not be manually modified.
3
+ This log was last generated on Tue, 20 Feb 2024 14:15:21 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
+ ## [9.8.0](https://github.com/microsoft/fluentui/tree/@fluentui/react-combobox_v9.8.0)
8
+
9
+ Tue, 20 Feb 2024 14:15:21 GMT
10
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-combobox_v9.7.5..@fluentui/react-combobox_v9.8.0)
11
+
12
+ ### Minor changes
13
+
14
+ - feat: Decouple activedescendant handling from react state ([PR #30539](https://github.com/microsoft/fluentui/pull/30539) by lingfan.gao@microsoft.com)
15
+ - Bump @fluentui/react-aria to v9.9.0 ([PR #30543](https://github.com/microsoft/fluentui/pull/30543) by beachball)
16
+ - Bump @fluentui/react-context-selector to v9.1.52 ([PR #30543](https://github.com/microsoft/fluentui/pull/30543) by beachball)
17
+ - Bump @fluentui/react-field to v9.1.54 ([PR #30543](https://github.com/microsoft/fluentui/pull/30543) by beachball)
18
+ - Bump @fluentui/react-jsx-runtime to v9.0.30 ([PR #30543](https://github.com/microsoft/fluentui/pull/30543) by beachball)
19
+ - Bump @fluentui/react-portal to v9.4.14 ([PR #30543](https://github.com/microsoft/fluentui/pull/30543) by beachball)
20
+ - Bump @fluentui/react-positioning to v9.13.4 ([PR #30543](https://github.com/microsoft/fluentui/pull/30543) by beachball)
21
+ - Bump @fluentui/react-tabster to v9.19.1 ([PR #30543](https://github.com/microsoft/fluentui/pull/30543) by beachball)
22
+ - Bump @fluentui/react-utilities to v9.18.1 ([PR #30543](https://github.com/microsoft/fluentui/pull/30543) by beachball)
23
+
24
+ ### Patches
25
+
26
+ - chore: disable consistent-callback-type lint rule for existing callbacks ([PR #30293](https://github.com/microsoft/fluentui/pull/30293) by yuanboxue@microsoft.com)
27
+
7
28
  ## [9.7.5](https://github.com/microsoft/fluentui/tree/@fluentui/react-combobox_v9.7.5)
8
29
 
9
- Tue, 06 Feb 2024 17:52:10 GMT
30
+ Tue, 06 Feb 2024 17:55:21 GMT
10
31
  [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-combobox_v9.7.4..@fluentui/react-combobox_v9.7.5)
11
32
 
12
33
  ### Patches
13
34
 
14
- - Bump @fluentui/react-portal to v9.4.13 ([PR #26681](https://github.com/microsoft/fluentui/pull/26681) by beachball)
15
- - Bump @fluentui/react-positioning to v9.13.3 ([PR #26681](https://github.com/microsoft/fluentui/pull/26681) by beachball)
16
- - Bump @fluentui/react-tabster to v9.19.0 ([PR #26681](https://github.com/microsoft/fluentui/pull/26681) by beachball)
35
+ - Bump @fluentui/react-portal to v9.4.13 ([PR #30392](https://github.com/microsoft/fluentui/pull/30392) by beachball)
36
+ - Bump @fluentui/react-positioning to v9.13.3 ([PR #30392](https://github.com/microsoft/fluentui/pull/30392) by beachball)
37
+ - Bump @fluentui/react-tabster to v9.19.0 ([PR #30392](https://github.com/microsoft/fluentui/pull/30392) by beachball)
17
38
 
18
39
  ## [9.7.4](https://github.com/microsoft/fluentui/tree/@fluentui/react-combobox_v9.7.4)
19
40
 
package/dist/index.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  /// <reference types="react" />
2
2
 
3
+ import type { ActiveDescendantContextValue } from '@fluentui/react-aria';
4
+ import type { ActiveDescendantImperativeRef } from '@fluentui/react-aria';
3
5
  import type { ComponentProps } from '@fluentui/react-utilities';
4
6
  import type { ComponentState } from '@fluentui/react-utilities';
5
7
  import { FC } from 'react';
@@ -19,6 +21,7 @@ export declare const Combobox: ForwardRefComponent<ComboboxProps>;
19
21
 
20
22
  declare type ComboboxBaseContextValues = {
21
23
  combobox: ComboboxContextValue;
24
+ activeDescendant: ActiveDescendantContextValue;
22
25
  };
23
26
 
24
27
  /**
@@ -92,18 +95,29 @@ declare type ComboboxBaseProps = SelectionProps & Pick<PortalProps, 'mountNode'>
92
95
  * State used in rendering Combobox
93
96
  */
94
97
  declare type ComboboxBaseState = Required<Pick<ComboboxBaseProps, 'appearance' | 'open' | 'clearable' | 'inlinePopup' | 'size'>> & Pick<ComboboxBaseProps, 'mountNode' | 'placeholder' | 'value' | 'multiselect'> & OptionCollectionState & SelectionState & {
98
+ /**
99
+ * @deprecated - no longer used internally
100
+ * @see activeDescendantController.active() instead
101
+ */
95
102
  activeOption?: OptionValue;
96
- focusVisible: boolean;
97
103
  /**
98
- * whether the combobox/dropdown currently has focus
104
+ * @deprecated - no longer used internally
99
105
  */
100
- hasFocus: boolean;
106
+ focusVisible: boolean;
101
107
  /**
102
108
  * @deprecated - no longer used internally
103
109
  * Whether the next blur event should be ignored, and the combobox/dropdown will not close.
104
110
  */
105
111
  ignoreNextBlur: React_2.MutableRefObject<boolean>;
112
+ /**
113
+ * @deprecated - no longer used internally
114
+ * @see activeDescendantController.focus(id) instead
115
+ */
106
116
  setActiveOption: React_2.Dispatch<React_2.SetStateAction<OptionValue | undefined>>;
117
+ /**
118
+ * whether the combobox/dropdown currently has focus
119
+ */
120
+ hasFocus: boolean;
107
121
  setFocusVisible(focusVisible: boolean): void;
108
122
  setHasFocus(hasFocus: boolean): void;
109
123
  setOpen(event: ComboboxBaseOpenEvents, newState: boolean): void;
@@ -146,6 +160,7 @@ export declare type ComboboxSlots = {
146
160
  */
147
161
  export declare type ComboboxState = ComponentState<ComboboxSlots> & ComboboxBaseState & {
148
162
  showClearIcon?: boolean;
163
+ activeDescendantController: ActiveDescendantImperativeRef;
149
164
  };
150
165
 
151
166
  /**
@@ -180,6 +195,7 @@ export declare type DropdownSlots = {
180
195
  export declare type DropdownState = ComponentState<DropdownSlots> & ComboboxBaseState & {
181
196
  placeholderVisible: boolean;
182
197
  showClearButton?: boolean;
198
+ activeDescendantController: ActiveDescendantImperativeRef;
183
199
  };
184
200
 
185
201
  /**
@@ -196,6 +212,7 @@ export declare type ListboxContextValue = Pick<ListboxState, 'activeOption' | 'f
196
212
 
197
213
  export declare type ListboxContextValues = {
198
214
  listbox: ListboxContextValue;
215
+ activeDescendant: ActiveDescendantContextValue;
199
216
  };
200
217
 
201
218
  /**
@@ -213,10 +230,22 @@ export declare type ListboxSlots = {
213
230
  * State used in rendering Listbox
214
231
  */
215
232
  export declare type ListboxState = ComponentState<ListboxSlots> & OptionCollectionState & Pick<SelectionProps, 'multiselect'> & SelectionState & {
233
+ /**
234
+ * @deprecated - no longer used internally
235
+ * @see activeDescendantController.active()
236
+ */
216
237
  activeOption?: OptionValue;
238
+ /**
239
+ * @deprecated - no longer used internally
240
+ */
217
241
  focusVisible: boolean;
218
- selectOption(event: SelectionEvents, option: OptionValue): void;
242
+ /**
243
+ * @deprecated - no longer used internally
244
+ * @see activeDescendantController.focus(id)
245
+ */
219
246
  setActiveOption(option?: OptionValue): void;
247
+ selectOption(event: SelectionEvents, option: OptionValue): void;
248
+ activeDescendantController: ActiveDescendantImperativeRef;
220
249
  };
221
250
 
222
251
  /**
@@ -228,16 +257,22 @@ export { Option_2 as Option }
228
257
  export declare const optionClassNames: SlotClassNames<OptionSlots>;
229
258
 
230
259
  declare type OptionCollectionState = {
231
- /** The total number of options in the collection. */
232
- getCount: () => number;
233
- /** Returns the index of an option by key. */
260
+ /**
261
+ * @deprecated - no longer used internally
262
+ */
234
263
  getIndexOfId(id: string): number;
235
- /** Returns the option data for the nth option. */
264
+ /**
265
+ * @deprecated - no longer used internally
266
+ */
236
267
  getOptionAtIndex(index: number): OptionValue | undefined;
268
+ /**
269
+ * @deprecated - no longer used internally
270
+ */
271
+ getOptionsMatchingText(matcher: (text: string) => boolean): OptionValue[];
272
+ /** The total number of options in the collection. */
273
+ getCount: () => number;
237
274
  /** Returns the option data by key. */
238
275
  getOptionById(id: string): OptionValue | undefined;
239
- /** Returns an array of options filtered by a value matching function against the option's text string. */
240
- getOptionsMatchingText(matcher: (text: string) => boolean): OptionValue[];
241
276
  /** Returns an array of options filtered by a value matching function against the option's value string. */
242
277
  getOptionsMatchingValue(matcher: (value: string) => boolean): OptionValue[];
243
278
  /** The unordered option data. */
@@ -311,7 +346,13 @@ export declare type OptionSlots = {
311
346
  * State used in rendering Option
312
347
  */
313
348
  export declare type OptionState = ComponentState<OptionSlots> & Pick<OptionProps, 'disabled'> & {
349
+ /**
350
+ * @deprecated - no longer used internally
351
+ */
314
352
  active: boolean;
353
+ /**
354
+ * @deprecated - no longer used internally
355
+ */
315
356
  focusVisible: boolean;
316
357
  multiselect?: boolean;
317
358
  selected: boolean;
@@ -394,7 +435,9 @@ declare type SelectionState = {
394
435
  */
395
436
  export declare const useCombobox_unstable: (props: ComboboxProps, ref: React_2.Ref<HTMLInputElement>) => ComboboxState;
396
437
 
397
- export declare function useComboboxContextValues(state: ComboboxBaseState): ComboboxBaseContextValues;
438
+ export declare function useComboboxContextValues(state: ComboboxBaseState & {
439
+ activeDescendantController: ActiveDescendantImperativeRef;
440
+ }): ComboboxBaseContextValues;
398
441
 
399
442
  export declare function useComboboxFilter<T extends {
400
443
  children: React_2.ReactNode;
@@ -1 +1 @@
1
- {"version":3,"sources":["Combobox.types.ts"],"sourcesContent":["import * as React from 'react';\nimport type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';\nimport type {\n ComboboxBaseContextValues,\n ComboboxBaseOpenChangeData,\n ComboboxBaseOpenEvents,\n ComboboxBaseProps,\n ComboboxBaseState,\n} from '../../utils/ComboboxBase.types';\nimport { Listbox } from '../Listbox/Listbox';\n\nexport type ComboboxSlots = {\n /* The root combobox slot */\n root: NonNullable<Slot<'div'>>;\n\n /* The dropdown arrow icon */\n expandIcon: Slot<'span'>;\n\n /* The dropdown clear icon */\n clearIcon?: Slot<'span'>;\n\n /* The primary slot, an input with role=\"combobox\" */\n input: NonNullable<Slot<'input'>>;\n\n /* The dropdown listbox slot */\n listbox?: Slot<typeof Listbox>;\n};\n\n/**\n * Combobox Props\n */\nexport type ComboboxProps = Omit<ComponentProps<Partial<ComboboxSlots>, 'input'>, 'children' | 'size'> &\n ComboboxBaseProps & {\n /*\n * Whether the ComboBox allows freeform user input, rather than restricting to the provided options.\n */\n freeform?: boolean;\n\n /*\n * The primary slot, `<input>`, does not support children so we need to explicitly include it here.\n */\n children?: React.ReactNode;\n };\n\n/**\n * State used in rendering Combobox\n */\nexport type ComboboxState = ComponentState<ComboboxSlots> &\n ComboboxBaseState & {\n showClearIcon?: boolean;\n };\n\n/* Export types defined in ComboboxBase */\nexport type ComboboxContextValues = ComboboxBaseContextValues;\nexport type ComboboxOpenChangeData = ComboboxBaseOpenChangeData;\nexport type ComboboxOpenEvents = ComboboxBaseOpenEvents;\n"],"names":["React"],"mappings":"AAAA,YAAYA,WAAW,QAAQ"}
1
+ {"version":3,"sources":["Combobox.types.ts"],"sourcesContent":["import * as React from 'react';\nimport type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';\nimport type { ActiveDescendantImperativeRef } from '@fluentui/react-aria';\nimport type {\n ComboboxBaseContextValues,\n ComboboxBaseOpenChangeData,\n ComboboxBaseOpenEvents,\n ComboboxBaseProps,\n ComboboxBaseState,\n} from '../../utils/ComboboxBase.types';\nimport { Listbox } from '../Listbox/Listbox';\n\nexport type ComboboxSlots = {\n /* The root combobox slot */\n root: NonNullable<Slot<'div'>>;\n\n /* The dropdown arrow icon */\n expandIcon: Slot<'span'>;\n\n /* The dropdown clear icon */\n clearIcon?: Slot<'span'>;\n\n /* The primary slot, an input with role=\"combobox\" */\n input: NonNullable<Slot<'input'>>;\n\n /* The dropdown listbox slot */\n listbox?: Slot<typeof Listbox>;\n};\n\n/**\n * Combobox Props\n */\nexport type ComboboxProps = Omit<ComponentProps<Partial<ComboboxSlots>, 'input'>, 'children' | 'size'> &\n ComboboxBaseProps & {\n /*\n * Whether the ComboBox allows freeform user input, rather than restricting to the provided options.\n */\n freeform?: boolean;\n\n /*\n * The primary slot, `<input>`, does not support children so we need to explicitly include it here.\n */\n children?: React.ReactNode;\n };\n\n/**\n * State used in rendering Combobox\n */\nexport type ComboboxState = ComponentState<ComboboxSlots> &\n ComboboxBaseState & {\n showClearIcon?: boolean;\n activeDescendantController: ActiveDescendantImperativeRef;\n };\n\n/* Export types defined in ComboboxBase */\nexport type ComboboxContextValues = ComboboxBaseContextValues;\nexport type ComboboxOpenChangeData = ComboboxBaseOpenChangeData;\nexport type ComboboxOpenEvents = ComboboxBaseOpenEvents;\n"],"names":["React"],"mappings":"AAAA,YAAYA,WAAW,QAAQ"}
@@ -1,5 +1,6 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "@fluentui/react-jsx-runtime/jsx-runtime";
2
2
  import { Portal } from '@fluentui/react-portal';
3
+ import { ActiveDescendantContextProvider } from '@fluentui/react-aria';
3
4
  import { assertSlots } from '@fluentui/react-utilities';
4
5
  import { ComboboxContext } from '../../contexts/ComboboxContext';
5
6
  /**
@@ -7,17 +8,20 @@ import { ComboboxContext } from '../../contexts/ComboboxContext';
7
8
  */ export const renderCombobox_unstable = (state, contextValues)=>{
8
9
  assertSlots(state);
9
10
  return /*#__PURE__*/ _jsx(state.root, {
10
- children: /*#__PURE__*/ _jsxs(ComboboxContext.Provider, {
11
- value: contextValues.combobox,
12
- children: [
13
- /*#__PURE__*/ _jsx(state.input, {}),
14
- state.clearIcon && /*#__PURE__*/ _jsx(state.clearIcon, {}),
15
- /*#__PURE__*/ _jsx(state.expandIcon, {}),
16
- state.listbox && (state.inlinePopup ? /*#__PURE__*/ _jsx(state.listbox, {}) : /*#__PURE__*/ _jsx(Portal, {
17
- mountNode: state.mountNode,
18
- children: /*#__PURE__*/ _jsx(state.listbox, {})
19
- }))
20
- ]
11
+ children: /*#__PURE__*/ _jsx(ActiveDescendantContextProvider, {
12
+ value: contextValues.activeDescendant,
13
+ children: /*#__PURE__*/ _jsxs(ComboboxContext.Provider, {
14
+ value: contextValues.combobox,
15
+ children: [
16
+ /*#__PURE__*/ _jsx(state.input, {}),
17
+ state.clearIcon && /*#__PURE__*/ _jsx(state.clearIcon, {}),
18
+ /*#__PURE__*/ _jsx(state.expandIcon, {}),
19
+ state.listbox && (state.inlinePopup ? /*#__PURE__*/ _jsx(state.listbox, {}) : /*#__PURE__*/ _jsx(Portal, {
20
+ mountNode: state.mountNode,
21
+ children: /*#__PURE__*/ _jsx(state.listbox, {})
22
+ }))
23
+ ]
24
+ })
21
25
  })
22
26
  });
23
27
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["renderCombobox.tsx"],"sourcesContent":["/** @jsxRuntime automatic */\n/** @jsxImportSource @fluentui/react-jsx-runtime */\nimport { Portal } from '@fluentui/react-portal';\n\nimport { assertSlots } from '@fluentui/react-utilities';\nimport { ComboboxContext } from '../../contexts/ComboboxContext';\nimport type { ComboboxContextValues, ComboboxState, ComboboxSlots } from './Combobox.types';\n\n/**\n * Render the final JSX of Combobox\n */\nexport const renderCombobox_unstable = (state: ComboboxState, contextValues: ComboboxContextValues) => {\n assertSlots<ComboboxSlots>(state);\n\n return (\n <state.root>\n <ComboboxContext.Provider value={contextValues.combobox}>\n <state.input />\n {state.clearIcon && <state.clearIcon />}\n <state.expandIcon />\n {state.listbox &&\n (state.inlinePopup ? (\n <state.listbox />\n ) : (\n <Portal mountNode={state.mountNode}>\n <state.listbox />\n </Portal>\n ))}\n </ComboboxContext.Provider>\n </state.root>\n );\n};\n"],"names":["Portal","assertSlots","ComboboxContext","renderCombobox_unstable","state","contextValues","root","Provider","value","combobox","input","clearIcon","expandIcon","listbox","inlinePopup","mountNode"],"mappings":"AAAA,0BAA0B,GAC1B,iDAAiD;AACjD,SAASA,MAAM,QAAQ,yBAAyB;AAEhD,SAASC,WAAW,QAAQ,4BAA4B;AACxD,SAASC,eAAe,QAAQ,iCAAiC;AAGjE;;CAEC,GACD,OAAO,MAAMC,0BAA0B,CAACC,OAAsBC;IAC5DJ,YAA2BG;IAE3B,qBACE,KAACA,MAAME,IAAI;kBACT,cAAA,MAACJ,gBAAgBK,QAAQ;YAACC,OAAOH,cAAcI,QAAQ;;8BACrD,KAACL,MAAMM,KAAK;gBACXN,MAAMO,SAAS,kBAAI,KAACP,MAAMO,SAAS;8BACpC,KAACP,MAAMQ,UAAU;gBAChBR,MAAMS,OAAO,IACXT,CAAAA,MAAMU,WAAW,iBAChB,KAACV,MAAMS,OAAO,sBAEd,KAACb;oBAAOe,WAAWX,MAAMW,SAAS;8BAChC,cAAA,KAACX,MAAMS,OAAO;kBAElB;;;;AAIV,EAAE"}
1
+ {"version":3,"sources":["renderCombobox.tsx"],"sourcesContent":["/** @jsxRuntime automatic */\n/** @jsxImportSource @fluentui/react-jsx-runtime */\nimport { Portal } from '@fluentui/react-portal';\nimport { ActiveDescendantContextProvider } from '@fluentui/react-aria';\n\nimport { assertSlots } from '@fluentui/react-utilities';\nimport { ComboboxContext } from '../../contexts/ComboboxContext';\nimport type { ComboboxContextValues, ComboboxState, ComboboxSlots } from './Combobox.types';\n\n/**\n * Render the final JSX of Combobox\n */\nexport const renderCombobox_unstable = (state: ComboboxState, contextValues: ComboboxContextValues) => {\n assertSlots<ComboboxSlots>(state);\n\n return (\n <state.root>\n <ActiveDescendantContextProvider value={contextValues.activeDescendant}>\n <ComboboxContext.Provider value={contextValues.combobox}>\n <state.input />\n {state.clearIcon && <state.clearIcon />}\n <state.expandIcon />\n {state.listbox &&\n (state.inlinePopup ? (\n <state.listbox />\n ) : (\n <Portal mountNode={state.mountNode}>\n <state.listbox />\n </Portal>\n ))}\n </ComboboxContext.Provider>\n </ActiveDescendantContextProvider>\n </state.root>\n );\n};\n"],"names":["Portal","ActiveDescendantContextProvider","assertSlots","ComboboxContext","renderCombobox_unstable","state","contextValues","root","value","activeDescendant","Provider","combobox","input","clearIcon","expandIcon","listbox","inlinePopup","mountNode"],"mappings":"AAAA,0BAA0B,GAC1B,iDAAiD;AACjD,SAASA,MAAM,QAAQ,yBAAyB;AAChD,SAASC,+BAA+B,QAAQ,uBAAuB;AAEvE,SAASC,WAAW,QAAQ,4BAA4B;AACxD,SAASC,eAAe,QAAQ,iCAAiC;AAGjE;;CAEC,GACD,OAAO,MAAMC,0BAA0B,CAACC,OAAsBC;IAC5DJ,YAA2BG;IAE3B,qBACE,KAACA,MAAME,IAAI;kBACT,cAAA,KAACN;YAAgCO,OAAOF,cAAcG,gBAAgB;sBACpE,cAAA,MAACN,gBAAgBO,QAAQ;gBAACF,OAAOF,cAAcK,QAAQ;;kCACrD,KAACN,MAAMO,KAAK;oBACXP,MAAMQ,SAAS,kBAAI,KAACR,MAAMQ,SAAS;kCACpC,KAACR,MAAMS,UAAU;oBAChBT,MAAMU,OAAO,IACXV,CAAAA,MAAMW,WAAW,iBAChB,KAACX,MAAMU,OAAO,sBAEd,KAACf;wBAAOiB,WAAWZ,MAAMY,SAAS;kCAChC,cAAA,KAACZ,MAAMU,OAAO;sBAElB;;;;;AAKZ,EAAE"}
@@ -1,4 +1,5 @@
1
1
  import * as React from 'react';
2
+ import { useActiveDescendant } from '@fluentui/react-aria';
2
3
  import { useFieldControlProps_unstable } from '@fluentui/react-field';
3
4
  import { ChevronDownRegular as ChevronDownIcon, DismissRegular as DismissIcon } from '@fluentui/react-icons';
4
5
  import { getPartitionedNativeProps, mergeCallbacks, useEventCallback, useId, useMergedRefs, slot } from '@fluentui/react-utilities';
@@ -7,6 +8,7 @@ import { useComboboxPositioning } from '../../utils/useComboboxPositioning';
7
8
  import { Listbox } from '../Listbox/Listbox';
8
9
  import { useListboxSlot } from '../../utils/useListboxSlot';
9
10
  import { useInputTriggerSlot } from './useInputTriggerSlot';
11
+ import { optionClassNames } from '../Option/useOptionStyles.styles';
10
12
  /**
11
13
  * Create the state required to render Combobox.
12
14
  *
@@ -23,9 +25,13 @@ import { useInputTriggerSlot } from './useInputTriggerSlot';
23
25
  supportsRequired: true,
24
26
  supportsSize: true
25
27
  });
28
+ const { listboxRef: activeDescendantListboxRef, activeParentRef, controller: activeDescendantController } = useActiveDescendant({
29
+ matchOption: (el)=>el.classList.contains(optionClassNames.root)
30
+ });
26
31
  const baseState = useComboboxBaseState({
27
32
  ...props,
28
- editable: true
33
+ editable: true,
34
+ activeDescendantController
29
35
  });
30
36
  const { clearable, clearSelection, multiselect, open, selectedOptions, selectOption, setOpen, setValue, value, hasFocus } = baseState;
31
37
  const [comboboxPopupRef, comboboxTargetRef] = useComboboxPositioning(props);
@@ -54,7 +60,7 @@ import { useInputTriggerSlot } from './useInputTriggerSlot';
54
60
  setOpen(ev, newState);
55
61
  };
56
62
  const triggerRef = React.useRef(null);
57
- const listbox = useListboxSlot(props.listbox, comboboxPopupRef, {
63
+ const listbox = useListboxSlot(props.listbox, useMergedRefs(comboboxPopupRef, activeDescendantListboxRef), {
58
64
  state: baseState,
59
65
  triggerRef,
60
66
  defaultProps: {
@@ -62,7 +68,7 @@ import { useInputTriggerSlot } from './useInputTriggerSlot';
62
68
  }
63
69
  });
64
70
  var _props_input;
65
- const triggerSlot = useInputTriggerSlot((_props_input = props.input) !== null && _props_input !== void 0 ? _props_input : {}, useMergedRefs(triggerRef, ref), {
71
+ const triggerSlot = useInputTriggerSlot((_props_input = props.input) !== null && _props_input !== void 0 ? _props_input : {}, useMergedRefs(triggerRef, activeParentRef, ref), {
66
72
  state: baseState,
67
73
  freeform,
68
74
  defaultProps: {
@@ -70,7 +76,8 @@ import { useInputTriggerSlot } from './useInputTriggerSlot';
70
76
  value: value !== null && value !== void 0 ? value : '',
71
77
  'aria-controls': open ? listbox === null || listbox === void 0 ? void 0 : listbox.id : undefined,
72
78
  ...triggerNativeProps
73
- }
79
+ },
80
+ activeDescendantController
74
81
  });
75
82
  const rootSlot = slot.always(props.root, {
76
83
  defaultProps: {
@@ -110,6 +117,7 @@ import { useInputTriggerSlot } from './useInputTriggerSlot';
110
117
  elementType: 'span'
111
118
  }),
112
119
  showClearIcon,
120
+ activeDescendantController,
113
121
  ...baseState
114
122
  };
115
123
  /* handle open/close + focus change when clicking expandIcon */ const { onMouseDown: onIconMouseDown } = state.expandIcon || {};
@@ -1 +1 @@
1
- {"version":3,"sources":["useCombobox.tsx"],"sourcesContent":["import * as React from 'react';\nimport { useFieldControlProps_unstable } from '@fluentui/react-field';\nimport { ChevronDownRegular as ChevronDownIcon, DismissRegular as DismissIcon } from '@fluentui/react-icons';\nimport {\n getPartitionedNativeProps,\n mergeCallbacks,\n useEventCallback,\n useId,\n useMergedRefs,\n slot,\n} from '@fluentui/react-utilities';\nimport { useComboboxBaseState } from '../../utils/useComboboxBaseState';\nimport { useComboboxPositioning } from '../../utils/useComboboxPositioning';\nimport { Listbox } from '../Listbox/Listbox';\nimport type { SelectionEvents } from '../../utils/Selection.types';\nimport type { OptionValue } from '../../utils/OptionCollection.types';\nimport type { ComboboxProps, ComboboxState } from './Combobox.types';\nimport { useListboxSlot } from '../../utils/useListboxSlot';\nimport { useInputTriggerSlot } from './useInputTriggerSlot';\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 clearable,\n clearSelection,\n multiselect,\n open,\n selectedOptions,\n selectOption,\n setOpen,\n setValue,\n value,\n hasFocus,\n } = baseState;\n const [comboboxPopupRef, comboboxTargetRef] = useComboboxPositioning(props);\n const { disabled, freeform, inlinePopup } = 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 // 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 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 const triggerRef = React.useRef<HTMLInputElement>(null);\n\n const listbox = useListboxSlot(props.listbox, comboboxPopupRef, {\n state: baseState,\n triggerRef,\n defaultProps: {\n children: props.children,\n },\n });\n\n const triggerSlot = useInputTriggerSlot(props.input ?? {}, useMergedRefs(triggerRef, ref), {\n state: baseState,\n freeform,\n defaultProps: {\n type: 'text',\n value: value ?? '',\n 'aria-controls': open ? listbox?.id : undefined,\n ...triggerNativeProps,\n },\n });\n\n const rootSlot = slot.always(props.root, {\n defaultProps: {\n 'aria-owns': !inlinePopup && open ? listbox?.id : undefined,\n ...rootNativeProps,\n },\n elementType: 'div',\n });\n rootSlot.ref = useMergedRefs(rootSlot.ref, comboboxTargetRef);\n\n const showClearIcon = selectedOptions.length > 0 && clearable && !multiselect;\n const state: ComboboxState = {\n components: { root: 'div', input: 'input', expandIcon: 'span', listbox: Listbox, clearIcon: 'span' },\n root: rootSlot,\n input: triggerSlot,\n listbox: open || hasFocus ? listbox : undefined,\n clearIcon: slot.optional(props.clearIcon, {\n defaultProps: {\n 'aria-hidden': 'true',\n children: <DismissIcon />,\n },\n elementType: 'span',\n renderByDefault: true,\n }),\n expandIcon: slot.optional(props.expandIcon, {\n renderByDefault: true,\n defaultProps: {\n 'aria-expanded': open,\n children: <ChevronDownIcon />,\n role: 'button',\n },\n elementType: 'span',\n }),\n showClearIcon,\n ...baseState,\n };\n\n /* handle open/close + focus change when clicking expandIcon */\n const { onMouseDown: onIconMouseDown } = state.expandIcon || {};\n\n const onExpandIconMouseDown = useEventCallback(\n mergeCallbacks(onIconMouseDown, (event: React.MouseEvent<HTMLSpanElement>) => {\n event.preventDefault();\n state.setOpen(event, !state.open);\n triggerRef.current?.focus();\n }),\n );\n\n if (state.expandIcon) {\n state.expandIcon.onMouseDown = onExpandIconMouseDown;\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 const onClearIconMouseDown = useEventCallback(\n mergeCallbacks(state.clearIcon?.onMouseDown, (ev: React.MouseEvent<HTMLSpanElement>) => {\n ev.preventDefault();\n }),\n );\n const onClearIconClick = useEventCallback(\n mergeCallbacks(state.clearIcon?.onClick, (ev: React.MouseEvent<HTMLSpanElement>) => {\n clearSelection(ev);\n }),\n );\n\n if (state.clearIcon) {\n state.clearIcon.onMouseDown = onClearIconMouseDown;\n state.clearIcon.onClick = onClearIconClick;\n }\n\n // Heads up! We don't support \"clearable\" in multiselect mode, so we should never display a slot\n if (multiselect) {\n state.clearIcon = undefined;\n }\n\n if (process.env.NODE_ENV !== 'production') {\n // eslint-disable-next-line react-hooks/rules-of-hooks -- \"process.env\" does not change in runtime\n React.useEffect(() => {\n if (clearable && multiselect) {\n // eslint-disable-next-line no-console\n console.error(`[@fluentui/react-combobox] \"clearable\" prop is not supported in multiselect mode.`);\n }\n }, [clearable, multiselect]);\n }\n\n return state;\n};\n"],"names":["React","useFieldControlProps_unstable","ChevronDownRegular","ChevronDownIcon","DismissRegular","DismissIcon","getPartitionedNativeProps","mergeCallbacks","useEventCallback","useId","useMergedRefs","slot","useComboboxBaseState","useComboboxPositioning","Listbox","useListboxSlot","useInputTriggerSlot","useCombobox_unstable","props","ref","state","supportsLabelFor","supportsRequired","supportsSize","baseState","editable","clearable","clearSelection","multiselect","open","selectedOptions","selectOption","setOpen","setValue","value","hasFocus","comboboxPopupRef","comboboxTargetRef","disabled","freeform","inlinePopup","comboId","primary","triggerNativeProps","root","rootNativeProps","primarySlotTagName","excludedPropNames","ev","option","undefined","newState","triggerRef","useRef","listbox","defaultProps","children","triggerSlot","input","type","id","rootSlot","always","elementType","showClearIcon","length","components","expandIcon","clearIcon","optional","renderByDefault","role","onMouseDown","onIconMouseDown","onExpandIconMouseDown","event","preventDefault","current","focus","hasExpandLabel","defaultOpenString","chevronId","chevronLabelledBy","onClearIconMouseDown","onClearIconClick","onClick","process","env","NODE_ENV","useEffect","console","error"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,6BAA6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O,IAAIhE,KAAK,CAAC,aAAa,EAAE;gBAC9BE,MAAM+C,UAAU,CAAC,aAAa,GAAG,CAAC,EAAEa,kBAAkB,CAAC,EAAE9D,KAAK,CAAC,aAAa,CAAC,CAAC;YAChF,OAAO;gBACLE,MAAM+C,UAAU,CAAC,aAAa,GAAGa;YACnC;QACF;IACF;IAEA,MAAMG,uBAAuB3E,iBAC3BD,gBAAea,mBAAAA,MAAMgD,SAAS,cAAfhD,uCAAAA,iBAAiBoD,WAAW,EAAE,CAACxB;QAC5CA,GAAG4B,cAAc;IACnB;IAEF,MAAMQ,mBAAmB5E,iBACvBD,gBAAea,oBAAAA,MAAMgD,SAAS,cAAfhD,wCAAAA,kBAAiBiE,OAAO,EAAE,CAACrC;QACxCrB,eAAeqB;IACjB;IAGF,IAAI5B,MAAMgD,SAAS,EAAE;QACnBhD,MAAMgD,SAAS,CAACI,WAAW,GAAGW;QAC9B/D,MAAMgD,SAAS,CAACiB,OAAO,GAAGD;IAC5B;IAEA,gGAAgG;IAChG,IAAIxD,aAAa;QACfR,MAAMgD,SAAS,GAAGlB;IACpB;IAEA,IAAIoC,QAAQC,GAAG,CAACC,QAAQ,KAAK,cAAc;QACzC,kGAAkG;QAClGxF,MAAMyF,SAAS,CAAC;YACd,IAAI/D,aAAaE,aAAa;gBAC5B,sCAAsC;gBACtC8D,QAAQC,KAAK,CAAC,CAAC,iFAAiF,CAAC;YACnG;QACF,GAAG;YAACjE;YAAWE;SAAY;IAC7B;IAEA,OAAOR;AACT,EAAE"}
1
+ {"version":3,"sources":["useCombobox.tsx"],"sourcesContent":["import * as React from 'react';\nimport { useActiveDescendant } from '@fluentui/react-aria';\nimport { useFieldControlProps_unstable } from '@fluentui/react-field';\nimport { ChevronDownRegular as ChevronDownIcon, DismissRegular as DismissIcon } from '@fluentui/react-icons';\nimport {\n getPartitionedNativeProps,\n mergeCallbacks,\n useEventCallback,\n useId,\n useMergedRefs,\n slot,\n} from '@fluentui/react-utilities';\nimport { useComboboxBaseState } from '../../utils/useComboboxBaseState';\nimport { useComboboxPositioning } from '../../utils/useComboboxPositioning';\nimport { Listbox } from '../Listbox/Listbox';\nimport type { SelectionEvents } from '../../utils/Selection.types';\nimport type { OptionValue } from '../../utils/OptionCollection.types';\nimport type { ComboboxProps, ComboboxState } from './Combobox.types';\nimport { useListboxSlot } from '../../utils/useListboxSlot';\nimport { useInputTriggerSlot } from './useInputTriggerSlot';\nimport { optionClassNames } from '../Option/useOptionStyles.styles';\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 const {\n listboxRef: activeDescendantListboxRef,\n activeParentRef,\n controller: activeDescendantController,\n } = useActiveDescendant<HTMLInputElement, HTMLDivElement>({\n matchOption: el => el.classList.contains(optionClassNames.root),\n });\n const baseState = useComboboxBaseState({ ...props, editable: true, activeDescendantController });\n\n const {\n clearable,\n clearSelection,\n multiselect,\n open,\n selectedOptions,\n selectOption,\n setOpen,\n setValue,\n value,\n hasFocus,\n } = baseState;\n const [comboboxPopupRef, comboboxTargetRef] = useComboboxPositioning(props);\n const { disabled, freeform, inlinePopup } = 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 // 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 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 const triggerRef = React.useRef<HTMLInputElement>(null);\n\n const listbox = useListboxSlot(props.listbox, useMergedRefs(comboboxPopupRef, activeDescendantListboxRef), {\n state: baseState,\n triggerRef,\n defaultProps: {\n children: props.children,\n },\n });\n\n const triggerSlot = useInputTriggerSlot(props.input ?? {}, useMergedRefs(triggerRef, activeParentRef, ref), {\n state: baseState,\n freeform,\n defaultProps: {\n type: 'text',\n value: value ?? '',\n 'aria-controls': open ? listbox?.id : undefined,\n ...triggerNativeProps,\n },\n activeDescendantController,\n });\n\n const rootSlot = slot.always(props.root, {\n defaultProps: {\n 'aria-owns': !inlinePopup && open ? listbox?.id : undefined,\n ...rootNativeProps,\n },\n elementType: 'div',\n });\n rootSlot.ref = useMergedRefs(rootSlot.ref, comboboxTargetRef);\n\n const showClearIcon = selectedOptions.length > 0 && clearable && !multiselect;\n const state: ComboboxState = {\n components: { root: 'div', input: 'input', expandIcon: 'span', listbox: Listbox, clearIcon: 'span' },\n root: rootSlot,\n input: triggerSlot,\n listbox: open || hasFocus ? listbox : undefined,\n clearIcon: slot.optional(props.clearIcon, {\n defaultProps: {\n 'aria-hidden': 'true',\n children: <DismissIcon />,\n },\n elementType: 'span',\n renderByDefault: true,\n }),\n expandIcon: slot.optional(props.expandIcon, {\n renderByDefault: true,\n defaultProps: {\n 'aria-expanded': open,\n children: <ChevronDownIcon />,\n role: 'button',\n },\n elementType: 'span',\n }),\n showClearIcon,\n activeDescendantController,\n ...baseState,\n };\n\n /* handle open/close + focus change when clicking expandIcon */\n const { onMouseDown: onIconMouseDown } = state.expandIcon || {};\n\n const onExpandIconMouseDown = useEventCallback(\n mergeCallbacks(onIconMouseDown, (event: React.MouseEvent<HTMLSpanElement>) => {\n event.preventDefault();\n state.setOpen(event, !state.open);\n triggerRef.current?.focus();\n }),\n );\n\n if (state.expandIcon) {\n state.expandIcon.onMouseDown = onExpandIconMouseDown;\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 const onClearIconMouseDown = useEventCallback(\n mergeCallbacks(state.clearIcon?.onMouseDown, (ev: React.MouseEvent<HTMLSpanElement>) => {\n ev.preventDefault();\n }),\n );\n const onClearIconClick = useEventCallback(\n mergeCallbacks(state.clearIcon?.onClick, (ev: React.MouseEvent<HTMLSpanElement>) => {\n clearSelection(ev);\n }),\n );\n\n if (state.clearIcon) {\n state.clearIcon.onMouseDown = onClearIconMouseDown;\n state.clearIcon.onClick = onClearIconClick;\n }\n\n // Heads up! We don't support \"clearable\" in multiselect mode, so we should never display a slot\n if (multiselect) {\n state.clearIcon = undefined;\n }\n\n if (process.env.NODE_ENV !== 'production') {\n // eslint-disable-next-line react-hooks/rules-of-hooks -- \"process.env\" does not change in runtime\n React.useEffect(() => {\n if (clearable && multiselect) {\n // eslint-disable-next-line no-console\n console.error(`[@fluentui/react-combobox] \"clearable\" prop is not supported in multiselect mode.`);\n }\n }, [clearable, multiselect]);\n }\n\n return state;\n};\n"],"names":["React","useActiveDescendant","useFieldControlProps_unstable","ChevronDownRegular","ChevronDownIcon","DismissRegular","DismissIcon","getPartitionedNativeProps","mergeCallbacks","useEventCallback","useId","useMergedRefs","slot","useComboboxBaseState","useComboboxPositioning","Listbox","useListboxSlot","useInputTriggerSlot","optionClassNames","useCombobox_unstable","props","ref","state","supportsLabelFor","supportsRequired","supportsSize","listboxRef","activeDescendantListboxRef","activeParentRef","controller","activeDescendantController","matchOption","el","classList","contains","root","baseState","editable","clearable","clearSelection","multiselect","open","selectedOptions","selectOption","setOpen","setValue","value","hasFocus","comboboxPopupRef","comboboxTargetRef","disabled","freeform","inlinePopup","comboId","primary","triggerNativeProps","rootNativeProps","primarySlotTagName","excludedPropNames","ev","option","undefined","newState","triggerRef","useRef","listbox","defaultProps","children","triggerSlot","input","type","id","rootSlot","always","elementType","showClearIcon","length","components","expandIcon","clearIcon","optional","renderByDefault","role","onMouseDown","onIconMouseDown","onExpandIconMouseDown","event","preventDefault","current","focus","hasExpandLabel","defaultOpenString","chevronId","chevronLabelledBy","onClearIconMouseDown","onClearIconClick","onClick","process","env","NODE_ENV","useEffect","console","error"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,mBAAmB,QAAQ,uBAAuB;AAC3D,SAASC,6BAA6B,QAAQ,wBAAwB;AACtE,SAASC,sBAAsBC,eAAe,EAAEC,kBAAkBC,WAAW,QAAQ,wBAAwB;AAC7G,SACEC,yBAAyB,EACzBC,cAAc,EACdC,gBAAgB,EAChBC,KAAK,EACLC,aAAa,EACbC,IAAI,QACC,4BAA4B;AACnC,SAASC,oBAAoB,QAAQ,mCAAmC;AACxE,SAASC,sBAAsB,QAAQ,qCAAqC;AAC5E,SAASC,OAAO,QAAQ,qBAAqB;AAI7C,SAASC,cAAc,QAAQ,6BAA6B;AAC5D,SAASC,mBAAmB,QAAQ,wBAAwB;AAC5D,SAASC,gBAAgB,QAAQ,mCAAmC;AAEpE;;;;;;;;CAQC,GACD,OAAO,MAAMC,uBAAuB,CAACC,OAAsBC;QAsJxCC,kBAKAA;IA1Jj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EA,MAAMG,uBAAuBrF,iBAC3BD,gBAAec,mBAAAA,MAAMyD,SAAS,cAAfzD,uCAAAA,iBAAiB6D,WAAW,EAAE,CAACxB;QAC5CA,GAAG4B,cAAc;IACnB;IAEF,MAAMQ,mBAAmBtF,iBACvBD,gBAAec,oBAAAA,MAAMyD,SAAS,cAAfzD,wCAAAA,kBAAiB0E,OAAO,EAAE,CAACrC;QACxCpB,eAAeoB;IACjB;IAGF,IAAIrC,MAAMyD,SAAS,EAAE;QACnBzD,MAAMyD,SAAS,CAACI,WAAW,GAAGW;QAC9BxE,MAAMyD,SAAS,CAACiB,OAAO,GAAGD;IAC5B;IAEA,gGAAgG;IAChG,IAAIvD,aAAa;QACflB,MAAMyD,SAAS,GAAGlB;IACpB;IAEA,IAAIoC,QAAQC,GAAG,CAACC,QAAQ,KAAK,cAAc;QACzC,kGAAkG;QAClGnG,MAAMoG,SAAS,CAAC;YACd,IAAI9D,aAAaE,aAAa;gBAC5B,sCAAsC;gBACtC6D,QAAQC,KAAK,CAAC,CAAC,iFAAiF,CAAC;YACnG;QACF,GAAG;YAAChE;YAAWE;SAAY;IAC7B;IAEA,OAAOlB;AACT,EAAE"}
@@ -8,10 +8,12 @@ import { getDropdownActionFromKey } from '../../utils/dropdownKeyActions';
8
8
  * with the semantics and event handlers needed for the Combobox and Dropdown components.
9
9
  * The element type of the ref should always match the element type used in the trigger shorthand.
10
10
  */ export function useInputTriggerSlot(triggerFromProps, ref, options) {
11
- const { state: { open, value, activeOption, selectOption, setValue, setActiveOption, setFocusVisible, multiselect, selectedOptions, clearSelection, getOptionsMatchingText, getIndexOfId, setOpen }, freeform, defaultProps } = options;
11
+ const { state: { open, value, selectOption, setValue, multiselect, selectedOptions, clearSelection, getOptionById, setOpen }, freeform, defaultProps, activeDescendantController } = options;
12
12
  const onBlur = (ev)=>{
13
13
  // handle selection and updating value if freeform is false
14
14
  if (!open && !freeform) {
15
+ const activeOptionId = activeDescendantController.active();
16
+ const activeOption = activeOptionId ? getOptionById(activeOptionId) : null;
15
17
  // select matching option, if the value fully matches
16
18
  if (value && activeOption && value.trim().toLowerCase() === (activeOption === null || activeOption === void 0 ? void 0 : activeOption.text.toLowerCase())) {
17
19
  selectOption(ev, activeOption);
@@ -23,18 +25,19 @@ import { getDropdownActionFromKey } from '../../utils/dropdownKeyActions';
23
25
  const getOptionFromInput = (inputValue)=>{
24
26
  const searchString = inputValue === null || inputValue === void 0 ? void 0 : inputValue.trim().toLowerCase();
25
27
  if (!searchString || searchString.length === 0) {
28
+ activeDescendantController.blur();
26
29
  return;
27
30
  }
28
31
  const matcher = (optionText)=>optionText.toLowerCase().indexOf(searchString) === 0;
29
- const matches = getOptionsMatchingText(matcher);
30
- // return first matching option after the current active option, looping back to the top
31
- if (matches.length > 1 && activeOption) {
32
- const startIndex = getIndexOfId(activeOption.id);
33
- const nextMatch = matches.find((option)=>getIndexOfId(option.id) >= startIndex);
34
- return nextMatch !== null && nextMatch !== void 0 ? nextMatch : matches[0];
32
+ const match = activeDescendantController.find((id)=>{
33
+ const option = getOptionById(id);
34
+ return !!option && matcher(option.text);
35
+ });
36
+ if (!match) {
37
+ activeDescendantController.blur();
38
+ return undefined;
35
39
  }
36
- var _matches_;
37
- return (_matches_ = matches[0]) !== null && _matches_ !== void 0 ? _matches_ : undefined;
40
+ return getOptionById(match);
38
41
  };
39
42
  // update value and active option based on input
40
43
  const onChange = (ev)=>{
@@ -43,8 +46,6 @@ import { getDropdownActionFromKey } from '../../utils/dropdownKeyActions';
43
46
  setValue(inputValue);
44
47
  // handle updating active option based on input
45
48
  const matchingOption = getOptionFromInput(inputValue);
46
- setActiveOption(matchingOption);
47
- setFocusVisible(true);
48
49
  // clear selection for single-select if the input value no longer matches the selection
49
50
  if (!multiselect && selectedOptions.length === 1 && (inputValue.length < 1 || !matchingOption)) {
50
51
  clearSelection(ev);
@@ -53,7 +54,8 @@ import { getDropdownActionFromKey } from '../../utils/dropdownKeyActions';
53
54
  const trigger = useTriggerSlot(triggerFromProps, ref, {
54
55
  state: options.state,
55
56
  defaultProps,
56
- elementType: 'input'
57
+ elementType: 'input',
58
+ activeDescendantController
57
59
  });
58
60
  trigger.onChange = mergeCallbacks(trigger.onChange, onChange);
59
61
  trigger.onBlur = mergeCallbacks(trigger.onBlur, onBlur);
@@ -1 +1 @@
1
- {"version":3,"sources":["useInputTriggerSlot.ts"],"sourcesContent":["import * as React from 'react';\nimport { mergeCallbacks, useEventCallback } from '@fluentui/react-utilities';\nimport type { ExtractSlotProps, Slot, SlotComponentType } from '@fluentui/react-utilities';\nimport { ArrowLeft, ArrowRight } from '@fluentui/keyboard-keys';\nimport { useTriggerSlot, UseTriggerSlotState } from '../../utils/useTriggerSlot';\nimport { ComboboxProps, ComboboxState } from './Combobox.types';\nimport { OptionValue } from '../../utils/OptionCollection.types';\nimport { getDropdownActionFromKey } from '../../utils/dropdownKeyActions';\n\ntype UsedComboboxState = UseTriggerSlotState &\n Pick<ComboboxState, 'value' | 'setValue' | 'selectedOptions' | 'clearSelection' | 'getOptionsMatchingText'>;\n\ntype UseInputTriggerSlotOptions = {\n state: UsedComboboxState;\n freeform: boolean | undefined;\n defaultProps: Partial<ComboboxProps>;\n};\n\n/*\n * useInputTriggerSlot returns a tuple of trigger/listbox shorthand,\n * with the semantics and event handlers needed for the Combobox and Dropdown components.\n * The element type of the ref should always match the element type used in the trigger shorthand.\n */\nexport function useInputTriggerSlot(\n triggerFromProps: NonNullable<Slot<'input'>>,\n ref: React.Ref<HTMLInputElement>,\n options: UseInputTriggerSlotOptions,\n): SlotComponentType<ExtractSlotProps<Slot<'input'>>> {\n const {\n state: {\n open,\n value,\n activeOption,\n selectOption,\n setValue,\n setActiveOption,\n setFocusVisible,\n multiselect,\n selectedOptions,\n clearSelection,\n getOptionsMatchingText,\n getIndexOfId,\n setOpen,\n },\n freeform,\n defaultProps,\n } = options;\n\n const onBlur = (ev: React.FocusEvent<HTMLInputElement>) => {\n // handle selection and updating value if freeform is false\n if (!open && !freeform) {\n // select matching option, if the value fully matches\n if (value && activeOption && value.trim().toLowerCase() === activeOption?.text.toLowerCase()) {\n 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 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 // update value and active option based on input\n const onChange = (ev: React.ChangeEvent<HTMLInputElement>) => {\n const inputValue = ev.target.value;\n // update uncontrolled value\n 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 const trigger = useTriggerSlot(triggerFromProps, ref, {\n state: options.state,\n defaultProps,\n elementType: 'input',\n });\n\n trigger.onChange = mergeCallbacks(trigger.onChange, onChange);\n trigger.onBlur = mergeCallbacks(trigger.onBlur, onBlur);\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 // save the typing vs. navigating options state, as the space key should behave differently in each case\n // we do not want to update the combobox when this changes, just save the value between renders\n const isTyping = React.useRef(false);\n\n /**\n * Freeform combobox should not select\n */\n const defaultOnKeyDown = trigger.onKeyDown;\n const onKeyDown = useEventCallback((ev: React.KeyboardEvent<HTMLInputElement>) => {\n if (!open && getDropdownActionFromKey(ev) === 'Type') {\n 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 // update typing state to true if the user is typing\n const action = getDropdownActionFromKey(ev, { open, multiselect });\n if (action === 'Type') {\n isTyping.current = true;\n }\n // otherwise, update the typing state to false if opening or navigating dropdown options\n // other actions, like closing the dropdown, should not impact typing state.\n else if (\n (action === 'Open' && ev.key !== ' ') ||\n action === 'Next' ||\n action === 'Previous' ||\n action === 'First' ||\n action === 'Last' ||\n action === 'PageUp' ||\n action === 'PageDown'\n ) {\n isTyping.current = false;\n }\n\n // allow space to insert a character if freeform & the last action was typing, or if the popup is closed\n if ((isTyping.current || !open) && ev.key === ' ') {\n triggerFromProps?.onKeyDown?.(ev);\n return;\n }\n\n defaultOnKeyDown?.(ev);\n });\n\n trigger.onKeyDown = onKeyDown;\n\n if (hideActiveDescendant) {\n trigger['aria-activedescendant'] = undefined;\n }\n\n return trigger;\n}\n"],"names":["React","mergeCallbacks","useEventCallback","ArrowLeft","ArrowRight","useTriggerSlot","getDropdownActionFromKey","useInputTriggerSlot","triggerFromProps","ref","options","state","open","value","activeOption","selectOption","setValue","setActiveOption","setFocusVisible","multiselect","selectedOptions","clearSelection","getOptionsMatchingText","getIndexOfId","setOpen","freeform","defaultProps","onBlur","ev","trim","toLowerCase","text","undefined","getOptionFromInput","inputValue","searchString","length","matcher","optionText","indexOf","matches","startIndex","id","nextMatch","find","option","onChange","target","matchingOption","trigger","elementType","hideActiveDescendant","setHideActiveDescendant","useState","isTyping","useRef","defaultOnKeyDown","onKeyDown","key","action","current"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,cAAc,EAAEC,gBAAgB,QAAQ,4BAA4B;AAE7E,SAASC,SAAS,EAAEC,UAAU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G;QACrB,OAGK,IACH,AAACD,WAAW,UAAU/B,GAAG8B,GAAG,KAAK,OACjCC,WAAW,UACXA,WAAW,cACXA,WAAW,WACXA,WAAW,UACXA,WAAW,YACXA,WAAW,YACX;YACAL,SAASM,OAAO,GAAG;QACrB;QAEA,wGAAwG;QACxG,IAAI,AAACN,CAAAA,SAASM,OAAO,IAAI,CAAChD,IAAG,KAAMgB,GAAG8B,GAAG,KAAK,KAAK;gBACjDlD;YAAAA,6BAAAA,wCAAAA,8BAAAA,iBAAkBiD,SAAS,cAA3BjD,kDAAAA,iCAAAA,kBAA8BoB;YAC9B;QACF;QAEA4B,6BAAAA,uCAAAA,iBAAmB5B;IACrB;IAEAqB,QAAQQ,SAAS,GAAGA;IAEpB,IAAIN,sBAAsB;QACxBF,OAAO,CAAC,wBAAwB,GAAGjB;IACrC;IAEA,OAAOiB;AACT"}
1
+ {"version":3,"sources":["useInputTriggerSlot.ts"],"sourcesContent":["import * as React from 'react';\nimport type { ActiveDescendantImperativeRef } from '@fluentui/react-aria';\nimport { mergeCallbacks, useEventCallback } from '@fluentui/react-utilities';\nimport type { ExtractSlotProps, Slot, SlotComponentType } from '@fluentui/react-utilities';\nimport { ArrowLeft, ArrowRight } from '@fluentui/keyboard-keys';\nimport { useTriggerSlot, UseTriggerSlotState } from '../../utils/useTriggerSlot';\nimport { ComboboxProps, ComboboxState } from './Combobox.types';\nimport { OptionValue } from '../../utils/OptionCollection.types';\nimport { getDropdownActionFromKey } from '../../utils/dropdownKeyActions';\n\ntype UsedComboboxState = UseTriggerSlotState &\n Pick<ComboboxState, 'value' | 'setValue' | 'selectedOptions' | 'clearSelection' | 'getOptionById'>;\n\ntype UseInputTriggerSlotOptions = {\n state: UsedComboboxState;\n freeform: boolean | undefined;\n defaultProps: Partial<ComboboxProps>;\n activeDescendantController: ActiveDescendantImperativeRef;\n};\n\n/*\n * useInputTriggerSlot returns a tuple of trigger/listbox shorthand,\n * with the semantics and event handlers needed for the Combobox and Dropdown components.\n * The element type of the ref should always match the element type used in the trigger shorthand.\n */\nexport function useInputTriggerSlot(\n triggerFromProps: NonNullable<Slot<'input'>>,\n ref: React.Ref<HTMLInputElement>,\n options: UseInputTriggerSlotOptions,\n): SlotComponentType<ExtractSlotProps<Slot<'input'>>> {\n const {\n state: {\n open,\n value,\n selectOption,\n setValue,\n multiselect,\n selectedOptions,\n clearSelection,\n getOptionById,\n setOpen,\n },\n freeform,\n defaultProps,\n activeDescendantController,\n } = options;\n\n const onBlur = (ev: React.FocusEvent<HTMLInputElement>) => {\n // handle selection and updating value if freeform is false\n if (!open && !freeform) {\n const activeOptionId = activeDescendantController.active();\n const activeOption = activeOptionId ? getOptionById(activeOptionId) : null;\n // select matching option, if the value fully matches\n if (value && activeOption && value.trim().toLowerCase() === activeOption?.text.toLowerCase()) {\n 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 const getOptionFromInput = (inputValue: string): OptionValue | undefined => {\n const searchString = inputValue?.trim().toLowerCase();\n\n if (!searchString || searchString.length === 0) {\n activeDescendantController.blur();\n return;\n }\n\n const matcher = (optionText: string) => optionText.toLowerCase().indexOf(searchString) === 0;\n const match = activeDescendantController.find(id => {\n const option = getOptionById(id);\n return !!option && matcher(option.text);\n });\n\n if (!match) {\n activeDescendantController.blur();\n return undefined;\n }\n\n return getOptionById(match);\n };\n\n // update value and active option based on input\n const onChange = (ev: React.ChangeEvent<HTMLInputElement>) => {\n const inputValue = ev.target.value;\n // update uncontrolled value\n setValue(inputValue);\n\n // handle updating active option based on input\n const matchingOption = getOptionFromInput(inputValue);\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 const trigger = useTriggerSlot(triggerFromProps, ref, {\n state: options.state,\n defaultProps,\n elementType: 'input',\n activeDescendantController,\n });\n\n trigger.onChange = mergeCallbacks(trigger.onChange, onChange);\n trigger.onBlur = mergeCallbacks(trigger.onBlur, onBlur);\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 // save the typing vs. navigating options state, as the space key should behave differently in each case\n // we do not want to update the combobox when this changes, just save the value between renders\n const isTyping = React.useRef(false);\n\n /**\n * Freeform combobox should not select\n */\n const defaultOnKeyDown = trigger.onKeyDown;\n const onKeyDown = useEventCallback((ev: React.KeyboardEvent<HTMLInputElement>) => {\n if (!open && getDropdownActionFromKey(ev) === 'Type') {\n 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 // update typing state to true if the user is typing\n const action = getDropdownActionFromKey(ev, { open, multiselect });\n if (action === 'Type') {\n isTyping.current = true;\n }\n // otherwise, update the typing state to false if opening or navigating dropdown options\n // other actions, like closing the dropdown, should not impact typing state.\n else if (\n (action === 'Open' && ev.key !== ' ') ||\n action === 'Next' ||\n action === 'Previous' ||\n action === 'First' ||\n action === 'Last' ||\n action === 'PageUp' ||\n action === 'PageDown'\n ) {\n isTyping.current = false;\n }\n\n // allow space to insert a character if freeform & the last action was typing, or if the popup is closed\n if ((isTyping.current || !open) && ev.key === ' ') {\n triggerFromProps?.onKeyDown?.(ev);\n return;\n }\n\n defaultOnKeyDown?.(ev);\n });\n\n trigger.onKeyDown = onKeyDown;\n\n if (hideActiveDescendant) {\n trigger['aria-activedescendant'] = undefined;\n }\n\n return trigger;\n}\n"],"names":["React","mergeCallbacks","useEventCallback","ArrowLeft","ArrowRight","useTriggerSlot","getDropdownActionFromKey","useInputTriggerSlot","triggerFromProps","ref","options","state","open","value","selectOption","setValue","multiselect","selectedOptions","clearSelection","getOptionById","setOpen","freeform","defaultProps","activeDescendantController","onBlur","ev","activeOptionId","active","activeOption","trim","toLowerCase","text","undefined","getOptionFromInput","inputValue","searchString","length","blur","matcher","optionText","indexOf","match","find","id","option","onChange","target","matchingOption","trigger","elementType","hideActiveDescendant","setHideActiveDescendant","useState","isTyping","useRef","defaultOnKeyDown","onKeyDown","key","action","current"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAE/B,SAASC,cAAc,EAAEC,gBAAgB,QAAQ,4BAA4B;AAE7E,SAASC,SAAS,EAAEC,UAAU,QAAQ,0BAA0B;AAChE,SAASC,cAAc,QAA6B,6BAA6B;AAGjF,SAASC,wBAAwB,QAAQ,iCAAiC;AAY1E;;;;CAIC,GACD,OAAO,SAASC,oBACdC,gBAA4C,EAC5CC,GAAgC,EAChCC,OAAmC;IAEnC,MAAM,EACJC,OAAO,EACLC,IAAI,EACJC,KAAK,EACLC,YAAY,EACZC,QAAQ,EACRC,WAAW,EACXC,eAAe,EACfC,cAAc,EACdC,aAAa,EACbC,OAAO,EACR,EACDC,QAAQ,EACRC,YAAY,EACZC,0BAA0B,EAC3B,GAAGb;IAEJ,MAAMc,SAAS,CAACC;QACd,2DAA2D;QAC3D,IAAI,CAACb,QAAQ,CAACS,UAAU;YACtB,MAAMK,iBAAiBH,2BAA2BI,MAAM;YACxD,MAAMC,eAAeF,iBAAiBP,cAAcO,kBAAkB;YACtE,qDAAqD;YACrD,IAAIb,SAASe,gBAAgBf,MAAMgB,IAAI,GAAGC,WAAW,QAAOF,yBAAAA,mCAAAA,aAAcG,IAAI,CAACD,WAAW,KAAI;gBAC5FhB,aAAaW,IAAIG;YACnB;YAEA,wFAAwF;YACxFb,SAASiB;QACX;IACF;IAEA,MAAMC,qBAAqB,CAACC;QAC1B,MAAMC,eAAeD,uBAAAA,iCAAAA,WAAYL,IAAI,GAAGC,WAAW;QAEnD,IAAI,CAACK,gBAAgBA,aAAaC,MAAM,KAAK,GAAG;YAC9Cb,2BAA2Bc,IAAI;YAC/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/D,IAAIA,GAAGgC,GAAG,KAAKtD,aAAasB,GAAGgC,GAAG,KAAKrD,YAAY;YACjD+C,wBAAwB;QAC1B,OAAO;YACLA,wBAAwB;QAC1B;QAEA,oDAAoD;QACpD,MAAMO,SAASpD,yBAAyBmB,IAAI;YAAEb;YAAMI;QAAY;QAChE,IAAI0C,WAAW,QAAQ;YACrBL,SAASM,OAAO,GAAG;QACrB,OAGK,IACH,AAACD,WAAW,UAAUjC,GAAGgC,GAAG,KAAK,OACjCC,WAAW,UACXA,WAAW,cACXA,WAAW,WACXA,WAAW,UACXA,WAAW,YACXA,WAAW,YACX;YACAL,SAASM,OAAO,GAAG;QACrB;QAEA,wGAAwG;QACxG,IAAI,AAACN,CAAAA,SAASM,OAAO,IAAI,CAAC/C,IAAG,KAAMa,GAAGgC,GAAG,KAAK,KAAK;gBACjDjD;YAAAA,6BAAAA,wCAAAA,8BAAAA,iBAAkBgD,SAAS,cAA3BhD,kDAAAA,iCAAAA,kBAA8BiB;YAC9B;QACF;QAEA8B,6BAAAA,uCAAAA,iBAAmB9B;IACrB;IAEAuB,QAAQQ,SAAS,GAAGA;IAEpB,IAAIN,sBAAsB;QACxBF,OAAO,CAAC,wBAAwB,GAAGhB;IACrC;IAEA,OAAOgB;AACT"}
@@ -1 +1 @@
1
- {"version":3,"sources":["Dropdown.types.ts"],"sourcesContent":["import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';\nimport type {\n ComboboxBaseContextValues,\n ComboboxBaseOpenChangeData,\n ComboboxBaseOpenEvents,\n ComboboxBaseProps,\n ComboboxBaseState,\n} from '../../utils/ComboboxBase.types';\nimport { Listbox } from '../Listbox/Listbox';\n\nexport type DropdownSlots = {\n /* The root dropdown slot */\n root: NonNullable<Slot<'div'>>;\n\n /* The dropdown arrow icon */\n expandIcon?: Slot<'span'>;\n\n /* The dropdown clear icon */\n clearButton?: Slot<'button'>;\n\n /* The primary slot, the element with role=\"combobox\" */\n button: NonNullable<Slot<'button'>>;\n\n /* The dropdown listbox slot */\n listbox?: Slot<typeof Listbox>;\n};\n\n/**\n * Dropdown Props\n */\nexport type DropdownProps = ComponentProps<Partial<DropdownSlots>, 'button'> & ComboboxBaseProps;\n\n/**\n * State used in rendering Dropdown\n */\nexport type DropdownState = ComponentState<DropdownSlots> &\n ComboboxBaseState & {\n /* Whether the placeholder is currently displayed */\n placeholderVisible: boolean;\n\n showClearButton?: boolean;\n };\n\n/* Export types defined in ComboboxBase */\nexport type DropdownContextValues = ComboboxBaseContextValues;\nexport type DropdownOpenEvents = ComboboxBaseOpenEvents;\nexport type DropdownOpenChangeData = ComboboxBaseOpenChangeData;\n"],"names":[],"mappings":"AAAA,WA8CgE"}
1
+ {"version":3,"sources":["Dropdown.types.ts"],"sourcesContent":["import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';\nimport type { ActiveDescendantImperativeRef } from '@fluentui/react-aria';\nimport type {\n ComboboxBaseContextValues,\n ComboboxBaseOpenChangeData,\n ComboboxBaseOpenEvents,\n ComboboxBaseProps,\n ComboboxBaseState,\n} from '../../utils/ComboboxBase.types';\nimport { Listbox } from '../Listbox/Listbox';\n\nexport type DropdownSlots = {\n /* The root dropdown slot */\n root: NonNullable<Slot<'div'>>;\n\n /* The dropdown arrow icon */\n expandIcon?: Slot<'span'>;\n\n /* The dropdown clear icon */\n clearButton?: Slot<'button'>;\n\n /* The primary slot, the element with role=\"combobox\" */\n button: NonNullable<Slot<'button'>>;\n\n /* The dropdown listbox slot */\n listbox?: Slot<typeof Listbox>;\n};\n\n/**\n * Dropdown Props\n */\nexport type DropdownProps = ComponentProps<Partial<DropdownSlots>, 'button'> & ComboboxBaseProps;\n\n/**\n * State used in rendering Dropdown\n */\nexport type DropdownState = ComponentState<DropdownSlots> &\n ComboboxBaseState & {\n /* Whether the placeholder is currently displayed */\n placeholderVisible: boolean;\n\n showClearButton?: boolean;\n\n activeDescendantController: ActiveDescendantImperativeRef;\n };\n\n/* Export types defined in ComboboxBase */\nexport type DropdownContextValues = ComboboxBaseContextValues;\nexport type DropdownOpenEvents = ComboboxBaseOpenEvents;\nexport type DropdownOpenChangeData = ComboboxBaseOpenChangeData;\n"],"names":[],"mappings":"AAAA,WAiDgE"}
@@ -1,27 +1,31 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "@fluentui/react-jsx-runtime/jsx-runtime";
2
2
  import { Portal } from '@fluentui/react-portal';
3
3
  import { assertSlots } from '@fluentui/react-utilities';
4
+ import { ActiveDescendantContextProvider } from '@fluentui/react-aria';
4
5
  import { ComboboxContext } from '../../contexts/ComboboxContext';
5
6
  /**
6
7
  * Render the final JSX of Dropdown
7
8
  */ export const renderDropdown_unstable = (state, contextValues)=>{
8
9
  assertSlots(state);
9
10
  return /*#__PURE__*/ _jsx(state.root, {
10
- children: /*#__PURE__*/ _jsxs(ComboboxContext.Provider, {
11
- value: contextValues.combobox,
12
- children: [
13
- /*#__PURE__*/ _jsxs(state.button, {
14
- children: [
15
- state.button.children,
16
- state.expandIcon && /*#__PURE__*/ _jsx(state.expandIcon, {})
17
- ]
18
- }),
19
- state.clearButton && /*#__PURE__*/ _jsx(state.clearButton, {}),
20
- state.listbox && (state.inlinePopup ? /*#__PURE__*/ _jsx(state.listbox, {}) : /*#__PURE__*/ _jsx(Portal, {
21
- mountNode: state.mountNode,
22
- children: /*#__PURE__*/ _jsx(state.listbox, {})
23
- }))
24
- ]
11
+ children: /*#__PURE__*/ _jsx(ActiveDescendantContextProvider, {
12
+ value: contextValues.activeDescendant,
13
+ children: /*#__PURE__*/ _jsxs(ComboboxContext.Provider, {
14
+ value: contextValues.combobox,
15
+ children: [
16
+ /*#__PURE__*/ _jsxs(state.button, {
17
+ children: [
18
+ state.button.children,
19
+ state.expandIcon && /*#__PURE__*/ _jsx(state.expandIcon, {})
20
+ ]
21
+ }),
22
+ state.clearButton && /*#__PURE__*/ _jsx(state.clearButton, {}),
23
+ state.listbox && (state.inlinePopup ? /*#__PURE__*/ _jsx(state.listbox, {}) : /*#__PURE__*/ _jsx(Portal, {
24
+ mountNode: state.mountNode,
25
+ children: /*#__PURE__*/ _jsx(state.listbox, {})
26
+ }))
27
+ ]
28
+ })
25
29
  })
26
30
  });
27
31
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["renderDropdown.tsx"],"sourcesContent":["/** @jsxRuntime automatic */\n/** @jsxImportSource @fluentui/react-jsx-runtime */\n\nimport { Portal } from '@fluentui/react-portal';\n\nimport { assertSlots } from '@fluentui/react-utilities';\nimport { ComboboxContext } from '../../contexts/ComboboxContext';\nimport type { DropdownContextValues, DropdownState, DropdownSlots } from './Dropdown.types';\n\n/**\n * Render the final JSX of Dropdown\n */\nexport const renderDropdown_unstable = (state: DropdownState, contextValues: DropdownContextValues) => {\n assertSlots<DropdownSlots>(state);\n\n return (\n <state.root>\n <ComboboxContext.Provider value={contextValues.combobox}>\n <state.button>\n {state.button.children}\n {state.expandIcon && <state.expandIcon />}\n </state.button>\n {state.clearButton && <state.clearButton />}\n {state.listbox &&\n (state.inlinePopup ? (\n <state.listbox />\n ) : (\n <Portal mountNode={state.mountNode}>\n <state.listbox />\n </Portal>\n ))}\n </ComboboxContext.Provider>\n </state.root>\n );\n};\n"],"names":["Portal","assertSlots","ComboboxContext","renderDropdown_unstable","state","contextValues","root","Provider","value","combobox","button","children","expandIcon","clearButton","listbox","inlinePopup","mountNode"],"mappings":"AAAA,0BAA0B,GAC1B,iDAAiD;AAEjD,SAASA,MAAM,QAAQ,yBAAyB;AAEhD,SAASC,WAAW,QAAQ,4BAA4B;AACxD,SAASC,eAAe,QAAQ,iCAAiC;AAGjE;;CAEC,GACD,OAAO,MAAMC,0BAA0B,CAACC,OAAsBC;IAC5DJ,YAA2BG;IAE3B,qBACE,KAACA,MAAME,IAAI;kBACT,cAAA,MAACJ,gBAAgBK,QAAQ;YAACC,OAAOH,cAAcI,QAAQ;;8BACrD,MAACL,MAAMM,MAAM;;wBACVN,MAAMM,MAAM,CAACC,QAAQ;wBACrBP,MAAMQ,UAAU,kBAAI,KAACR,MAAMQ,UAAU;;;gBAEvCR,MAAMS,WAAW,kBAAI,KAACT,MAAMS,WAAW;gBACvCT,MAAMU,OAAO,IACXV,CAAAA,MAAMW,WAAW,iBAChB,KAACX,MAAMU,OAAO,sBAEd,KAACd;oBAAOgB,WAAWZ,MAAMY,SAAS;8BAChC,cAAA,KAACZ,MAAMU,OAAO;kBAElB;;;;AAIV,EAAE"}
1
+ {"version":3,"sources":["renderDropdown.tsx"],"sourcesContent":["/** @jsxRuntime automatic */\n/** @jsxImportSource @fluentui/react-jsx-runtime */\n\nimport { Portal } from '@fluentui/react-portal';\n\nimport { assertSlots } from '@fluentui/react-utilities';\nimport { ActiveDescendantContextProvider } from '@fluentui/react-aria';\nimport { ComboboxContext } from '../../contexts/ComboboxContext';\nimport type { DropdownContextValues, DropdownState, DropdownSlots } from './Dropdown.types';\n\n/**\n * Render the final JSX of Dropdown\n */\nexport const renderDropdown_unstable = (state: DropdownState, contextValues: DropdownContextValues) => {\n assertSlots<DropdownSlots>(state);\n\n return (\n <state.root>\n <ActiveDescendantContextProvider value={contextValues.activeDescendant}>\n <ComboboxContext.Provider value={contextValues.combobox}>\n <state.button>\n {state.button.children}\n {state.expandIcon && <state.expandIcon />}\n </state.button>\n {state.clearButton && <state.clearButton />}\n {state.listbox &&\n (state.inlinePopup ? (\n <state.listbox />\n ) : (\n <Portal mountNode={state.mountNode}>\n <state.listbox />\n </Portal>\n ))}\n </ComboboxContext.Provider>\n </ActiveDescendantContextProvider>\n </state.root>\n );\n};\n"],"names":["Portal","assertSlots","ActiveDescendantContextProvider","ComboboxContext","renderDropdown_unstable","state","contextValues","root","value","activeDescendant","Provider","combobox","button","children","expandIcon","clearButton","listbox","inlinePopup","mountNode"],"mappings":"AAAA,0BAA0B,GAC1B,iDAAiD;AAEjD,SAASA,MAAM,QAAQ,yBAAyB;AAEhD,SAASC,WAAW,QAAQ,4BAA4B;AACxD,SAASC,+BAA+B,QAAQ,uBAAuB;AACvE,SAASC,eAAe,QAAQ,iCAAiC;AAGjE;;CAEC,GACD,OAAO,MAAMC,0BAA0B,CAACC,OAAsBC;IAC5DL,YAA2BI;IAE3B,qBACE,KAACA,MAAME,IAAI;kBACT,cAAA,KAACL;YAAgCM,OAAOF,cAAcG,gBAAgB;sBACpE,cAAA,MAACN,gBAAgBO,QAAQ;gBAACF,OAAOF,cAAcK,QAAQ;;kCACrD,MAACN,MAAMO,MAAM;;4BACVP,MAAMO,MAAM,CAACC,QAAQ;4BACrBR,MAAMS,UAAU,kBAAI,KAACT,MAAMS,UAAU;;;oBAEvCT,MAAMU,WAAW,kBAAI,KAACV,MAAMU,WAAW;oBACvCV,MAAMW,OAAO,IACXX,CAAAA,MAAMY,WAAW,iBAChB,KAACZ,MAAMW,OAAO,sBAEd,KAAChB;wBAAOkB,WAAWb,MAAMa,SAAS;kCAChC,cAAA,KAACb,MAAMW,OAAO;sBAElB;;;;;AAKZ,EAAE"}