Rating API
The API documentation of the Rating React component. Learn more about the properties and the CSS customization points.
import Rating from '@material-ui/lab/Rating';
Props
Name | Type | Default | Description |
---|---|---|---|
classes | object | Override or extend the styles applied to the component. See CSS API below for more details. | |
disabled | bool | false | If true , the rating will be disabled. |
emptyIcon | node | The icon to display when empty. | |
getLabelText | func | function defaultLabelText(value) { return ${value} Star${value !== 1 ? 's' : ''} ;} |
Accepts a function which returns a string value that provides a user-friendly name for the current value of the rating. Signature: function(value: number) => void value: The rating label's value to format |
icon | node | <Star fontSize="inherit" /> | The icon to display. |
IconContainerComponent | elementType | function IconContainer(props) { const { value, ...other } = props; return <div {...other} />;} | The component containing the icon. |
max | number | 5 | Maximum rating. |
name | string | Name attribute of the radio input elements. |
|
onChange | func | Callback fired when the value changes. Signature: function(event: object, value: number) => void event: The event source of the callback value: The new value |
|
onChangeActive | func | Callback function that is fired when the hover state changes. Signature: function(event: object, value: any) => void event: The event source of the callback value: The new value |
|
precision | number | 1 | The minimum increment value change allowed. |
readOnly | bool | false | Removes all hover effects and pointer events. |
size | enum: 'small' | 'medium' | 'large' |
'medium' | The size of the rating. |
value | number | null | The rating value. |
The ref
is forwarded to the root element.
Any other properties supplied will be provided to the root element (native element).
CSS
You can override all the class names injected by Material-UI thanks to the classes
property.
This property accepts the following keys:
Name | Description |
---|---|
root | Styles applied to the root element. |
sizeSmall | Styles applied to the root element if size="small" . |
sizeLarge | Styles applied to the root element if size="large" . |
readOnly | Styles applied to the root element if readOnly={true} . |
disabled | Pseudo-class applied to the root element if disabled={true} . |
focusVisible | Pseudo-class applied to the root element if keyboard focused. |
visuallyhidden | Visually hide an element. |
pristine | Styles applied to the pristine label. |
label | Styles applied to the label elements. |
icon | Styles applied to the icon wrapping elements. |
iconEmpty | Styles applied to the icon wrapping elements when empty. |
iconFilled | Styles applied to the icon wrapping elements when filled. |
iconHover | Styles applied to the icon wrapping elements when hover. |
iconFocus | Styles applied to the icon wrapping elements when focus. |
iconActive | Styles applied to the icon wrapping elements when active. |
decimal | Styles applied to the icon wrapping elements when decimals are necessary. |
Have a look at the overriding styles with classes section and the implementation of the component for more detail.
If using the overrides
key of the theme,
you need to use the following style sheet name: MuiRating
.
Notes
The component is fully StrictMode compatible.