Skip to content

Commit

Permalink
[Rating] Fix readOnly + precision combination (#19414)
Browse files Browse the repository at this point in the history
  • Loading branch information
TommyJackson85 authored Jan 30, 2020
1 parent 95d9c78 commit 7e97de3
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 15 deletions.
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

0 comments on commit 7e97de3

Please sign in to comment.