0 Tk

rating

Import

import Rating from '@mui/material/Rating';
// or
import { Rating } from '@mui/material';

Learn about the difference by reading this guide on minimizing bundle size.

Props of the native component are also available.

Name Type Default Description
classes object - Override or extend the styles applied to the component. See CSS classes API below for more details.
component elementType - The component used for the root node. Either a string to use a HTML element or a component.
defaultValue number null The default value. Use when the component is not controlled.
disabled bool false If true, the component is disabled.
emptyIcon node <StarBorder fontSize="inherit" /> The icon to display when empty.
emptyLabelText node ‘Empty’ The label read when the rating input is empty.
getLabelText func function defaultLabelText(value) { return \${value
highlightSelectedOnly bool false If true, only the selected icon will be highlighted.
icon node <Star fontSize="inherit" /> The icon to display.
IconContainerComponent elementType function IconContainer(props) { const { value, ...other } = props; return <span {...other} />; } The component containing the icon.
max number 5 Maximum rating.
name string - The name attribute of the radio input elements. This input name should be unique within the page.
onChange func - Callback fired when the value changes.
onChangeActive func - Callback function that is fired when the hover state changes.
precision number 1 The minimum increment value change allowed.
readOnly bool false Removes all hover effects and pointer events.
size ‘small’ | ‘medium’ | ‘large’ | string ‘medium’ The size of the component.
sx Array<func | object | bool> | func | object - The system prop that allows defining system overrides as well as additional CSS styles.
value number - The rating value.

The ref is forwarded to the root element.

Theme default props

You can use MuiRating to change the default props of this component with the theme.

These class names are useful for styling with CSS. They are applied to the component’s slots when specific states are triggered.

Class name Rule name Description
.Mui-disabled - State class applied to the root element if disabled={true}.
.Mui-focusVisible - State class applied to the root element if keyboard focused.
.Mui-readOnly - Styles applied to the root element if readOnly={true}.
.MuiRating-decimal decimal Styles applied to the icon wrapping elements when decimals are necessary.
.MuiRating-icon icon Styles applied to the icon wrapping elements.
.MuiRating-iconActive iconActive Styles applied to the icon wrapping elements when active.
.MuiRating-iconEmpty iconEmpty Styles applied to the icon wrapping elements when empty.
.MuiRating-iconFilled iconFilled Styles applied to the icon wrapping elements when filled.
.MuiRating-iconFocus iconFocus Styles applied to the icon wrapping elements when focus.
.MuiRating-iconHover iconHover Styles applied to the icon wrapping elements when hover.
.MuiRating-label label Styles applied to the label elements.
.MuiRating-labelEmptyValueActive labelEmptyValueActive Styles applied to the label of the “no value” input when it is active.
.MuiRating-root root Styles applied to the root element.
.MuiRating-sizeLarge sizeLarge Styles applied to the root element if size="large".
.MuiRating-sizeMedium sizeMedium Styles applied to the root element if size="medium".
.MuiRating-sizeSmall sizeSmall Styles applied to the root element if size="small".
.MuiRating-visuallyHidden visuallyHidden Visually hide an element.

You can override the style of the component using one of these customization options:

Source code

If you did not find the information in this page, consider having a look at the implementation of the component for more detail.