Skip to content
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] Fix readOnly + precision combination #19414

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion docs/src/pages/components/rating/HalfRating.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
import React from 'react';
import Rating from '@material-ui/lab/Rating';
import { makeStyles } from '@material-ui/core/styles';

const useStyles = makeStyles(theme => ({
root: {
display: 'flex',
flexDirection: 'column',
'& > * + *': {
marginTop: theme.spacing(1),
},
},
}));

export default function HalfRating() {
return <Rating name="half-rating" defaultValue={2.5} precision={0.5} />;
const classes = useStyles();

return (
<div className={classes.root}>
<Rating name="half-rating" defaultValue={2.5} precision={0.5} />
<Rating name="half-rating-read" defaultValue={2.5} precision={0.5} readOnly />
</div>
);
}
22 changes: 21 additions & 1 deletion docs/src/pages/components/rating/HalfRating.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
import React from 'react';
import Rating from '@material-ui/lab/Rating';
import { makeStyles, Theme, createStyles } from '@material-ui/core/styles';

const useStyles = makeStyles((theme: Theme) =>
createStyles({
root: {
display: 'flex',
flexDirection: 'column',
'& > * + *': {
marginTop: theme.spacing(1),
},
},
}),
);

export default function HalfRating() {
return <Rating name="half-rating" defaultValue={2.5} precision={0.5} />;
const classes = useStyles();

return (
<div className={classes.root}>
<Rating name="half-rating" defaultValue={2.5} precision={0.5} />
<Rating name="half-rating-read" defaultValue={2.5} precision={0.5} readOnly />
</div>
);
}
4 changes: 2 additions & 2 deletions docs/src/pages/components/rating/HoverRating.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const labels = {
};

const useStyles = makeStyles({
rating: {
root: {
width: 200,
display: 'flex',
alignItems: 'center',
Expand All @@ -30,7 +30,7 @@ export default function HoverRating() {
const classes = useStyles();

return (
<div className={classes.rating}>
<div className={classes.root}>
<Rating
name="hover-feedback"
value={value}
Expand Down
4 changes: 2 additions & 2 deletions docs/src/pages/components/rating/HoverRating.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const labels: { [index: string]: string } = {
};

const useStyles = makeStyles({
rating: {
root: {
width: 200,
display: 'flex',
alignItems: 'center',
Expand All @@ -30,7 +30,7 @@ export default function HoverRating() {
const classes = useStyles();

return (
<div className={classes.rating}>
<div className={classes.root}>
<Rating
name="hover-feedback"
value={value}
Expand Down
20 changes: 16 additions & 4 deletions docs/src/pages/components/rating/RatingSize.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
import React from 'react';
import Box from '@material-ui/core/Box';
import Rating from '@material-ui/lab/Rating';
import { makeStyles } from '@material-ui/core/styles';

const useStyles = makeStyles(theme => ({
root: {
display: 'flex',
flexDirection: 'column',
'& > * + *': {
marginTop: theme.spacing(1),
},
},
}));

export default function HalfRating() {
const classes = useStyles();

export default function RatingSize() {
return (
<Box display="flex" flexDirection="column">
<div className={classes.root}>
<Rating name="size-small" defaultValue={2} size="small" />
<Rating name="size-medium" defaultValue={2} />
<Rating name="size-large" defaultValue={2} size="large" />
</Box>
</div>
);
}
22 changes: 18 additions & 4 deletions docs/src/pages/components/rating/RatingSize.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
import React from 'react';
import Box from '@material-ui/core/Box';
import Rating from '@material-ui/lab/Rating';
import { makeStyles, Theme, createStyles } from '@material-ui/core/styles';

const useStyles = makeStyles((theme: Theme) =>
createStyles({
root: {
display: 'flex',
flexDirection: 'column',
'& > * + *': {
marginTop: theme.spacing(1),
},
},
}),
);

export default function HalfRating() {
const classes = useStyles();

export default function RatingSize() {
return (
<Box display="flex" flexDirection="column">
<div className={classes.root}>
<Rating name="size-small" defaultValue={2} size="small" />
<Rating name="size-medium" defaultValue={2} />
<Rating name="size-large" defaultValue={2} size="large" />
</Box>
</div>
);
}
6 changes: 5 additions & 1 deletion packages/material-ui-lab/src/Rating/Rating.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,11 @@ const Rating = React.forwardRef(function Rating(props, ref) {
);

if (readOnly) {
return <React.Fragment key={state.value}>{container}</React.Fragment>;
return (
<span key={state.value} {...labelProps}>
{container}
</span>
);
}

return (
Expand Down