Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/@react-stately/combobox/src/useComboBoxState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
* governing permissions and limitations under the License.
*/

import {ChangeValueType, ComboBoxProps, MenuTriggerAction, SelectionMode, ValueType} from '@react-types/combobox';
import {Collection, CollectionStateBase, FocusStrategy, Key, Node, Selection} from '@react-types/shared';
import {ComboBoxProps, MenuTriggerAction, SelectionMode, ValueType} from '@react-types/combobox';
import {FormValidationState, useFormValidationState} from '@react-stately/form';
import {getChildNodes} from '@react-stately/collections';
import {ListCollection, ListState, useListState} from '@react-stately/list';
Expand Down Expand Up @@ -373,7 +373,7 @@ export function useComboBoxState<T extends object, M extends SelectionMode = 'si
// If multiple things are controlled, call onSelectionChange
if (value !== undefined && props.inputValue !== undefined) {
props.onSelectionChange?.(selectedKey);
props.onChange?.(displayValue);
props.onChange?.(displayValue as ChangeValueType<M>);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this is the right approach. Perhaps we could also update the change type to a readonly array at some point?


// Stop menu from reopening from useEffect
let itemText = selectedKey != null ? collection.getItem(selectedKey)?.textValue ?? '' : '';
Expand Down Expand Up @@ -504,7 +504,7 @@ function getDefaultInputValue(defaultInputValue: string | null | undefined, sele
return defaultInputValue;
}

function convertValue(value: Key | Key[] | null | undefined) {
function convertValue(value: Key | readonly Key[] | null | undefined) {
if (value === undefined) {
return undefined;
}
Expand Down
5 changes: 3 additions & 2 deletions packages/@react-types/combobox/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ import {

export type MenuTriggerAction = 'focus' | 'input' | 'manual';
export type SelectionMode = 'single' | 'multiple';
export type ValueType<M extends SelectionMode> = M extends 'single' ? Key | null : Key[];
export type ValueType<M extends SelectionMode> = M extends 'single' ? Key | null : readonly Key[];
export type ChangeValueType<M extends SelectionMode> = M extends 'single' ? Key | null : Key[];
type ValidationType<M extends SelectionMode> = M extends 'single' ? Key : Key[];

export interface ComboBoxValidationValue<M extends SelectionMode = 'single'> {
Expand All @@ -50,7 +51,7 @@ export interface ComboBoxValidationValue<M extends SelectionMode = 'single'> {
inputValue: string
}

export interface ComboBoxProps<T, M extends SelectionMode = 'single'> extends CollectionBase<T>, InputBase, ValueBase<ValueType<M>>, TextInputBase, Validation<ComboBoxValidationValue>, FocusableProps<HTMLInputElement>, LabelableProps, HelpTextProps {
export interface ComboBoxProps<T, M extends SelectionMode = 'single'> extends CollectionBase<T>, InputBase, ValueBase<ValueType<M>, ChangeValueType<M>>, TextInputBase, Validation<ComboBoxValidationValue>, FocusableProps<HTMLInputElement>, LabelableProps, HelpTextProps {
/** The list of ComboBox items (uncontrolled). */
defaultItems?: Iterable<T>,
/** The list of ComboBox items (controlled). */
Expand Down