-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
[Select][base] Add event parameter to the onChange callback #34158
[Select][base] Add event parameter to the onChange callback #34158
Conversation
…onchange-parameters
@michaldudak I can help update the Joy Select demos if you'd like. I added |
Thanks a lot, there's no need to, I can take a look at them myself. |
@michaldudak Can I use 'event.target.value' for getting the selected option? |
@siriwatknp no. The |
👍 for leaning toward consistency (similar to the |
Signed-off-by: Siriwat K <siriwatkunaporn@gmail.com>
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.
👍 Looks good to me.
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.
It's great to see this change of API :D
@@ -104,7 +104,10 @@ export interface SelectOwnProps<TValue extends {}> extends SelectStaticProps { | |||
/** | |||
* Callback fired when an option is selected. | |||
*/ | |||
onChange?: (value: TValue | null) => void; | |||
onChange?: ( | |||
e: React.MouseEvent | React.KeyboardEvent | React.FocusEvent | null, |
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.
💯 to remove these shorthands. As far as I know, these are the first in the codebase. I would argue that it's confusing for developers that are getting started, and less clear for experienced developers that are coming back to an old codebase. I think that e > event only for writing code, but if we assume that this code will be read a lot more than written, then I think it would be better with:
e: React.MouseEvent | React.KeyboardEvent | React.FocusEvent | null, | |
event: React.MouseEvent | React.KeyboardEvent | React.FocusEvent | null, |
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.
All right, will do a follow-up PR.
@@ -154,7 +154,7 @@ export default function UnstyledSelectsMultiple() { | |||
const [value, setValue] = React.useState<number | null>(10); | |||
return ( | |||
<div> | |||
<CustomSelect value={value} onChange={setValue}> | |||
<CustomSelect value={value} onChange={(e, newValue) => setValue(newValue)}> |
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.
based on the comment above, I think that it either:
<CustomSelect value={value} onChange={(e, newValue) => setValue(newValue)}> | |
<CustomSelect value={value} onChange={(event, newValue) => setValue(newValue)}> |
or
<CustomSelect value={value} onChange={(e, newValue) => setValue(newValue)}> | |
<CustomSelect value={value} onChange={(_, newValue) => setValue(newValue)}> |
Co-authored-by: Siriwat K <siriwatkunaporn@gmail.com>
The SelectUnstyled and MultiSelectUnstyled onChange callbacks did not have event as the first parameter, leading to inconsistency with other components and native HTML elements.
This PR adds the event parameter as the first one and moves the newly selected value to the second position. Because of this, it's a breaking change.
I've also changed the signature of Joy Select's
onChange
to match the one in Base (CC @siriwatknp).The
onHighlightChange
in useListbox while not exposed by Select and MultiSelect was also updated.Closes #33901