-
-
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
[Rating] Warn if precision prop is less than 0.1 #20491
[Rating] Warn if precision prop is less than 0.1 #20491
Conversation
Details of bundle changes.Comparing: 89f6208...9e7275b Details of page changes
|
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.
What do you think of this approach instead?
diff --git a/packages/material-ui-lab/src/Rating/Rating.js b/packages/material-ui-lab/src/Rating/Rating.js
index b0c65494d..72064fc26 100644
--- a/packages/material-ui-lab/src/Rating/Rating.js
+++ b/packages/material-ui-lab/src/Rating/Rating.js
@@ -187,14 +187,6 @@ const Rating = React.forwardRef(function Rating(props, ref) {
].join('\n'),
);
}
-
- if (precision < 0.1) {
- console.warn(
- `precision prop shouldn't be less than 0.1,
- because it can cause unexpected behaviour of rendering in <Rating> component.
- More info: https://material-ui.com/api/rating/`,
- );
- }
}, [valueProp, isControlled, precision]);
}
@@ -575,7 +567,17 @@ Rating.propTypes = {
/**
* The minimum increment value change allowed.
*/
- precision: PropTypes.number,
+ precision: chainPropTypes(PropTypes.number, (props) => {
+ if (props.precision < 0.1) {
+ return new Error(
+ [
+ 'Material-UI: the prop `precision` should be above 0.1.',
+ 'A value below this limit has an imperceptible impact.',
+ ].join('\n'),
+ );
+ }
+ return null;
+ }),
/**
* Removes all hover effects and pointer events.
*/
diff --git a/packages/material-ui-lab/src/Rating/Rating.test.js b/packages/material-ui-lab/src/Rating/Rating.test.js
index 2b8505c38..5b743fc0f 100644
--- a/packages/material-ui-lab/src/Rating/Rating.test.js
+++ b/packages/material-ui-lab/src/Rating/Rating.test.js
@@ -115,22 +115,4 @@ describe('<Rating />', () => {
checked = container.querySelector('input[name="rating-test"]:checked');
expect(checked.value).to.equal('2');
});
-
- it('should raise console warning if precision prop is less than 0.1', () => {
- beforeEach(() => {
- consoleErrorMock.spy();
- });
-
- afterEach(() => {
- consoleErrorMock.reset();
- });
-
- render(<Rating {...defaultProps} precision={0.01} />);
-
- expect(consoleErrorMock.messages()[0]).to.include(
- `precision prop shouldn't be less than 0.1,
- because it can cause unexpected behaviour of rendering in <Rating> component.
- More info: https://material-ui.com/api/rating/`,
- );
- });
});
We can have the component trace by using the prop-types, and we can avoid the test overhead given the simplicity of the logic.
f2e42c265
Didn't think about it. |
Should i update this pull request with your changes? |
Yes please :) |
cb08c79
to
9e7275b
Compare
By the way, thank you for helping :) |
Well done, thanks. |
Closes #16939