@fluentui/react-combobox 9.16.18 → 9.17.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 (58) hide show
  1. package/CHANGELOG.md +13 -3
  2. package/dist/index.d.ts +52 -4
  3. package/lib/Combobox.js +1 -1
  4. package/lib/Combobox.js.map +1 -1
  5. package/lib/Dropdown.js +1 -1
  6. package/lib/Dropdown.js.map +1 -1
  7. package/lib/Option.js +1 -1
  8. package/lib/Option.js.map +1 -1
  9. package/lib/components/Combobox/Combobox.types.js.map +1 -1
  10. package/lib/components/Combobox/index.js +1 -1
  11. package/lib/components/Combobox/index.js.map +1 -1
  12. package/lib/components/Combobox/renderCombobox.js.map +1 -1
  13. package/lib/components/Combobox/useCombobox.js +39 -17
  14. package/lib/components/Combobox/useCombobox.js.map +1 -1
  15. package/lib/components/Combobox/useInputTriggerSlot.js +2 -1
  16. package/lib/components/Combobox/useInputTriggerSlot.js.map +1 -1
  17. package/lib/components/Dropdown/Dropdown.types.js.map +1 -1
  18. package/lib/components/Dropdown/index.js +1 -1
  19. package/lib/components/Dropdown/index.js.map +1 -1
  20. package/lib/components/Dropdown/useButtonTriggerSlot.js +2 -1
  21. package/lib/components/Dropdown/useButtonTriggerSlot.js.map +1 -1
  22. package/lib/components/Dropdown/useDropdown.js +37 -16
  23. package/lib/components/Dropdown/useDropdown.js.map +1 -1
  24. package/lib/components/Option/index.js +1 -1
  25. package/lib/components/Option/index.js.map +1 -1
  26. package/lib/components/Option/useOption.js +21 -7
  27. package/lib/components/Option/useOption.js.map +1 -1
  28. package/lib/index.js +3 -3
  29. package/lib/index.js.map +1 -1
  30. package/lib/utils/useComboboxBaseState.js +2 -1
  31. package/lib/utils/useComboboxBaseState.js.map +1 -1
  32. package/lib-commonjs/Combobox.js +3 -0
  33. package/lib-commonjs/Combobox.js.map +1 -1
  34. package/lib-commonjs/Dropdown.js +3 -0
  35. package/lib-commonjs/Dropdown.js.map +1 -1
  36. package/lib-commonjs/Option.js +3 -0
  37. package/lib-commonjs/Option.js.map +1 -1
  38. package/lib-commonjs/components/Combobox/Combobox.types.js.map +1 -1
  39. package/lib-commonjs/components/Combobox/index.js +3 -0
  40. package/lib-commonjs/components/Combobox/index.js.map +1 -1
  41. package/lib-commonjs/components/Combobox/renderCombobox.js.map +1 -1
  42. package/lib-commonjs/components/Combobox/useCombobox.js +39 -14
  43. package/lib-commonjs/components/Combobox/useCombobox.js.map +1 -1
  44. package/lib-commonjs/components/Combobox/useInputTriggerSlot.js.map +1 -1
  45. package/lib-commonjs/components/Dropdown/Dropdown.types.js.map +1 -1
  46. package/lib-commonjs/components/Dropdown/index.js +3 -0
  47. package/lib-commonjs/components/Dropdown/index.js.map +1 -1
  48. package/lib-commonjs/components/Dropdown/useButtonTriggerSlot.js.map +1 -1
  49. package/lib-commonjs/components/Dropdown/useDropdown.js +37 -13
  50. package/lib-commonjs/components/Dropdown/useDropdown.js.map +1 -1
  51. package/lib-commonjs/components/Option/index.js +3 -0
  52. package/lib-commonjs/components/Option/index.js.map +1 -1
  53. package/lib-commonjs/components/Option/useOption.js +27 -10
  54. package/lib-commonjs/components/Option/useOption.js.map +1 -1
  55. package/lib-commonjs/index.js +9 -0
  56. package/lib-commonjs/index.js.map +1 -1
  57. package/lib-commonjs/utils/useComboboxBaseState.js.map +1 -1
  58. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -1,17 +1,27 @@
1
1
  # Change Log - @fluentui/react-combobox
2
2
 
3
- This log was last generated on Wed, 11 Mar 2026 09:20:38 GMT and should not be manually modified.
3
+ This log was last generated on Wed, 01 Apr 2026 15:50:20 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
+ ## [9.17.0](https://github.com/microsoft/fluentui/tree/@fluentui/react-combobox_v9.17.0)
8
+
9
+ Wed, 01 Apr 2026 15:50:20 GMT
10
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-combobox_v9.16.18..@fluentui/react-combobox_v9.17.0)
11
+
12
+ ### Minor changes
13
+
14
+ - feat: add useComboboxBase_unstable and useDropdownBase_unstable hooks ([PR #35915](https://github.com/microsoft/fluentui/pull/35915) by dmytrokirpa@microsoft.com)
15
+ - Bump @fluentui/react-field to v9.5.0 ([PR #35912](https://github.com/microsoft/fluentui/pull/35912) by beachball)
16
+
7
17
  ## [9.16.18](https://github.com/microsoft/fluentui/tree/@fluentui/react-combobox_v9.16.18)
8
18
 
9
- Wed, 11 Mar 2026 09:20:38 GMT
19
+ Wed, 11 Mar 2026 09:22:22 GMT
10
20
  [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-combobox_v9.16.17..@fluentui/react-combobox_v9.16.18)
11
21
 
12
22
  ### Patches
13
23
 
14
- - Bump @fluentui/react-field to v9.4.16 ([PR #35854](https://github.com/microsoft/fluentui/pull/35854) by beachball)
24
+ - Bump @fluentui/react-field to v9.4.16 ([PR #35859](https://github.com/microsoft/fluentui/pull/35859) by beachball)
15
25
 
16
26
  ## [9.16.17](https://github.com/microsoft/fluentui/tree/@fluentui/react-combobox_v9.16.17)
17
27
 
package/dist/index.d.ts CHANGED
@@ -4,6 +4,7 @@ import { ActiveDescendantImperativeRef } from '@fluentui/react-aria';
4
4
  import type { ComponentProps } from '@fluentui/react-utilities';
5
5
  import type { ComponentState } from '@fluentui/react-utilities';
6
6
  import { ContextSelector } from '@fluentui/react-context-selector';
7
+ import type { DistributiveOmit } from '@fluentui/react-utilities';
7
8
  import { EventData } from '@fluentui/react-utilities';
8
9
  import { EventHandler } from '@fluentui/react-utilities';
9
10
  import type { ExtractSlotProps } from '@fluentui/react-utilities';
@@ -24,6 +25,16 @@ declare type ActiveOptionChangeData = EventData<'change', ActiveDescendantChange
24
25
  nextOption: OptionValue | null | undefined;
25
26
  };
26
27
 
28
+ /**
29
+ * Combobox Props without design-only props.
30
+ */
31
+ export declare type BaseComboboxProps = DistributiveOmit<ComboboxProps, 'appearance' | 'size'>;
32
+
33
+ /**
34
+ * State used in rendering Combobox, without design-only state.
35
+ */
36
+ export declare type BaseComboboxState = DistributiveOmit<ComboboxState, 'appearance' | 'size'>;
37
+
27
38
  /**
28
39
  * Combobox component: a selection control that allows users to choose from a set of possible options
29
40
  */
@@ -217,6 +228,16 @@ export declare type ComboboxState = ComponentState<ComboboxSlots> & ComboboxBase
217
228
  */
218
229
  export declare const Dropdown: ForwardRefComponent<DropdownProps>;
219
230
 
231
+ /**
232
+ * Dropdown Props without design-only props.
233
+ */
234
+ export declare type DropdownBaseHookProps = DistributiveOmit<DropdownProps, 'appearance' | 'size'>;
235
+
236
+ /**
237
+ * State used in rendering Dropdown, without design-only state.
238
+ */
239
+ export declare type DropdownBaseHookState = DistributiveOmit<DropdownState, 'appearance' | 'size'>;
240
+
220
241
  export declare const dropdownClassNames: SlotClassNames<DropdownSlots>;
221
242
 
222
243
  export declare type DropdownContextValues = ComboboxBaseContextValues;
@@ -463,7 +484,7 @@ declare type OptionValue = {
463
484
  /**
464
485
  * Render the final JSX of Combobox
465
486
  */
466
- export declare const renderCombobox_unstable: (state: ComboboxState, contextValues: ComboboxContextValues) => JSXElement;
487
+ export declare const renderCombobox_unstable: (state: BaseComboboxState, contextValues: ComboboxContextValues) => JSXElement;
467
488
 
468
489
  /**
469
490
  * Render the final JSX of Dropdown
@@ -519,10 +540,11 @@ declare type SelectionState = {
519
540
  };
520
541
 
521
542
  /**
522
- * @internal
523
543
  * useButtonTriggerSlot returns a tuple of trigger/listbox shorthand,
524
544
  * with the semantics and event handlers needed for the Combobox and Dropdown components.
525
545
  * The element type of the ref should always match the element type used in the trigger shorthand.
546
+ *
547
+ * @internal
526
548
  */
527
549
  export declare function useButtonTriggerSlot(triggerFromProps: NonNullable<Slot<'button'>>, ref: React_2.Ref<HTMLButtonElement>, options: UseButtonTriggerSlotOptions): SlotComponentType<ExtractSlotProps<Slot<'button'>>>;
528
550
 
@@ -544,8 +566,17 @@ declare type UseButtonTriggerSlotOptions = {
544
566
  export declare const useCombobox_unstable: (props: ComboboxProps, ref: React_2.Ref<HTMLInputElement>) => ComboboxState;
545
567
 
546
568
  /**
547
- * @internal
569
+ * Create the base state required to render Combobox, without design-only props.
570
+ *
571
+ * @param props - props from this instance of Combobox (without appearance and size)
572
+ * @param ref - reference to root HTMLInputElement of Combobox
573
+ */
574
+ export declare const useComboboxBase_unstable: (props: BaseComboboxProps, ref: React_2.Ref<HTMLInputElement>) => BaseComboboxState;
575
+
576
+ /**
548
577
  * State shared between Combobox and Dropdown components
578
+ *
579
+ * @internal
549
580
  */
550
581
  export declare const useComboboxBaseState: (props: ComboboxBaseProps & {
551
582
  children?: React_2.ReactNode;
@@ -599,16 +630,25 @@ declare type UsedComboboxState = UseTriggerSlotState & Pick<ComboboxBaseState, '
599
630
  */
600
631
  export declare const useDropdown_unstable: (props: DropdownProps, ref: React_2.Ref<HTMLButtonElement>) => DropdownState;
601
632
 
633
+ /**
634
+ * Create the base state required to render Dropdown, without design-only props.
635
+ *
636
+ * @param props - props from this instance of Dropdown (without appearance and size)
637
+ * @param ref - reference to root HTMLButtonElement of Dropdown
638
+ */
639
+ export declare const useDropdownBase_unstable: (props: DropdownBaseHookProps, ref: React_2.Ref<HTMLButtonElement>) => DropdownBaseHookState;
640
+
602
641
  /**
603
642
  * Apply styling to the Dropdown slots based on the state
604
643
  */
605
644
  export declare const useDropdownStyles_unstable: (state: DropdownState) => DropdownState;
606
645
 
607
646
  /**
608
- * @internal
609
647
  * useInputTriggerSlot returns a tuple of trigger/listbox shorthand,
610
648
  * with the semantics and event handlers needed for the Combobox and Dropdown components.
611
649
  * The element type of the ref should always match the element type used in the trigger shorthand.
650
+ *
651
+ * @internal
612
652
  */
613
653
  export declare function useInputTriggerSlot(triggerFromProps: NonNullable<Slot<'input'>>, ref: React_2.Ref<HTMLInputElement>, options: UseInputTriggerSlotOptions): SlotComponentType<ExtractSlotProps<Slot<'input'>>>;
614
654
 
@@ -664,6 +704,14 @@ export declare const useListboxStyles_unstable: (state: ListboxState) => Listbox
664
704
  */
665
705
  export declare const useOption_unstable: (props: OptionProps, ref: React_2.Ref<HTMLElement>) => OptionState;
666
706
 
707
+ /**
708
+ * Create the base state required to render Option.
709
+ *
710
+ * @param props - props from this instance of Option
711
+ * @param ref - reference to root HTMLElement of Option
712
+ */
713
+ export declare const useOptionBase_unstable: (props: OptionProps, ref: React_2.Ref<HTMLElement>) => OptionState;
714
+
667
715
  /**
668
716
  * Create the state required to render OptionGroup.
669
717
  *
package/lib/Combobox.js CHANGED
@@ -1 +1 @@
1
- export { Combobox, comboboxClassNames, renderCombobox_unstable, useComboboxStyles_unstable, useCombobox_unstable } from './components/Combobox/index';
1
+ export { Combobox, comboboxClassNames, renderCombobox_unstable, useComboboxStyles_unstable, useComboboxBase_unstable, useCombobox_unstable } from './components/Combobox/index';
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/Combobox.ts"],"sourcesContent":["export type {\n ActiveOptionChangeData,\n ComboboxContextValues,\n ComboboxOpenChangeData,\n ComboboxOpenEvents,\n ComboboxProps,\n ComboboxSlots,\n ComboboxState,\n} from './components/Combobox/index';\nexport {\n Combobox,\n comboboxClassNames,\n renderCombobox_unstable,\n useComboboxStyles_unstable,\n useCombobox_unstable,\n} from './components/Combobox/index';\n"],"names":["Combobox","comboboxClassNames","renderCombobox_unstable","useComboboxStyles_unstable","useCombobox_unstable"],"mappings":"AASA,SACEA,QAAQ,EACRC,kBAAkB,EAClBC,uBAAuB,EACvBC,0BAA0B,EAC1BC,oBAAoB,QACf,8BAA8B"}
1
+ {"version":3,"sources":["../src/Combobox.ts"],"sourcesContent":["export type {\n ActiveOptionChangeData,\n BaseComboboxProps,\n BaseComboboxState,\n ComboboxContextValues,\n ComboboxOpenChangeData,\n ComboboxOpenEvents,\n ComboboxProps,\n ComboboxSlots,\n ComboboxState,\n} from './components/Combobox/index';\nexport {\n Combobox,\n comboboxClassNames,\n renderCombobox_unstable,\n useComboboxStyles_unstable,\n useComboboxBase_unstable,\n useCombobox_unstable,\n} from './components/Combobox/index';\n"],"names":["Combobox","comboboxClassNames","renderCombobox_unstable","useComboboxStyles_unstable","useComboboxBase_unstable","useCombobox_unstable"],"mappings":"AAWA,SACEA,QAAQ,EACRC,kBAAkB,EAClBC,uBAAuB,EACvBC,0BAA0B,EAC1BC,wBAAwB,EACxBC,oBAAoB,QACf,8BAA8B"}
package/lib/Dropdown.js CHANGED
@@ -1 +1 @@
1
- export { Dropdown, dropdownClassNames, renderDropdown_unstable, useDropdownStyles_unstable, useDropdown_unstable } from './components/Dropdown/index';
1
+ export { Dropdown, dropdownClassNames, renderDropdown_unstable, useDropdownStyles_unstable, useDropdownBase_unstable, useDropdown_unstable } from './components/Dropdown/index';
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/Dropdown.ts"],"sourcesContent":["export type {\n ActiveOptionChangeData,\n DropdownContextValues,\n DropdownOpenChangeData,\n DropdownOpenEvents,\n DropdownProps,\n DropdownSlots,\n DropdownState,\n} from './components/Dropdown/index';\nexport {\n Dropdown,\n dropdownClassNames,\n renderDropdown_unstable,\n useDropdownStyles_unstable,\n useDropdown_unstable,\n} from './components/Dropdown/index';\n"],"names":["Dropdown","dropdownClassNames","renderDropdown_unstable","useDropdownStyles_unstable","useDropdown_unstable"],"mappings":"AASA,SACEA,QAAQ,EACRC,kBAAkB,EAClBC,uBAAuB,EACvBC,0BAA0B,EAC1BC,oBAAoB,QACf,8BAA8B"}
1
+ {"version":3,"sources":["../src/Dropdown.ts"],"sourcesContent":["export type {\n ActiveOptionChangeData,\n DropdownBaseHookProps,\n DropdownBaseHookState,\n DropdownContextValues,\n DropdownOpenChangeData,\n DropdownOpenEvents,\n DropdownProps,\n DropdownSlots,\n DropdownState,\n} from './components/Dropdown/index';\nexport {\n Dropdown,\n dropdownClassNames,\n renderDropdown_unstable,\n useDropdownStyles_unstable,\n useDropdownBase_unstable,\n useDropdown_unstable,\n} from './components/Dropdown/index';\n"],"names":["Dropdown","dropdownClassNames","renderDropdown_unstable","useDropdownStyles_unstable","useDropdownBase_unstable","useDropdown_unstable"],"mappings":"AAWA,SACEA,QAAQ,EACRC,kBAAkB,EAClBC,uBAAuB,EACvBC,0BAA0B,EAC1BC,wBAAwB,EACxBC,oBAAoB,QACf,8BAA8B"}
package/lib/Option.js CHANGED
@@ -1 +1 @@
1
- export { Option, optionClassNames, renderOption_unstable, useOptionStyles_unstable, useOption_unstable } from './components/Option/index';
1
+ export { Option, optionClassNames, renderOption_unstable, useOptionStyles_unstable, useOption_unstable, useOptionBase_unstable } from './components/Option/index';
package/lib/Option.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/Option.ts"],"sourcesContent":["export type { OptionProps, OptionSlots, OptionState } from './components/Option/index';\nexport {\n Option,\n optionClassNames,\n renderOption_unstable,\n useOptionStyles_unstable,\n useOption_unstable,\n} from './components/Option/index';\n"],"names":["Option","optionClassNames","renderOption_unstable","useOptionStyles_unstable","useOption_unstable"],"mappings":"AACA,SACEA,MAAM,EACNC,gBAAgB,EAChBC,qBAAqB,EACrBC,wBAAwB,EACxBC,kBAAkB,QACb,4BAA4B"}
1
+ {"version":3,"sources":["../src/Option.ts"],"sourcesContent":["export type { OptionProps, OptionSlots, OptionState } from './components/Option/index';\nexport {\n Option,\n optionClassNames,\n renderOption_unstable,\n useOptionStyles_unstable,\n useOption_unstable,\n useOptionBase_unstable,\n} from './components/Option/index';\n"],"names":["Option","optionClassNames","renderOption_unstable","useOptionStyles_unstable","useOption_unstable","useOptionBase_unstable"],"mappings":"AACA,SACEA,MAAM,EACNC,gBAAgB,EAChBC,qBAAqB,EACrBC,wBAAwB,EACxBC,kBAAkB,EAClBC,sBAAsB,QACjB,4BAA4B"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/components/Combobox/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 ActiveOptionChangeData as ComboboxBaseActiveOptionChangeData,\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 freeform?: boolean;\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;\nexport type ActiveOptionChangeData = ComboboxBaseActiveOptionChangeData;\n"],"names":["React"],"mappings":"AAAA,YAAYA,WAAW,QAAQ"}
1
+ {"version":3,"sources":["../src/components/Combobox/Combobox.types.ts"],"sourcesContent":["import * as React from 'react';\nimport type { ComponentProps, ComponentState, DistributiveOmit, Slot } from '@fluentui/react-utilities';\nimport type { ActiveDescendantImperativeRef } from '@fluentui/react-aria';\nimport type {\n ActiveOptionChangeData as ComboboxBaseActiveOptionChangeData,\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 freeform?: boolean;\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 * Combobox Props without design-only props.\n */\nexport type BaseComboboxProps = DistributiveOmit<ComboboxProps, 'appearance' | 'size'>;\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/**\n * State used in rendering Combobox, without design-only state.\n */\nexport type BaseComboboxState = DistributiveOmit<ComboboxState, 'appearance' | 'size'>;\n\n/* Export types defined in ComboboxBase */\nexport type ComboboxContextValues = ComboboxBaseContextValues;\nexport type ComboboxOpenChangeData = ComboboxBaseOpenChangeData;\nexport type ComboboxOpenEvents = ComboboxBaseOpenEvents;\nexport type ActiveOptionChangeData = ComboboxBaseActiveOptionChangeData;\n"],"names":["React"],"mappings":"AAAA,YAAYA,WAAW,QAAQ"}
@@ -1,4 +1,4 @@
1
1
  export { Combobox } from './Combobox';
2
2
  export { renderCombobox_unstable } from './renderCombobox';
3
- export { useCombobox_unstable } from './useCombobox';
3
+ export { useComboboxBase_unstable, useCombobox_unstable } from './useCombobox';
4
4
  export { comboboxClassNames, useComboboxStyles_unstable } from './useComboboxStyles.styles';
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/components/Combobox/index.ts"],"sourcesContent":["export { Combobox } from './Combobox';\nexport type {\n ActiveOptionChangeData,\n ComboboxContextValues,\n ComboboxOpenChangeData,\n ComboboxOpenEvents,\n ComboboxProps,\n ComboboxSlots,\n ComboboxState,\n} from './Combobox.types';\nexport { renderCombobox_unstable } from './renderCombobox';\nexport { useCombobox_unstable } from './useCombobox';\nexport { comboboxClassNames, useComboboxStyles_unstable } from './useComboboxStyles.styles';\n"],"names":["Combobox","renderCombobox_unstable","useCombobox_unstable","comboboxClassNames","useComboboxStyles_unstable"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,aAAa;AAUtC,SAASC,uBAAuB,QAAQ,mBAAmB;AAC3D,SAASC,oBAAoB,QAAQ,gBAAgB;AACrD,SAASC,kBAAkB,EAAEC,0BAA0B,QAAQ,6BAA6B"}
1
+ {"version":3,"sources":["../src/components/Combobox/index.ts"],"sourcesContent":["export { Combobox } from './Combobox';\nexport type {\n ActiveOptionChangeData,\n BaseComboboxProps,\n BaseComboboxState,\n ComboboxContextValues,\n ComboboxOpenChangeData,\n ComboboxOpenEvents,\n ComboboxProps,\n ComboboxSlots,\n ComboboxState,\n} from './Combobox.types';\nexport { renderCombobox_unstable } from './renderCombobox';\nexport { useComboboxBase_unstable, useCombobox_unstable } from './useCombobox';\nexport { comboboxClassNames, useComboboxStyles_unstable } from './useComboboxStyles.styles';\n"],"names":["Combobox","renderCombobox_unstable","useComboboxBase_unstable","useCombobox_unstable","comboboxClassNames","useComboboxStyles_unstable"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,aAAa;AAYtC,SAASC,uBAAuB,QAAQ,mBAAmB;AAC3D,SAASC,wBAAwB,EAAEC,oBAAoB,QAAQ,gBAAgB;AAC/E,SAASC,kBAAkB,EAAEC,0BAA0B,QAAQ,6BAA6B"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/components/Combobox/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 type { JSXElement } from '@fluentui/react-utilities';\nimport { ComboboxContext } from '../../contexts/ComboboxContext';\nimport type { ComboboxContextValues, ComboboxState, ComboboxSlots } from './Combobox.types';\nimport { ListboxProvider } from '../../contexts/ListboxContext';\n\n/**\n * Render the final JSX of Combobox\n */\nexport const renderCombobox_unstable = (state: ComboboxState, contextValues: ComboboxContextValues): JSXElement => {\n assertSlots<ComboboxSlots>(state);\n\n return (\n <state.root>\n <ActiveDescendantContextProvider value={contextValues.activeDescendant}>\n <ListboxProvider value={contextValues.listbox}>\n {/*eslint-disable-next-line @typescript-eslint/no-deprecated*/}\n <ComboboxContext.Provider value={contextValues.combobox}>\n <state.input />\n {state.clearIcon && <state.clearIcon />}\n {state.expandIcon && <state.expandIcon />}\n {state.listbox &&\n (state.inlinePopup ? (\n <state.listbox />\n ) : (\n <Portal mountNode={state.mountNode}>\n <state.listbox />\n </Portal>\n ))}\n {/*eslint-disable-next-line @typescript-eslint/no-deprecated*/}\n </ComboboxContext.Provider>\n </ListboxProvider>\n </ActiveDescendantContextProvider>\n </state.root>\n );\n};\n"],"names":["Portal","ActiveDescendantContextProvider","assertSlots","ComboboxContext","ListboxProvider","renderCombobox_unstable","state","contextValues","root","value","activeDescendant","listbox","Provider","combobox","input","clearIcon","expandIcon","inlinePopup","mountNode"],"mappings":"AAAA,0BAA0B,GAC1B,iDAAiD;AACjD,SAASA,MAAM,QAAQ,yBAAyB;AAChD,SAASC,+BAA+B,QAAQ,uBAAuB;AAEvE,SAASC,WAAW,QAAQ,4BAA4B;AAExD,SAASC,eAAe,QAAQ,iCAAiC;AAEjE,SAASC,eAAe,QAAQ,gCAAgC;AAEhE;;CAEC,GACD,OAAO,MAAMC,0BAA0B,CAACC,OAAsBC;IAC5DL,YAA2BI;IAE3B,qBACE,KAACA,MAAME,IAAI;kBACT,cAAA,KAACP;YAAgCQ,OAAOF,cAAcG,gBAAgB;sBACpE,cAAA,KAACN;gBAAgBK,OAAOF,cAAcI,OAAO;0BAE3C,cAAA,MAACR,gBAAgBS,QAAQ;oBAACH,OAAOF,cAAcM,QAAQ;;sCACrD,KAACP,MAAMQ,KAAK;wBACXR,MAAMS,SAAS,kBAAI,KAACT,MAAMS,SAAS;wBACnCT,MAAMU,UAAU,kBAAI,KAACV,MAAMU,UAAU;wBACrCV,MAAMK,OAAO,IACXL,CAAAA,MAAMW,WAAW,iBAChB,KAACX,MAAMK,OAAO,sBAEd,KAACX;4BAAOkB,WAAWZ,MAAMY,SAAS;sCAChC,cAAA,KAACZ,MAAMK,OAAO;0BAElB;;;;;;AAOd,EAAE"}
1
+ {"version":3,"sources":["../src/components/Combobox/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 type { JSXElement } from '@fluentui/react-utilities';\nimport { ComboboxContext } from '../../contexts/ComboboxContext';\nimport type { ComboboxContextValues, BaseComboboxState, ComboboxSlots } from './Combobox.types';\nimport { ListboxProvider } from '../../contexts/ListboxContext';\n\n/**\n * Render the final JSX of Combobox\n */\nexport const renderCombobox_unstable = (state: BaseComboboxState, contextValues: ComboboxContextValues): JSXElement => {\n assertSlots<ComboboxSlots>(state);\n\n return (\n <state.root>\n <ActiveDescendantContextProvider value={contextValues.activeDescendant}>\n <ListboxProvider value={contextValues.listbox}>\n {/*eslint-disable-next-line @typescript-eslint/no-deprecated*/}\n <ComboboxContext.Provider value={contextValues.combobox}>\n <state.input />\n {state.clearIcon && <state.clearIcon />}\n {state.expandIcon && <state.expandIcon />}\n {state.listbox &&\n (state.inlinePopup ? (\n <state.listbox />\n ) : (\n <Portal mountNode={state.mountNode}>\n <state.listbox />\n </Portal>\n ))}\n {/*eslint-disable-next-line @typescript-eslint/no-deprecated*/}\n </ComboboxContext.Provider>\n </ListboxProvider>\n </ActiveDescendantContextProvider>\n </state.root>\n );\n};\n"],"names":["Portal","ActiveDescendantContextProvider","assertSlots","ComboboxContext","ListboxProvider","renderCombobox_unstable","state","contextValues","root","value","activeDescendant","listbox","Provider","combobox","input","clearIcon","expandIcon","inlinePopup","mountNode"],"mappings":"AAAA,0BAA0B,GAC1B,iDAAiD;AACjD,SAASA,MAAM,QAAQ,yBAAyB;AAChD,SAASC,+BAA+B,QAAQ,uBAAuB;AAEvE,SAASC,WAAW,QAAQ,4BAA4B;AAExD,SAASC,eAAe,QAAQ,iCAAiC;AAEjE,SAASC,eAAe,QAAQ,gCAAgC;AAEhE;;CAEC,GACD,OAAO,MAAMC,0BAA0B,CAACC,OAA0BC;IAChEL,YAA2BI;IAE3B,qBACE,KAACA,MAAME,IAAI;kBACT,cAAA,KAACP;YAAgCQ,OAAOF,cAAcG,gBAAgB;sBACpE,cAAA,KAACN;gBAAgBK,OAAOF,cAAcI,OAAO;0BAE3C,cAAA,MAACR,gBAAgBS,QAAQ;oBAACH,OAAOF,cAAcM,QAAQ;;sCACrD,KAACP,MAAMQ,KAAK;wBACXR,MAAMS,SAAS,kBAAI,KAACT,MAAMS,SAAS;wBACnCT,MAAMU,UAAU,kBAAI,KAACV,MAAMU,UAAU;wBACrCV,MAAMK,OAAO,IACXL,CAAAA,MAAMW,WAAW,iBAChB,KAACX,MAAMK,OAAO,sBAEd,KAACX;4BAAOkB,WAAWZ,MAAMY,SAAS;sCAChC,cAAA,KAACZ,MAAMK,OAAO;0BAElB;;;;;;AAOd,EAAE"}
@@ -12,30 +12,27 @@ import { useListboxSlot } from '../../utils/useListboxSlot';
12
12
  import { useInputTriggerSlot } from './useInputTriggerSlot';
13
13
  import { optionClassNames } from '../Option/useOptionStyles.styles';
14
14
  /**
15
- * Create the state required to render Combobox.
16
- *
17
- * The returned state can be modified with hooks such as useComboboxStyles_unstable,
18
- * before being passed to renderCombobox_unstable.
15
+ * Create the base state required to render Combobox, without design-only props.
19
16
  *
20
- * @param props - props from this instance of Combobox
21
- * @param ref - reference to root HTMLElement of Combobox
22
- */ export const useCombobox_unstable = (props, ref)=>{
17
+ * @param props - props from this instance of Combobox (without appearance and size)
18
+ * @param ref - reference to root HTMLInputElement of Combobox
19
+ */ export const useComboboxBase_unstable = (props, ref)=>{
23
20
  'use no memo';
24
21
  var _state_clearIcon, _state_clearIcon1;
25
22
  // Merge props from surrounding <Field>, if any
26
23
  props = useFieldControlProps_unstable(props, {
27
24
  supportsLabelFor: true,
28
- supportsRequired: true,
29
- supportsSize: true
25
+ supportsRequired: true
30
26
  });
31
27
  const { listboxRef: activeDescendantListboxRef, activeParentRef, controller: activeDescendantController } = useActiveDescendant({
32
28
  matchOption: (el)=>el.classList.contains(optionClassNames.root)
33
29
  });
34
- const baseState = useComboboxBaseState({
30
+ const comboboxInternalState = useComboboxBaseState({
35
31
  ...props,
36
32
  editable: true,
37
33
  activeDescendantController
38
34
  });
35
+ const { appearance: _appearance, size: _size, ...baseState } = comboboxInternalState;
39
36
  const { clearable, clearSelection, disabled, multiselect, open, selectedOptions, setOpen, value, hasFocus } = baseState;
40
37
  const [comboboxPopupRef, comboboxTargetRef] = useComboboxPositioning(props);
41
38
  const { disableAutoFocus = false, freeform, inlinePopup } = props;
@@ -44,13 +41,12 @@ import { optionClassNames } from '../Option/useOptionStyles.styles';
44
41
  props,
45
42
  primarySlotTagName: 'input',
46
43
  excludedPropNames: [
47
- 'children',
48
- 'size'
44
+ 'children'
49
45
  ]
50
46
  });
51
47
  const triggerRef = React.useRef(null);
52
48
  const listbox = useListboxSlot(props.listbox, useMergedRefs(comboboxPopupRef, activeDescendantListboxRef), {
53
- state: baseState,
49
+ state: comboboxInternalState,
54
50
  triggerRef,
55
51
  defaultProps: {
56
52
  children: props.children,
@@ -59,7 +55,7 @@ import { optionClassNames } from '../Option/useOptionStyles.styles';
59
55
  });
60
56
  var _props_input;
61
57
  const triggerSlot = useInputTriggerSlot((_props_input = props.input) !== null && _props_input !== void 0 ? _props_input : {}, useMergedRefs(triggerRef, activeParentRef, ref), {
62
- state: baseState,
58
+ state: comboboxInternalState,
63
59
  freeform,
64
60
  defaultProps: {
65
61
  type: 'text',
@@ -91,8 +87,7 @@ import { optionClassNames } from '../Option/useOptionStyles.styles';
91
87
  listbox: open || hasFocus ? listbox : undefined,
92
88
  clearIcon: slot.optional(props.clearIcon, {
93
89
  defaultProps: {
94
- 'aria-hidden': 'true',
95
- children: /*#__PURE__*/ React.createElement(DismissIcon, null)
90
+ 'aria-hidden': 'true'
96
91
  },
97
92
  elementType: 'span',
98
93
  renderByDefault: true
@@ -102,7 +97,6 @@ import { optionClassNames } from '../Option/useOptionStyles.styles';
102
97
  defaultProps: {
103
98
  'aria-disabled': disabled ? 'true' : undefined,
104
99
  'aria-expanded': open,
105
- children: /*#__PURE__*/ React.createElement(ChevronDownIcon, null),
106
100
  role: 'button'
107
101
  },
108
102
  elementType: 'span'
@@ -182,3 +176,31 @@ import { optionClassNames } from '../Option/useOptionStyles.styles';
182
176
  }
183
177
  return state;
184
178
  };
179
+ /**
180
+ * Create the state required to render Combobox.
181
+ *
182
+ * The returned state can be modified with hooks such as useComboboxStyles_unstable,
183
+ * before being passed to renderCombobox_unstable.
184
+ *
185
+ * @param props - props from this instance of Combobox
186
+ * @param ref - reference to root HTMLElement of Combobox
187
+ */ export const useCombobox_unstable = (props, ref)=>{
188
+ 'use no memo';
189
+ const { appearance = 'outline', size = 'medium', ...baseProps } = props;
190
+ const baseState = useComboboxBase_unstable(baseProps, ref);
191
+ if (baseState.clearIcon) {
192
+ var _baseState_clearIcon;
193
+ var _children;
194
+ (_children = (_baseState_clearIcon = baseState.clearIcon).children) !== null && _children !== void 0 ? _children : _baseState_clearIcon.children = /*#__PURE__*/ React.createElement(DismissIcon, null);
195
+ }
196
+ if (baseState.expandIcon) {
197
+ var _baseState_expandIcon;
198
+ var _children1;
199
+ (_children1 = (_baseState_expandIcon = baseState.expandIcon).children) !== null && _children1 !== void 0 ? _children1 : _baseState_expandIcon.children = /*#__PURE__*/ React.createElement(ChevronDownIcon, null);
200
+ }
201
+ return {
202
+ ...baseState,
203
+ appearance,
204
+ size
205
+ };
206
+ };
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/components/Combobox/useCombobox.tsx"],"sourcesContent":["'use client';\n\nimport * 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 useOnClickOutside,\n} from '@fluentui/react-utilities';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport { useComboboxBaseState } from '../../utils/useComboboxBaseState';\nimport { useComboboxPositioning } from '../../utils/useComboboxPositioning';\nimport { Listbox } from '../Listbox/Listbox';\nimport type { ComboboxOpenEvents, 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 'use no memo';\n\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 { clearable, clearSelection, disabled, multiselect, open, selectedOptions, setOpen, value, hasFocus } =\n baseState;\n const [comboboxPopupRef, comboboxTargetRef] = useComboboxPositioning(props);\n const { disableAutoFocus = false, 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 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 disableAutoFocus,\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 && !disabled && 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-disabled': disabled ? 'true' : undefined,\n 'aria-expanded': open,\n children: <ChevronDownIcon />,\n role: 'button',\n },\n elementType: 'span',\n }),\n showClearIcon,\n activeDescendantController,\n ...baseState,\n };\n\n const { targetDocument } = useFluent();\n\n useOnClickOutside({\n element: targetDocument,\n callback: event => setOpen(event as unknown as ComboboxOpenEvents, false),\n refs: [triggerRef, comboboxPopupRef, comboboxTargetRef],\n disabled: !open,\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","useOnClickOutside","useFluent_unstable","useFluent","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","disabled","multiselect","open","selectedOptions","setOpen","value","hasFocus","comboboxPopupRef","comboboxTargetRef","disableAutoFocus","freeform","inlinePopup","comboId","primary","triggerNativeProps","rootNativeProps","primarySlotTagName","excludedPropNames","triggerRef","useRef","listbox","defaultProps","children","triggerSlot","input","type","id","undefined","rootSlot","always","elementType","showClearIcon","length","components","expandIcon","clearIcon","optional","renderByDefault","role","targetDocument","element","callback","event","refs","onMouseDown","onIconMouseDown","onExpandIconMouseDown","preventDefault","current","focus","hasExpandLabel","defaultOpenString","chevronId","chevronLabelledBy","onClearIconMouseDown","ev","onClearIconClick","onClick","process","env","NODE_ENV","useEffect","console","error"],"mappings":"AAAA;AAEA,YAAYA,WAAW,QA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nG;QACF,GAAG;YAACjE;YAAWG;SAAY;IAC7B;IAEA,OAAOnB;AACT,EAAE"}
1
+ {"version":3,"sources":["../src/components/Combobox/useCombobox.tsx"],"sourcesContent":["'use client';\n\nimport * 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 useOnClickOutside,\n} from '@fluentui/react-utilities';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport { useComboboxBaseState } from '../../utils/useComboboxBaseState';\nimport { useComboboxPositioning } from '../../utils/useComboboxPositioning';\nimport { Listbox } from '../Listbox/Listbox';\nimport type {\n BaseComboboxProps,\n BaseComboboxState,\n ComboboxOpenEvents,\n ComboboxProps,\n ComboboxState,\n} from './Combobox.types';\nimport { useListboxSlot } from '../../utils/useListboxSlot';\nimport { useInputTriggerSlot } from './useInputTriggerSlot';\nimport { optionClassNames } from '../Option/useOptionStyles.styles';\n\n/**\n * Create the base state required to render Combobox, without design-only props.\n *\n * @param props - props from this instance of Combobox (without appearance and size)\n * @param ref - reference to root HTMLInputElement of Combobox\n */\nexport const useComboboxBase_unstable = (\n props: BaseComboboxProps,\n ref: React.Ref<HTMLInputElement>,\n): BaseComboboxState => {\n 'use no memo';\n\n // Merge props from surrounding <Field>, if any\n props = useFieldControlProps_unstable(props, { supportsLabelFor: true, supportsRequired: 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 comboboxInternalState = useComboboxBaseState({ ...props, editable: true, activeDescendantController });\n const { appearance: _appearance, size: _size, ...baseState } = comboboxInternalState;\n\n const { clearable, clearSelection, disabled, multiselect, open, selectedOptions, setOpen, value, hasFocus } =\n baseState;\n const [comboboxPopupRef, comboboxTargetRef] = useComboboxPositioning(props);\n const { disableAutoFocus = false, freeform, inlinePopup } = props;\n const comboId = useId('combobox-');\n\n const { primary: triggerNativeProps, root: rootNativeProps } = getPartitionedNativeProps({\n props,\n primarySlotTagName: 'input',\n excludedPropNames: ['children'],\n });\n\n const triggerRef = React.useRef<HTMLInputElement>(null);\n\n const listbox = useListboxSlot(props.listbox, useMergedRefs(comboboxPopupRef, activeDescendantListboxRef), {\n state: comboboxInternalState,\n triggerRef,\n defaultProps: {\n children: props.children,\n disableAutoFocus,\n },\n });\n\n const triggerSlot = useInputTriggerSlot(props.input ?? {}, useMergedRefs(triggerRef, activeParentRef, ref), {\n state: comboboxInternalState,\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 && !disabled && clearable && !multiselect;\n const state: BaseComboboxState = {\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 },\n elementType: 'span',\n renderByDefault: true,\n }),\n expandIcon: slot.optional(props.expandIcon, {\n renderByDefault: true,\n defaultProps: {\n 'aria-disabled': disabled ? 'true' : undefined,\n 'aria-expanded': open,\n role: 'button',\n },\n elementType: 'span',\n }),\n showClearIcon,\n activeDescendantController,\n ...baseState,\n };\n\n const { targetDocument } = useFluent();\n\n useOnClickOutside({\n element: targetDocument,\n callback: event => setOpen(event as unknown as ComboboxOpenEvents, false),\n refs: [triggerRef, comboboxPopupRef, comboboxTargetRef],\n disabled: !open,\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\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 'use no memo';\n\n const { appearance = 'outline', size = 'medium', ...baseProps } = props;\n const baseState = useComboboxBase_unstable(baseProps, ref);\n\n if (baseState.clearIcon) {\n baseState.clearIcon.children ??= <DismissIcon />;\n }\n\n if (baseState.expandIcon) {\n baseState.expandIcon.children ??= <ChevronDownIcon />;\n }\n\n return {\n ...baseState,\n appearance,\n size,\n };\n};\n"],"names":["React","useActiveDescendant","useFieldControlProps_unstable","ChevronDownRegular","ChevronDownIcon","DismissRegular","DismissIcon","getPartitionedNativeProps","mergeCallbacks","useEventCallback","useId","useMergedRefs","slot","useOnClickOutside","useFluent_unstable","useFluent","useComboboxBaseState","useComboboxPositioning","Listbox","useListboxSlot","useInputTriggerSlot","optionClassNames","useComboboxBase_unstable","props","ref","state","supportsLabelFor","supportsRequired","listboxRef","activeDescendantListboxRef","activeParentRef","controller","activeDescendantController","matchOption","el","classList","contains","root","comboboxInternalState","editable","appearance","_appearance","size","_size","baseState","clearable","clearSelection","disabled","multiselect","open","selectedOptions","setOpen","value","hasFocus","comboboxPopupRef","comboboxTargetRef","disableAutoFocus","freeform","inlinePopup","comboId","primary","triggerNativeProps","rootNativeProps","primarySlotTagName","excludedPropNames","triggerRef","useRef","listbox","defaultProps","children","triggerSlot","input","type","id","undefined","rootSlot","always","elementType","showClearIcon","length","components","expandIcon","clearIcon","optional","renderByDefault","role","targetDocument","element","callback","event","refs","onMouseDown","onIconMouseDown","onExpandIconMouseDown","preventDefault","current","focus","hasExpandLabel","defaultOpenString","chevronId","chevronLabelledBy","onClearIconMouseDown","ev","onClearIconClick","onClick","process","env","NODE_ENV","useEffect","console","error","useCombobox_unstable","baseProps"],"mappings":"AAAA;AAEA,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,EACJC,iBAAiB,QACZ,4BAA4B;AACnC,SAASC,sBAAsBC,SAAS,QAAQ,kCAAkC;AAClF,SAASC,oBAAoB,QAAQ,mCAAmC;AACxE,SAASC,sBAAsB,QAAQ,qCAAqC;AAC5E,SAASC,OAAO,QAAQ,qBAAqB;AAQ7C,SAASC,cAAc,QAAQ,6BAA6B;AAC5D,SAASC,mBAAmB,QAAQ,wBAAwB;AAC5D,SAASC,gBAAgB,QAAQ,mCAAmC;AAEpE;;;;;CAKC,GACD,OAAO,MAAMC,2BAA2B,CACtCC,OACAC;IAEA;QAqIiBC,kBAKAA;IAxIjB,+CAA+C;IAC/CF,QAAQrB,8BAA8BqB,OAAO;QAAEG,kBAAkB;QAAMC,kBAAkB;IAAK;IAC9F,MAAM,EACJC,YAAYC,0BAA0B,EACtCC,eAAe,EACfC,YAAYC,0BAA0B,EACvC,GAAG/B,oBAAsD;QACxDgC,aAAaC,CAAAA,KAAMA,GAAGC,SAAS,CAACC,QAAQ,CAACf,iBAAiBgB,IAAI;I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,MAAMyD,SAAS,EAAE;QACnBzD,MAAMyD,SAAS,CAACS,WAAW,GAAGU;QAC9B5E,MAAMyD,SAAS,CAACsB,OAAO,GAAGD;IAC5B;IAEA,gGAAgG;IAChG,IAAIvD,aAAa;QACfvB,MAAMyD,SAAS,GAAGR;IACpB;IAEA,IAAI+B,QAAQC,GAAG,CAACC,QAAQ,KAAK,cAAc;QACzC,kGAAkG;QAClG3G,MAAM4G,SAAS,CAAC;YACd,IAAI/D,aAAaG,aAAa;gBAC5B,sCAAsC;gBACtC6D,QAAQC,KAAK,CAAC,CAAC,iFAAiF,CAAC;YACnG;QACF,GAAG;YAACjE;YAAWG;SAAY;IAC7B;IAEA,OAAOvB;AACT,EAAE;AAEF;;;;;;;;CAQC,GACD,OAAO,MAAMsF,uBAAuB,CAACxF,OAAsBC;IACzD;IAEA,MAAM,EAAEgB,aAAa,SAAS,EAAEE,OAAO,QAAQ,EAAE,GAAGsE,WAAW,GAAGzF;IAClE,MAAMqB,YAAYtB,yBAAyB0F,WAAWxF;IAEtD,IAAIoB,UAAUsC,SAAS,EAAE;YACvBtC;;QAAAA,cAAAA,uBAAAA,UAAUsC,SAAS,EAACb,yDAApBzB,qBAAoByB,yBAAa,oBAAC/D;IACpC;IAEA,IAAIsC,UAAUqC,UAAU,EAAE;YACxBrC;;QAAAA,eAAAA,wBAAAA,UAAUqC,UAAU,EAACZ,2DAArBzB,sBAAqByB,yBAAa,oBAACjE;IACrC;IAEA,OAAO;QACL,GAAGwC,SAAS;QACZJ;QACAE;IACF;AACF,EAAE"}
@@ -5,10 +5,11 @@ import { ArrowLeft, ArrowRight } from '@fluentui/keyboard-keys';
5
5
  import { useTriggerSlot } from '../../utils/useTriggerSlot';
6
6
  import { getDropdownActionFromKey } from '../../utils/dropdownKeyActions';
7
7
  /**
8
- * @internal
9
8
  * useInputTriggerSlot returns a tuple of trigger/listbox shorthand,
10
9
  * with the semantics and event handlers needed for the Combobox and Dropdown components.
11
10
  * The element type of the ref should always match the element type used in the trigger shorthand.
11
+ *
12
+ * @internal
12
13
  */ export function useInputTriggerSlot(triggerFromProps, ref, options) {
13
14
  'use no memo';
14
15
  const { state: { open, value, selectOption, setValue, multiselect, selectedOptions, clearSelection, getOptionById, setOpen }, freeform, defaultProps, activeDescendantController } = options;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/components/Combobox/useInputTriggerSlot.ts"],"sourcesContent":["'use client';\n\nimport * 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 { ComboboxProps } from '../Combobox/Combobox.types';\nimport { UseTriggerSlotState, useTriggerSlot } from '../../utils/useTriggerSlot';\nimport { ComboboxBaseState } from '../../utils/ComboboxBase.types';\nimport { OptionValue } from '../../utils/OptionCollection.types';\nimport { getDropdownActionFromKey } from '../../utils/dropdownKeyActions';\n\ntype UsedComboboxState = UseTriggerSlotState &\n Pick<ComboboxBaseState, '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 * @internal\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 'use no memo';\n\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 = (event: 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(event, 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 = (event: React.ChangeEvent<HTMLInputElement>) => {\n const inputValue = event.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(event);\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((event: React.KeyboardEvent<HTMLInputElement>) => {\n if (!open && getDropdownActionFromKey(event) === 'Type') {\n setOpen(event, true);\n }\n\n // clear activedescendant when moving the text insertion cursor\n if (event.key === ArrowLeft || event.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(event, { 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' && event.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) && event.key === ' ') {\n triggerFromProps?.onKeyDown?.(event);\n return;\n }\n\n defaultOnKeyDown?.(event);\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","event","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;AAEA,YAAYA,WAAW,QAAQ;AAE/B,SAASC,cAAc,EAAEC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D,WAAW,UAAUjC,MAAMgC,GAAG,KAAK,OACpCC,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,MAAMgC,GAAG,KAAK,KAAK;gBACpDjD;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
+ {"version":3,"sources":["../src/components/Combobox/useInputTriggerSlot.ts"],"sourcesContent":["'use client';\n\nimport * 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 { ComboboxProps } from '../Combobox/Combobox.types';\nimport { UseTriggerSlotState, useTriggerSlot } from '../../utils/useTriggerSlot';\nimport { ComboboxBaseState } from '../../utils/ComboboxBase.types';\nimport { OptionValue } from '../../utils/OptionCollection.types';\nimport { getDropdownActionFromKey } from '../../utils/dropdownKeyActions';\n\ntype UsedComboboxState = UseTriggerSlotState &\n Pick<ComboboxBaseState, '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 *\n * @internal\n */\nexport function useInputTriggerSlot(\n triggerFromProps: NonNullable<Slot<'input'>>,\n ref: React.Ref<HTMLInputElement>,\n options: UseInputTriggerSlotOptions,\n): SlotComponentType<ExtractSlotProps<Slot<'input'>>> {\n 'use no memo';\n\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 = (event: 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(event, 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 = (event: React.ChangeEvent<HTMLInputElement>) => {\n const inputValue = event.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(event);\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((event: React.KeyboardEvent<HTMLInputElement>) => {\n if (!open && getDropdownActionFromKey(event) === 'Type') {\n setOpen(event, true);\n }\n\n // clear activedescendant when moving the text insertion cursor\n if (event.key === ArrowLeft || event.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(event, { 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' && event.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) && event.key === ' ') {\n triggerFromProps?.onKeyDown?.(event);\n return;\n }\n\n defaultOnKeyDown?.(event);\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","event","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;AAEA,YAAYA,WAAW,QAAQ;AAE/B,SAASC,cAAc,EAAEC,gBAAgB,QAAQ,4BAA4B;AAE7E,SAASC,SAAS,EAAEC,UAAU,QAAQ,0BAA0B;AAEhE,SAA8BC,cAAc,QAAQ,6BAA6B;AAGjF,SAASC,wBAAwB,QAAQ,iCAAiC;AAY1E;;;;;;CAMC,GACD,OAAO,SAASC,oBACdC,gBAA4C,EAC5CC,GAAgC,EAChCC,OAAmC;IAEnC;IAEA,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,OAAOG;YACtB;YAEA,wFAAwF;YACxFb,SAASiB;QACX;IACF;IAEA,MAAMC,qBAAqB,CAACC;QAC1B,MAAMC,eAAeD,uBAAAA,iCAAAA,WAAYL,IAAI,GAAGC,WAAW;QAEnD,IAAI,CAACK,g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AyBmB,WAAW,QAAQ;YACvDL,QAAQK,OAAO;QACjB;QAEA,+DAA+D;QAC/D,IAAIA,MAAMgC,GAAG,KAAKtD,aAAasB,MAAMgC,GAAG,KAAKrD,YAAY;YACvD+C,wBAAwB;QAC1B,OAAO;YACLA,wBAAwB;QAC1B;QAEA,oDAAoD;QACpD,MAAMO,SAASpD,yBAAyBmB,OAAO;YAAEb;YAAMI;QAAY;QACnE,IAAI0C,WAAW,QAAQ;YACrBL,SAASM,OAAO,GAAG;QACrB,OAGK,IACH,AAACD,WAAW,UAAUjC,MAAMgC,GAAG,KAAK,OACpCC,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,MAAMgC,GAAG,KAAK,KAAK;gBACpDjD;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":["../src/components/Dropdown/Dropdown.types.ts"],"sourcesContent":["import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';\nimport type { ActiveDescendantImperativeRef } from '@fluentui/react-aria';\nimport type {\n ActiveOptionChangeData as ComboboxBaseActiveOptionChangeData,\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 Omit<ComboboxBaseState, 'freeform'> & {\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;\nexport type ActiveOptionChangeData = ComboboxBaseActiveOptionChangeData;\n"],"names":[],"mappings":"AAmDA,WAAwE"}
1
+ {"version":3,"sources":["../src/components/Dropdown/Dropdown.types.ts"],"sourcesContent":["import type { ComponentProps, ComponentState, DistributiveOmit, Slot } from '@fluentui/react-utilities';\nimport type { ActiveDescendantImperativeRef } from '@fluentui/react-aria';\nimport type {\n ActiveOptionChangeData as ComboboxBaseActiveOptionChangeData,\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 * Dropdown Props without design-only props.\n */\nexport type DropdownBaseProps = DistributiveOmit<DropdownProps, 'appearance' | 'size'>;\n\n/**\n * State used in rendering Dropdown\n */\nexport type DropdownState = ComponentState<DropdownSlots> &\n Omit<ComboboxBaseState, 'freeform'> & {\n /** Whether the placeholder is currently displayed */\n placeholderVisible: boolean;\n\n showClearButton?: boolean;\n\n activeDescendantController: ActiveDescendantImperativeRef;\n };\n\n/**\n * State used in rendering Dropdown, without design-only state.\n */\nexport type DropdownBaseState = DistributiveOmit<DropdownState, 'appearance' | 'size'>;\n\n/* Export types defined in ComboboxBase */\nexport type DropdownContextValues = ComboboxBaseContextValues;\nexport type DropdownOpenEvents = ComboboxBaseOpenEvents;\nexport type DropdownOpenChangeData = ComboboxBaseOpenChangeData;\nexport type ActiveOptionChangeData = ComboboxBaseActiveOptionChangeData;\n"],"names":[],"mappings":"AA6DA,WAAwE"}
@@ -1,4 +1,4 @@
1
1
  export { Dropdown } from './Dropdown';
2
2
  export { renderDropdown_unstable } from './renderDropdown';
3
- export { useDropdown_unstable } from './useDropdown';
3
+ export { useDropdownBase_unstable, useDropdown_unstable } from './useDropdown';
4
4
  export { dropdownClassNames, useDropdownStyles_unstable } from './useDropdownStyles.styles';
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/components/Dropdown/index.ts"],"sourcesContent":["export { Dropdown } from './Dropdown';\nexport type {\n ActiveOptionChangeData,\n DropdownContextValues,\n DropdownOpenChangeData,\n DropdownOpenEvents,\n DropdownProps,\n DropdownSlots,\n DropdownState,\n} from './Dropdown.types';\nexport { renderDropdown_unstable } from './renderDropdown';\nexport { useDropdown_unstable } from './useDropdown';\nexport { dropdownClassNames, useDropdownStyles_unstable } from './useDropdownStyles.styles';\n"],"names":["Dropdown","renderDropdown_unstable","useDropdown_unstable","dropdownClassNames","useDropdownStyles_unstable"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,aAAa;AAUtC,SAASC,uBAAuB,QAAQ,mBAAmB;AAC3D,SAASC,oBAAoB,QAAQ,gBAAgB;AACrD,SAASC,kBAAkB,EAAEC,0BAA0B,QAAQ,6BAA6B"}
1
+ {"version":3,"sources":["../src/components/Dropdown/index.ts"],"sourcesContent":["export { Dropdown } from './Dropdown';\nexport type {\n ActiveOptionChangeData,\n DropdownBaseProps as DropdownBaseHookProps,\n DropdownBaseState as DropdownBaseHookState,\n DropdownContextValues,\n DropdownOpenChangeData,\n DropdownOpenEvents,\n DropdownProps,\n DropdownSlots,\n DropdownState,\n} from './Dropdown.types';\nexport { renderDropdown_unstable } from './renderDropdown';\nexport { useDropdownBase_unstable, useDropdown_unstable } from './useDropdown';\nexport { dropdownClassNames, useDropdownStyles_unstable } from './useDropdownStyles.styles';\n"],"names":["Dropdown","renderDropdown_unstable","useDropdownBase_unstable","useDropdown_unstable","dropdownClassNames","useDropdownStyles_unstable"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,aAAa;AAYtC,SAASC,uBAAuB,QAAQ,mBAAmB;AAC3D,SAASC,wBAAwB,EAAEC,oBAAoB,QAAQ,gBAAgB;AAC/E,SAASC,kBAAkB,EAAEC,0BAA0B,QAAQ,6BAA6B"}
@@ -4,10 +4,11 @@ import { useTimeout, mergeCallbacks } from '@fluentui/react-utilities';
4
4
  import { useTriggerSlot } from '../../utils/useTriggerSlot';
5
5
  import { getDropdownActionFromKey } from '../../utils/dropdownKeyActions';
6
6
  /**
7
- * @internal
8
7
  * useButtonTriggerSlot returns a tuple of trigger/listbox shorthand,
9
8
  * with the semantics and event handlers needed for the Combobox and Dropdown components.
10
9
  * The element type of the ref should always match the element type used in the trigger shorthand.
10
+ *
11
+ * @internal
11
12
  */ export function useButtonTriggerSlot(triggerFromProps, ref, options) {
12
13
  'use no memo';
13
14
  const { state: { open, setOpen, getOptionById }, defaultProps, activeDescendantController } = options;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/components/Dropdown/useButtonTriggerSlot.ts"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { useTimeout, mergeCallbacks } from '@fluentui/react-utilities';\nimport type { Slot, ExtractSlotProps, SlotComponentType } from '@fluentui/react-utilities';\nimport type { ActiveDescendantImperativeRef } from '@fluentui/react-aria';\nimport { useTriggerSlot, UseTriggerSlotState } from '../../utils/useTriggerSlot';\nimport { getDropdownActionFromKey } from '../../utils/dropdownKeyActions';\n\ntype UseButtonTriggerSlotOptions = {\n state: UseTriggerSlotState;\n defaultProps: unknown;\n activeDescendantController: ActiveDescendantImperativeRef;\n};\n\n/**\n * @internal\n * useButtonTriggerSlot 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 useButtonTriggerSlot(\n triggerFromProps: NonNullable<Slot<'button'>>,\n ref: React.Ref<HTMLButtonElement>,\n options: UseButtonTriggerSlotOptions,\n): SlotComponentType<ExtractSlotProps<Slot<'button'>>> {\n 'use no memo';\n\n const {\n state: { open, setOpen, getOptionById },\n defaultProps,\n activeDescendantController,\n } = options;\n\n // jump to matching option based on typing\n const searchString = React.useRef('');\n const [setKeyTimeout, clearKeyTimeout] = useTimeout();\n\n const moveToNextMatchingOption = (\n matcher: (optionText: string) => boolean,\n opt: { startFromNext: boolean } = { startFromNext: false },\n ) => {\n const { startFromNext } = opt;\n const activeOptionId = activeDescendantController.active();\n\n const nextInOrder = activeDescendantController.find(\n id => {\n const option = getOptionById(id);\n return !!option && matcher(option.text);\n },\n { startFrom: startFromNext ? activeDescendantController.next({ passive: true }) : activeOptionId },\n );\n\n if (nextInOrder) {\n return nextInOrder;\n }\n\n // Cycle back to first match\n return activeDescendantController.find(id => {\n const option = getOptionById(id);\n return !!option && matcher(option.text);\n });\n };\n\n const moveToNextMatchingOptionWithSameCharacterHandling = () => {\n if (\n moveToNextMatchingOption(\n optionText => {\n return optionText.toLocaleLowerCase().indexOf(searchString.current) === 0;\n },\n {\n // Slowly pressing the same key will cycle through options\n startFromNext: searchString.current.length === 1,\n },\n )\n ) {\n return;\n }\n\n // if there are no direct matches, check if the search is all the same letter, e.g. \"aaa\"\n if (\n allCharactersSame(searchString.current) &&\n moveToNextMatchingOption(\n optionText => {\n return optionText.toLocaleLowerCase().indexOf(searchString.current[0]) === 0;\n },\n {\n // if the search is all the same letter, cycle through options starting with that letter\n startFromNext: true,\n },\n )\n ) {\n return;\n }\n\n activeDescendantController.blur();\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 if (open) {\n moveToNextMatchingOptionWithSameCharacterHandling();\n }\n\n // update state\n !open && setOpen(ev, true);\n }\n };\n\n const trigger = useTriggerSlot(triggerFromProps, ref, {\n state: options.state,\n defaultProps,\n elementType: 'button',\n activeDescendantController,\n });\n trigger.onKeyDown = mergeCallbacks(onTriggerKeyDown, trigger.onKeyDown);\n\n return trigger;\n}\n\n/**\n * @returns - whether every character in the string is the same\n */\nfunction allCharactersSame(str: string) {\n for (let i = 1; i < str.length; i++) {\n if (str[i] !== str[i - 1]) {\n return false;\n }\n }\n\n return true;\n}\n"],"names":["React","useTimeout","mergeCallbacks","useTriggerSlot","getDropdownActionFromKey","useButtonTriggerSlot","triggerFromProps","ref","options","state","open","setOpen","getOptionById","defaultProps","activeDescendantController","searchString","useRef","setKeyTimeout","clearKeyTimeout","moveToNextMatchingOption","matcher","opt","startFromNext","activeOptionId","active","nextInOrder","find","id","option","text","startFrom","next","passive","moveToNextMatchingOptionWithSameCharacterHandling","optionText","toLocaleLowerCase","indexOf","current","length","allCharactersSame","blur","onTriggerKeyDown","ev","key","toLowerCase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D,IAEF;YACA;QACF;QAEA,yFAAyF;QACzF,IACEC,kBAAkBxB,aAAasB,OAAO,KACtClB,yBACEe,CAAAA;YACE,OAAOA,WAAWC,iBAAiB,GAAGC,OAAO,CAACrB,aAAasB,OAAO,CAAC,EAAE,MAAM;QAC7E,GACA;YACE,wFAAwF;YACxFf,eAAe;QACjB,IAEF;YACA;QACF;QAEAR,2BAA2B0B,IAAI;IACjC;IAEA,MAAMC,mBAAmB,CAACC;QACxB,8BAA8B;QAC9BxB;QAEA,kDAAkD;QAClD,IAAId,yBAAyBsC,QAAQ,QAAQ;YAC3C,uBAAuB;YACvB3B,aAAasB,OAAO,IAAIK,GAAGC,GAAG,CAACC,WAAW;YAC1C3B,cAAc;gBACZF,aAAasB,OAAO,GAAG;YACzB,GAAG;YAEH,IAAI3B,MAAM;gBACRuB;YACF;YAEA,eAAe;YACf,CAACvB,QAAQC,QAAQ+B,IAAI;QACvB;IACF;IAEA,MAAMG,UAAU1C,eAAeG,kBAAkBC,KAAK;QACpDE,OAAOD,QAAQC,KAAK;QACpBI;QACAiC,aAAa;QACbhC;IACF;IACA+B,QAAQE,SAAS,GAAG7C,eAAeuC,kBAAkBI,QAAQE,SAAS;IAEtE,OAAOF;AACT;AAEA;;CAEC,GACD,SAASN,kBAAkBS,GAAW;IACpC,IAAK,IAAIC,IAAI,GAAGA,IAAID,IAAIV,MAAM,EAAEW,IAAK;QACnC,IAAID,GAAG,CAACC,EAAE,KAAKD,GAAG,CAACC,IAAI,EAAE,EAAE;YACzB,OAAO;QACT;IACF;IAEA,OAAO;AACT"}
1
+ {"version":3,"sources":["../src/components/Dropdown/useButtonTriggerSlot.ts"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { useTimeout, mergeCallbacks } from '@fluentui/react-utilities';\nimport type { Slot, ExtractSlotProps, SlotComponentType } from '@fluentui/react-utilities';\nimport type { ActiveDescendantImperativeRef } from '@fluentui/react-aria';\nimport { useTriggerSlot, UseTriggerSlotState } from '../../utils/useTriggerSlot';\nimport { getDropdownActionFromKey } from '../../utils/dropdownKeyActions';\n\ntype UseButtonTriggerSlotOptions = {\n state: UseTriggerSlotState;\n defaultProps: unknown;\n activeDescendantController: ActiveDescendantImperativeRef;\n};\n\n/**\n * useButtonTriggerSlot 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 *\n * @internal\n */\nexport function useButtonTriggerSlot(\n triggerFromProps: NonNullable<Slot<'button'>>,\n ref: React.Ref<HTMLButtonElement>,\n options: UseButtonTriggerSlotOptions,\n): SlotComponentType<ExtractSlotProps<Slot<'button'>>> {\n 'use no memo';\n\n const {\n state: { open, setOpen, getOptionById },\n defaultProps,\n activeDescendantController,\n } = options;\n\n // jump to matching option based on typing\n const searchString = React.useRef('');\n const [setKeyTimeout, clearKeyTimeout] = useTimeout();\n\n const moveToNextMatchingOption = (\n matcher: (optionText: string) => boolean,\n opt: { startFromNext: boolean } = { startFromNext: false },\n ) => {\n const { startFromNext } = opt;\n const activeOptionId = activeDescendantController.active();\n\n const nextInOrder = activeDescendantController.find(\n id => {\n const option = getOptionById(id);\n return !!option && matcher(option.text);\n },\n { startFrom: startFromNext ? activeDescendantController.next({ passive: true }) : activeOptionId },\n );\n\n if (nextInOrder) {\n return nextInOrder;\n }\n\n // Cycle back to first match\n return activeDescendantController.find(id => {\n const option = getOptionById(id);\n return !!option && matcher(option.text);\n });\n };\n\n const moveToNextMatchingOptionWithSameCharacterHandling = () => {\n if (\n moveToNextMatchingOption(\n optionText => {\n return optionText.toLocaleLowerCase().indexOf(searchString.current) === 0;\n },\n {\n // Slowly pressing the same key will cycle through options\n startFromNext: searchString.current.length === 1,\n },\n )\n ) {\n return;\n }\n\n // if there are no direct matches, check if the search is all the same letter, e.g. \"aaa\"\n if (\n allCharactersSame(searchString.current) &&\n moveToNextMatchingOption(\n optionText => {\n return optionText.toLocaleLowerCase().indexOf(searchString.current[0]) === 0;\n },\n {\n // if the search is all the same letter, cycle through options starting with that letter\n startFromNext: true,\n },\n )\n ) {\n return;\n }\n\n activeDescendantController.blur();\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 if (open) {\n moveToNextMatchingOptionWithSameCharacterHandling();\n }\n\n // update state\n !open && setOpen(ev, true);\n }\n };\n\n const trigger = useTriggerSlot(triggerFromProps, ref, {\n state: options.state,\n defaultProps,\n elementType: 'button',\n activeDescendantController,\n });\n trigger.onKeyDown = mergeCallbacks(onTriggerKeyDown, trigger.onKeyDown);\n\n return trigger;\n}\n\n/**\n * @returns - whether every character in the string is the same\n */\nfunction allCharactersSame(str: string) {\n for (let i = 1; i < str.length; i++) {\n if (str[i] !== str[i - 1]) {\n return false;\n }\n }\n\n return true;\n}\n"],"names":["React","useTimeout","mergeCallbacks","useTriggerSlot","getDropdownActionFromKey","useButtonTriggerSlot","triggerFromProps","ref","options","state","open","setOpen","getOptionById","defaultProps","activeDescendantController","searchString","useRef","setKeyTimeout","clearKeyTimeout","moveToNextMatchingOption","matcher","opt","startFromNext","activeOptionId","active","nextInOrder","find","id","option","text","startFrom","next","passive","moveToNextMatchingOptionWithSameCharacterHandling","optionText","toLocaleLowerCase","indexOf","current","length","allCharactersSame","blur","onTriggerKeyDown","ev","key","toLowerCase","trigger","elementType","onKeyDown","str","i"],"mappings":"AAAA;AAEA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,UAAU,EAAEC,cAAc,QAAQ,4BAA4B;AAGvE,SAASC,cAAc,QAA6B,6BAA6B;AACjF,SAASC,wBAAwB,QAAQ,iCAAiC;AAQ1E;;;;;;CAMC,GACD,OAAO,SAASC,qBACdC,gBAA6C,EAC7CC,GAAiC,EACjCC,OAAoC;I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