Skip to content

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

logonoff
Copy link
Member

@logonoff logonoff commented Jul 23, 2025

What: Closes #11361

Non-breaking change to loosen the expected type of onSelect's value parameter, to match SelectOptionProps

Additional issues:

This PR wold allow for the removal of a bunch of ts-expect-errors I added in openshift/console#14783

@patternfly-build
Copy link
Contributor

patternfly-build commented Jul 23, 2025

@nicolethoen nicolethoen requested a review from kmcfaul July 25, 2025 13:12
Copy link
Contributor

@wise-king-sullyman wise-king-sullyman left a 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?

@logonoff
Copy link
Member Author

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

Copy link
Contributor

@kmcfaul kmcfaul left a 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;
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SelectOption.value and Select.selected has "any" type, but Select.onSelect has "(..., string | number)"
5 participants