Skip to content

Commit

Permalink
Handle undefined onChange and remove undefined from formEventTypeAdapter
Browse files Browse the repository at this point in the history
  • Loading branch information
poulch committed Aug 20, 2024
1 parent 14b8d0b commit 9afbcc9
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/components/Combobox/Dynamic/DynamicCombobox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ const DynamicComboboxInner = <T extends Option>(
disabled={disabled}
{...props}
{...inputProps}
onChange={formEventTypeAdapter(inputProps.onChange)}
onChange={
inputProps.onChange && formEventTypeAdapter(inputProps.onChange)
}
/>

{endAdornment && typed && <Box>{endAdornment(value)}</Box>}
Expand Down
4 changes: 3 additions & 1 deletion src/components/Combobox/Static/Combobox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ const ComboboxInner = <T extends Option, V extends Option | string>(
title={isString(value) ? value : value?.label}
{...props}
{...inputProps}
onChange={formEventTypeAdapter(inputProps.onChange)}
onChange={
inputProps.onChange && formEventTypeAdapter(inputProps.onChange)
}
/>

{endAdornment && typed && <Box>{endAdornment(value)}</Box>}
Expand Down
4 changes: 3 additions & 1 deletion src/components/Multiselect/Dynamic/DynamicMultiselect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,9 @@ const DynamicMultiselectInner = <T extends Option>(
visibility={showInput ? "visible" : "hidden"}
{...inputProps}
{...props}
onChange={formEventTypeAdapter(inputProps.onChange)}
onChange={
inputProps.onChange && formEventTypeAdapter(inputProps.onChange)
}
/>
</MultiselectWrapper>

Expand Down
4 changes: 3 additions & 1 deletion src/components/Multiselect/Static/Multiselect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,9 @@ const MultiselectInner = <T extends Option, V extends Option | string>(
visibility={showInput ? "visible" : "hidden"}
{...inputProps}
{...props}
onChange={formEventTypeAdapter(inputProps.onChange)}
onChange={
inputProps.onChange && formEventTypeAdapter(inputProps.onChange)
}
/>
</MultiselectWrapper>

Expand Down
5 changes: 3 additions & 2 deletions src/utils/formEventTypeAdapter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { ChangeEventHandler, FormEventHandler } from "react";

// There is mismatch between desert box onChange type and downshift on change event
export const formEventTypeAdapter = (
event: ChangeEventHandler<Element> | undefined
): FormEventHandler | undefined => {
event: ChangeEventHandler<Element>
): FormEventHandler => {
return event;
};

0 comments on commit 9afbcc9

Please sign in to comment.