Skip to content

Commit

Permalink
fix: onChange and onChangeValue should not be required
Browse files Browse the repository at this point in the history
  • Loading branch information
receter committed Jan 14, 2025
1 parent 8809152 commit eb16a1b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions packages/ui/lib/CheckboxGroup/useBaseCheckboxGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { CheckboxGroupContextType } from "./context";

export type BaseCheckboxGroupProps = {
value: string[];
onChangeValue: (value: string[]) => void;
onChange: (event: React.ChangeEvent<HTMLInputElement>) => void;
onChangeValue?: (value: string[]) => void;
onChange?: (event: React.ChangeEvent<HTMLInputElement>) => void;
children: React.ReactNode;
role?: "group";
name?: string;
Expand Down Expand Up @@ -34,9 +34,9 @@ export function useBaseCheckboxGroup<TTagName extends HTMLElementTagName>(
function handleChangeCheckbox(e: React.ChangeEvent<HTMLInputElement>) {
onChange?.(e);
if (e.target.checked && !value.includes(e.target.value)) {
onChangeValue([...value, e.target.value]);
onChangeValue?.([...value, e.target.value]);
} else if (!e.target.checked && value.includes(e.target.value)) {
onChangeValue(value.filter((v) => v !== e.target.value));
onChangeValue?.(value.filter((v) => v !== e.target.value));
}
}

Expand Down
6 changes: 3 additions & 3 deletions packages/ui/lib/RadioGroup/useBaseRadioGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { RadioGroupContextType } from "./context";

export type BaseRadioGroupProps = {
value: string;
onChangeValue: (value: string) => void;
onChange: (event: React.ChangeEvent<HTMLInputElement>) => void;
onChangeValue?: (value: string) => void;
onChange?: (event: React.ChangeEvent<HTMLInputElement>) => void;
children: React.ReactNode;
role?: "radiogroup";
name?: string;
Expand Down Expand Up @@ -31,7 +31,7 @@ export function useBaseRadioGroup<TTagName extends HTMLElementTagName>(
function handleChangeRadio(e: React.ChangeEvent<HTMLInputElement>) {
onChange?.(e);
if (e.target.checked && e.target.value !== value) {
onChangeValue(e.target.value);
onChangeValue?.(e.target.value);
}
}

Expand Down

0 comments on commit eb16a1b

Please sign in to comment.