@react-types/combobox 3.13.10 → 3.14.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 (2) hide show
  1. package/package.json +3 -3
  2. package/src/index.d.ts +35 -8
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-types/combobox",
3
- "version": "3.13.10",
3
+ "version": "3.14.0",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "types": "src/index.d.ts",
@@ -9,7 +9,7 @@
9
9
  "url": "https://github.com/adobe/react-spectrum"
10
10
  },
11
11
  "dependencies": {
12
- "@react-types/shared": "^3.32.1"
12
+ "@react-types/shared": "^3.33.1"
13
13
  },
14
14
  "peerDependencies": {
15
15
  "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1"
@@ -17,5 +17,5 @@
17
17
  "publishConfig": {
18
18
  "access": "public"
19
19
  },
20
- "gitHead": "4d838da5bfe36abb35aed166995a9ef63825370f"
20
+ "gitHead": "8df187370053aa35f553cb388ad670f65e1ab371"
21
21
  }
package/src/index.d.ts CHANGED
@@ -29,26 +29,53 @@ import {
29
29
  SpectrumTextInputBase,
30
30
  StyleProps,
31
31
  TextInputBase,
32
- Validation
32
+ Validation,
33
+ ValueBase
33
34
  } from '@react-types/shared';
34
35
 
35
36
  export type MenuTriggerAction = 'focus' | 'input' | 'manual';
37
+ export type SelectionMode = 'single' | 'multiple';
38
+ export type ValueType<M extends SelectionMode> = M extends 'single' ? Key | null : Key[];
39
+ type ValidationType<M extends SelectionMode> = M extends 'single' ? Key : Key[];
36
40
 
37
- export interface ComboBoxValidationValue {
38
- /** The selected key in the ComboBox. */
41
+ export interface ComboBoxValidationValue<M extends SelectionMode = 'single'> {
42
+ /**
43
+ * The selected key in the ComboBox.
44
+ * @deprecated
45
+ */
39
46
  selectedKey: Key | null,
47
+ /** The keys of the currently selected items. */
48
+ value: ValidationType<M>,
40
49
  /** The value of the ComboBox input. */
41
50
  inputValue: string
42
51
  }
43
52
 
44
- export interface ComboBoxProps<T> extends CollectionBase<T>, Omit<SingleSelection, 'disallowEmptySelection' | 'onSelectionChange'>, InputBase, TextInputBase, Validation<ComboBoxValidationValue>, FocusableProps<HTMLInputElement>, LabelableProps, HelpTextProps {
53
+ export interface ComboBoxProps<T, M extends SelectionMode = 'single'> extends CollectionBase<T>, InputBase, ValueBase<ValueType<M>>, TextInputBase, Validation<ComboBoxValidationValue>, FocusableProps<HTMLInputElement>, LabelableProps, HelpTextProps {
45
54
  /** The list of ComboBox items (uncontrolled). */
46
55
  defaultItems?: Iterable<T>,
47
56
  /** The list of ComboBox items (controlled). */
48
57
  items?: Iterable<T>,
49
58
  /** Method that is called when the open state of the menu changes. Returns the new open state and the action that caused the opening of the menu. */
50
59
  onOpenChange?: (isOpen: boolean, menuTrigger?: MenuTriggerAction) => void,
51
- /** Handler that is called when the selection changes. */
60
+ /**
61
+ * Whether single or multiple selection is enabled.
62
+ * @default 'single'
63
+ */
64
+ selectionMode?: M,
65
+ /**
66
+ * The currently selected key in the collection (controlled).
67
+ * @deprecated
68
+ */
69
+ selectedKey?: Key | null,
70
+ /**
71
+ * The initial selected key in the collection (uncontrolled).
72
+ * @deprecated
73
+ */
74
+ defaultSelectedKey?: Key | null,
75
+ /**
76
+ * Handler that is called when the selection changes.
77
+ * @deprecated
78
+ */
52
79
  onSelectionChange?: (key: Key | null) => void,
53
80
  /** The value of the ComboBox input (controlled). */
54
81
  inputValue?: string,
@@ -57,7 +84,7 @@ export interface ComboBoxProps<T> extends CollectionBase<T>, Omit<SingleSelectio
57
84
  /** Handler that is called when the ComboBox input value changes. */
58
85
  onInputChange?: (value: string) => void,
59
86
  /** Whether the ComboBox allows a non-item matching input value to be set. */
60
- allowsCustomValue?: boolean,
87
+ allowsCustomValue?: boolean,
61
88
  // /**
62
89
  // * Whether the Combobox should only suggest matching options or autocomplete the field with the nearest matching option.
63
90
  // * @default 'suggest'
@@ -70,12 +97,12 @@ export interface ComboBoxProps<T> extends CollectionBase<T>, Omit<SingleSelectio
70
97
  menuTrigger?: MenuTriggerAction
71
98
  }
72
99
 
73
- export interface AriaComboBoxProps<T> extends ComboBoxProps<T>, DOMProps, InputDOMProps, AriaLabelingProps {
100
+ export interface AriaComboBoxProps<T, M extends SelectionMode = 'single'> extends ComboBoxProps<T, M>, DOMProps, InputDOMProps, AriaLabelingProps {
74
101
  /** Whether keyboard navigation is circular. */
75
102
  shouldFocusWrap?: boolean
76
103
  }
77
104
 
78
- export interface SpectrumComboBoxProps<T> extends SpectrumTextInputBase, Omit<AriaComboBoxProps<T>, 'menuTrigger' | 'isInvalid' | 'validationState'>, SpectrumFieldValidation<ComboBoxValidationValue>, SpectrumLabelableProps, StyleProps, Omit<AsyncLoadable, 'isLoading'> {
105
+ export interface SpectrumComboBoxProps<T> extends SpectrumTextInputBase, Omit<AriaComboBoxProps<T>, 'menuTrigger' | 'isInvalid' | 'validationState' | 'selectionMode' | 'selectedKey' | 'defaultSelectedKey' | 'onSelectionChange' | 'value' | 'defaultValue' | 'onChange'>, Omit<SingleSelection, 'disallowEmptySelection'>, SpectrumFieldValidation<ComboBoxValidationValue>, SpectrumLabelableProps, StyleProps, Omit<AsyncLoadable, 'isLoading'> {
79
106
  /**
80
107
  * The interaction required to display the ComboBox menu. Note that this prop has no effect on the mobile ComboBox experience.
81
108
  * @default 'input'