-
Notifications
You must be signed in to change notification settings - Fork 370
fix(Select): improve type consistency in onSelect
#11935
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
base: main
Are you sure you want to change the base?
Conversation
Preview: https://patternfly-react-pr-11935.surge.sh A11y report: https://patternfly-react-pr-11935-a11y.surge.sh Preview: https://pf-react-pr-11935.surge.sh A11y report: https://pf-react-pr-11935-a11y.surge.sh |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this be a breaking change? If consumers are expecting that their onSelect callback will be only a string or number and have logic/typing set up to only handle those types would this result in errors?
Since this is loosening a type, nothing should break as users of the callback can continue to use only strings or numbers as before |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you write a couple unit tests showing that string, number, etc will all work?
@@ -56,7 +57,7 @@ export interface SelectProps extends MenuProps, OUIAProps { | |||
/** @beta Flag indicating the first menu item should be focused after opening the menu. */ | |||
shouldFocusFirstItemOnOpen?: boolean; | |||
/** Function callback when user selects an option. */ | |||
onSelect?: (event?: React.MouseEvent<Element, MouseEvent>, value?: string | number) => void; | |||
onSelect?: (event?: React.MouseEvent<Element, MouseEvent>, value?: SelectOptionProps['value']) => void; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Menu's onSelect
should also be updated to reference MenuItem
's itemId
.
What: Closes #11361
Non-breaking change to loosen the expected type of
onSelect
'svalue
parameter, to matchSelectOptionProps
Additional issues:
This PR wold allow for the removal of a bunch of
ts-expect-error
s I added in openshift/console#14783