Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: various bug fixes #456

Merged
merged 11 commits into from
Aug 26, 2024
Prev Previous commit
Next Next commit
fix(combobox): correct type definition & empty value for multiselect
jer3m01 committed Aug 26, 2024
commit c4ab48f1f78bb1cf90642f5f1038cab69ca240c8
8 changes: 4 additions & 4 deletions packages/core/src/combobox/combobox-root.tsx
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ import {

export interface ComboboxSingleSelectionOptions<T> {
/** The controlled value of the combobox. */
value?: T;
value?: T | null;

/**
* The value of the combobox when initially rendered.
@@ -24,7 +24,7 @@ export interface ComboboxSingleSelectionOptions<T> {
defaultValue?: T;

/** Event handler called when the value changes. */
onChange?: (value: T) => void;
onChange?: (value: T | null) => void;

/** Whether the combobox allow multiple selection. */
multiple?: false;
@@ -100,10 +100,10 @@ export function ComboboxRoot<

const onChange = (value: Option[]) => {
if (local.multiple) {
local.onChange?.(value as any);
local.onChange?.((value ?? []) as any);
} else {
// use `null` as "no value" because `undefined` mean the component is "uncontrolled".
local.onChange?.((value[0] ?? null) as any);
local.onChange?.((value[0] ?? null) as any); // TODO: maybe return undefined? breaking change!
}
};

4 changes: 2 additions & 2 deletions packages/core/src/select/select-root.tsx
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ import {

export interface SelectSingleSelectionOptions<T> {
/** The controlled value of the select. */
value?: T;
value?: T | null;

/**
* The value of the select when initially rendered.
@@ -104,7 +104,7 @@ export function SelectRoot<
local.onChange?.((value ?? []) as any);
} else {
// use `null` as "no value" because `undefined` mean the component is "uncontrolled".
local.onChange?.((value[0] ?? null) as any); // TODO: return undefined, breaking change!
local.onChange?.((value[0] ?? null) as any); // TODO: maybe return undefined? breaking change!
}
};