Skip to content

Commit

Permalink
fix(select): fix type issues with onChange
Browse files Browse the repository at this point in the history
  • Loading branch information
WesSouza authored and arturbien committed Jul 28, 2022
1 parent 7cef5d9 commit 38f7cf6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/Select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,10 @@ function SelectInner<T>(
return;
}

onChange?.(event, nextSelection as unknown as SelectOption<T>);
onChange?.(
event as unknown as SelectChangeEvent<T>,
nextSelection as unknown as SelectOption<T>
);
setValueState(nextSelection.value);
displayNode.current?.focus();
},
Expand Down
17 changes: 12 additions & 5 deletions src/Select/Select.types.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import React from 'react';

type SelectChangeEventTargetValue<T> = { value: T; name: string | undefined };

export type SelectChangeEvent<T> =
| (React.MouseEvent & {
target: {
value: { value: T; name: string | undefined };
};
| (Omit<React.ChangeEvent<HTMLSelectElement>, 'target'> & {
target: Omit<
React.ChangeEvent<HTMLSelectElement>['target'],
'name' | 'value'
> &
SelectChangeEventTargetValue<T>;
})
| React.ChangeEvent<HTMLSelectElement>;
| (Omit<React.MouseEvent, 'target'> & {
target: Omit<React.MouseEvent['target'], 'name' | 'value'> &
SelectChangeEventTargetValue<T>;
});

export type SelectOption<T> = {
label: string;
Expand Down

0 comments on commit 38f7cf6

Please sign in to comment.