Skip to content

Commit

Permalink
[Rating] Add random name when none is provided (mui#18284)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitao18 authored and oliviertassinari committed Nov 10, 2019
1 parent a71aca8 commit 29f20ea
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions docs/src/modules/components/DiamondSponsors.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export default function DiamondSponsors() {
{t('diamondSponsors')}
</Typography>
<a
aria-label={t('diamondSponsors')}
className={classes.placeholder}
rel="noopener noreferrer"
target="_blank"
Expand Down
2 changes: 1 addition & 1 deletion docs/src/pages/components/rating/HoverRating.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function IconContainer(props) {
const { value, ...other } = props;
return (
<Tooltip title={labels[value] || ''}>
<div {...other} />
<span {...other} />
</Tooltip>
);
}
Expand Down
2 changes: 1 addition & 1 deletion docs/src/pages/components/rating/HoverRating.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function IconContainer(props: IconContainerProps) {
const { value, ...other } = props;
return (
<Tooltip title={labels[value] || ''}>
<div {...other} />
<span {...other} />
</Tooltip>
);
}
Expand Down
2 changes: 1 addition & 1 deletion docs/src/pages/components/rating/SimpleRating.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default function SimpleRating() {
</Box>
<Box component="fieldset" mb={3} borderColor="transparent">
<Typography component="legend">Read only</Typography>
<Rating value={value} readOnly />
<Rating name="read-only" value={value} readOnly />
</Box>
<Box component="fieldset" mb={3} borderColor="transparent">
<Typography component="legend">Disabled</Typography>
Expand Down
2 changes: 1 addition & 1 deletion docs/src/pages/components/rating/SimpleRating.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default function SimpleRating() {
</Box>
<Box component="fieldset" mb={3} borderColor="transparent">
<Typography component="legend">Read only</Typography>
<Rating value={value} readOnly />
<Rating name="read-only" value={value} readOnly />
</Box>
<Box component="fieldset" mb={3} borderColor="transparent">
<Typography component="legend">Disabled</Typography>
Expand Down
12 changes: 11 additions & 1 deletion packages/material-ui-lab/src/Rating/Rating.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export const styles = theme => ({
clip: 'rect(0 0 0 0)',
height: 1,
margin: -1,
color: '#000',
overflow: 'hidden',
padding: 0,
position: 'absolute',
Expand Down Expand Up @@ -136,7 +137,7 @@ const Rating = React.forwardRef(function Rating(props, ref) {
icon = defaultIcon,
IconContainerComponent = IconContainer,
max = 5,
name,
name: nameProp,
onChange,
onChangeActive,
onMouseLeave,
Expand All @@ -148,6 +149,15 @@ const Rating = React.forwardRef(function Rating(props, ref) {
...other
} = props;

const [defaultName, setDefaultName] = React.useState();
const name = nameProp || defaultName;
React.useEffect(() => {
// Fallback to this default id when possible.
// Use the random value for client-side rendering only.
// We can't use it server-side.
setDefaultName(`mui-rating-${Math.round(Math.random() * 1e5)}`);
}, []);

const valueProp = roundValueToPrecision(valueProp2, precision);
const theme = useTheme();
const [{ hover, focus }, setState] = React.useState({
Expand Down

0 comments on commit 29f20ea

Please sign in to comment.