Skip to content

Commit 29f20ea

Browse files
Vitao18oliviertassinari
authored andcommitted
[Rating] Add random name when none is provided (#18284)
1 parent a71aca8 commit 29f20ea

File tree

6 files changed

+16
-5
lines changed

6 files changed

+16
-5
lines changed

docs/src/modules/components/DiamondSponsors.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export default function DiamondSponsors() {
4444
{t('diamondSponsors')}
4545
</Typography>
4646
<a
47+
aria-label={t('diamondSponsors')}
4748
className={classes.placeholder}
4849
rel="noopener noreferrer"
4950
target="_blank"

docs/src/pages/components/rating/HoverRating.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function IconContainer(props) {
2323
const { value, ...other } = props;
2424
return (
2525
<Tooltip title={labels[value] || ''}>
26-
<div {...other} />
26+
<span {...other} />
2727
</Tooltip>
2828
);
2929
}

docs/src/pages/components/rating/HoverRating.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function IconContainer(props: IconContainerProps) {
2222
const { value, ...other } = props;
2323
return (
2424
<Tooltip title={labels[value] || ''}>
25-
<div {...other} />
25+
<span {...other} />
2626
</Tooltip>
2727
);
2828
}

docs/src/pages/components/rating/SimpleRating.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default function SimpleRating() {
2020
</Box>
2121
<Box component="fieldset" mb={3} borderColor="transparent">
2222
<Typography component="legend">Read only</Typography>
23-
<Rating value={value} readOnly />
23+
<Rating name="read-only" value={value} readOnly />
2424
</Box>
2525
<Box component="fieldset" mb={3} borderColor="transparent">
2626
<Typography component="legend">Disabled</Typography>

docs/src/pages/components/rating/SimpleRating.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default function SimpleRating() {
2020
</Box>
2121
<Box component="fieldset" mb={3} borderColor="transparent">
2222
<Typography component="legend">Read only</Typography>
23-
<Rating value={value} readOnly />
23+
<Rating name="read-only" value={value} readOnly />
2424
</Box>
2525
<Box component="fieldset" mb={3} borderColor="transparent">
2626
<Typography component="legend">Disabled</Typography>

packages/material-ui-lab/src/Rating/Rating.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export const styles = theme => ({
6464
clip: 'rect(0 0 0 0)',
6565
height: 1,
6666
margin: -1,
67+
color: '#000',
6768
overflow: 'hidden',
6869
padding: 0,
6970
position: 'absolute',
@@ -136,7 +137,7 @@ const Rating = React.forwardRef(function Rating(props, ref) {
136137
icon = defaultIcon,
137138
IconContainerComponent = IconContainer,
138139
max = 5,
139-
name,
140+
name: nameProp,
140141
onChange,
141142
onChangeActive,
142143
onMouseLeave,
@@ -148,6 +149,15 @@ const Rating = React.forwardRef(function Rating(props, ref) {
148149
...other
149150
} = props;
150151

152+
const [defaultName, setDefaultName] = React.useState();
153+
const name = nameProp || defaultName;
154+
React.useEffect(() => {
155+
// Fallback to this default id when possible.
156+
// Use the random value for client-side rendering only.
157+
// We can't use it server-side.
158+
setDefaultName(`mui-rating-${Math.round(Math.random() * 1e5)}`);
159+
}, []);
160+
151161
const valueProp = roundValueToPrecision(valueProp2, precision);
152162
const theme = useTheme();
153163
const [{ hover, focus }, setState] = React.useState({

0 commit comments

Comments
 (0)