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
[docs] Rating
value
is nullable in onChange
#26542
Conversation
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.
Thanks! Should onChangeActive
get the same treatment?
onChangeActive shouldn't get the same treatment since value type is number in onChangeActive. https://github.com/mui-org/material-ui/blob/next/packages/material-ui/src/Rating/Rating.d.ts#L89-L91 Not very sure the actual reason why he
Rogue |
@sakura90 I think that the point that Sebastian is making is the the current prop description and type definition seems out of sync with the implementation. Isn't this callback called 1. when using the keyboard navigation and 2. with a null value is landing in the reset option? |
This comment has been minimized.
This comment has been minimized.
@oliviertassinari onChangeActive and onChange are spelled similarly, but they are just 2 different event listeners. I think about 3 input scenarios - mouse, touch (from Android/iPhone), and keyboard - about these 2 event listeners. For mouse, right now, onChange is called 1. when using the mouse selection and 2. with a null value is landing in the reset option, but onChangeActive is called 1. when using the mouse navigation and 2. with a -1 value when the position of the mouse is outside Rating component. For touch, right now, onChange is called 1. when using the touch selection and 2. with a null value is landing in the reset option For keyboard, I don't spend too much time on both onChangeActive and onChange as it is a low frequent scenario. Back to your question, I think it is fair to let onChangeActive be what it is. onChangeActive is mainly used for the mouse scenario. It feels unusual to see a -1 value when the position of the mouse is outside Rating component while an event listener with a similar name onChange returns a null in a similar situation. Having a new type such as OUT_OF_RANGE instead of -1 is going to be more descriptive, but because most users of onChangeActive are developers, I think developers can advance their work with -1 and onChangeActive can be left as what it is. |
@eps1lon Subtle, but nice to fix when there is time to do. |
@eps1lon If you don't have further comments about onChangeActive and other things, what about merging the PR? |
@sakura90 Thanks for the exploration. I had a look too. It seems that diff --git a/packages/material-ui/src/Rating/Rating.js b/packages/material-ui/src/Rating/Rating.js
index 55a52464a2..744fea2e97 100644
--- a/packages/material-ui/src/Rating/Rating.js
+++ b/packages/material-ui/src/Rating/Rating.js
@@ -357,10 +357,6 @@ const Rating = React.forwardRef(function Rating(inProps, ref) {
hover: prev.hover,
focus: newFocus,
}));
-
- if (onChangeActive && focus !== newFocus) {
- onChangeActive(event, newFocus);
- }
};
const handleBlur = (event) => {
@@ -378,10 +374,6 @@ const Rating = React.forwardRef(function Rating(inProps, ref) {
hover: prev.hover,
focus: newFocus,
}));
-
- if (onChangeActive && focus !== newFocus) {
- onChangeActive(event, newFocus);
- }
};
const [emptyValueFocused, setEmptyValueFocused] = React.useState(false); |
The change seems to be nice. But if I am going to make the change, I am going to manually test the change before PR. I think if it is clearer about things about I am going to create a new issue, assign it to myself, and work on the issue. |
Rating
value
is nullable in onChange
@sakura90 Thanks! |
The previous PR I created somehow got closed immediately after I reverted my previous change. Please look at this PR instead.
@eps1lon you told me to look at material-ui/packages/material-ui/src/Rating/Rating.d.ts Line 82, but I think you meant I might take a look of a different line of Rating.d.ts. I couldn't understand when I looked an line 82.
Put in null in onChange in Rating, and also put in handling NullLiteral in auto generation of the descriptions of a function and its parameters.
Closes #26497