Rating
Choose or display a numeric rating, including precision and read-only states.
This guide covers Material UI Core with the default Emotion engine; extensions and additional demos are explicitly classified.
Use case and business boundary
Ratings can be null; no score is submitted or persisted by the control itself.
Native composition and scope
Rating
Preserve native Material UI composition and types; do not substitute JGuang UI/Base UI/Radix APIs. Example entries are not extra components.
Native installation and initialization
npm install @mui/material@9.4.0 @emotion/react@11.14.0 @emotion/styled@11.14.1
Use native npm and Emotion, not an invented JGuang UI Registry URL. Place examples inside native ThemeProvider; choose CssBaseline or ScopedCssBaseline for the project. Inspect React, existing providers, lockfile and SSR first. Never overwrite files or conceal peer conflicts. This batch verified React 19.2.8; React 18 and below require matching react-is. See the included bilingual setup guide.
Practical native parameters
These selected parameters are not a flattened universal API. Preserve the native declaring owner, slot structure, nullable values and generics.
| Owner.prop | Practical role | Declaration source |
|---|---|---|
Rating.value | Controlled native value; its scalar/array/nullable type is owner-specific. | Rating |
Rating.precision | Rating value step, including supported fractional ratings. | Rating |
Rating.readOnly | Native read-only state; distinguish it from disabled. | Rating |
Rating.onChange | Owning control's native callback; preserve its exact event/value/nullable signature. | Rating |
Rating.getLabelText | Format accessible labels for native rating values. | Rating |
Runnable native examples
Machine keys select example entries, not universal variant props. Native demo JSX/data stay unchanged; JGuang-authored acceptance fixtures are explicitly labelled.
- Basic rating ·
BasicRating· upstream native demo - Rating precision ·
HalfRating· upstream native demo - Hover feedback ·
HoverRating· upstream native demo - Sizes ·
RatingSize· upstream native demo - Customization ·
CustomizedRating· upstream native demo - Radio group ·
RadioGroupRating· upstream native demo - Accessibility ·
TextRating· upstream native demo
Actual usage example
Unmodified pinned native demo; copy its required local helper files together.
import * as React from 'react';
import Box from '@mui/material/Box';
import Rating from '@mui/material/Rating';
import Typography from '@mui/material/Typography';
export default function BasicRating() {
const [value, setValue] = React.useState<number | null>(2);
return (
<Box sx={{ '& > legend': { mt: 2 } }}>
<Typography component="legend">Controlled</Typography>
<Rating
name="simple-controlled"
value={value}
onChange={(event, newValue) => {
setValue(newValue);
}}
/>
<Typography component="legend">Uncontrolled</Typography>
<Rating
name="simple-uncontrolled"
onChange={(event, newValue) => {
console.log(newValue);
}}
defaultValue={2}
/>
<Typography component="legend">Read only</Typography>
<Rating name="read-only" value={value} readOnly />
<Typography component="legend">Disabled</Typography>
<Rating name="disabled" value={value} disabled />
<Typography component="legend">No rating given</Typography>
<Rating name="no-value" value={null} />
</Box>
);
}
Example dependency boundaries
react, @mui/material/Box, @mui/material/Rating, @mui/material/Typography, @mui/material/Stack, @mui/icons-material/Star, @mui/material/styles, @mui/icons-material/Favorite, @mui/icons-material/FavoriteBorder, @mui/icons-material/SentimentVeryDissatisfied, @mui/icons-material/SentimentDissatisfied, @mui/icons-material/SentimentSatisfied, @mui/icons-material/SentimentSatisfiedAltOutlined, @mui/icons-material/SentimentVerySatisfied
Direct Icons/System/Utils example imports require their matching 9.4.0 packages. Relative data/helpers are part of the example closure, not extra components. Remote images and simulated operations do not supply a backend.
Pinned upstream API metadata reference
These tables retain the upstream metadata, not a newly inferred generic type system. Conditional generics, inherited props and callback details are defined by the source declarations below. Theme defaults may override metadata defaults.
Rating
import Rating from '@mui/material/Rating';
import { Rating } from '@mui/material';
| Prop | Required | Upstream metadata type / constraint | Metadata default |
|---|---|---|---|
classes | no | object | — |
component | no | elementType | — |
defaultValue | no | number | null |
disabled | no | bool | false |
emptyIcon | no | node | <StarBorder fontSize="inherit" /> |
emptyLabelText | no | node | 'Empty' |
getLabelText | no | func | function defaultLabelText(value) { return ${value || '0'} Star${value !== 1 ? 's' : ''}; } |
highlightSelectedOnly | no | bool | false |
icon | no | node | <Star fontSize="inherit" /> |
max | no | number | 5 |
name | no | string | — |
onChange | no | func | — |
onChangeActive | no | func | — |
precision | no | number | 1 |
readOnly | no | bool | false |
size | no | 'small' | 'medium' | 'large' | string | 'medium' |
slotProps | no | { decimal?: func | object, icon?: func | object, label?: func | object, root?: func | object } | {} |
slots | no | { decimal?: elementType, icon?: elementType, label?: elementType, root?: elementType } | {} |
sx | no | Array<func | object | bool> | func | object | — |
value | no | number | — |
Native source declarations
Declarations/imports are extracted from pinned source without flattening unions or external inheritance. Original English comments/types are source reference, not a claim of translated upstream prose. Shared types stay in their native packages.
vendor/src/Rating/Rating.d.ts
import * as React from 'react';
import { SxProps } from '@mui/system';
import { OverridableStringUnion } from '@mui/types';
import { Theme } from '../styles';
import { RatingClasses } from './ratingClasses';
import { OverridableComponent, OverrideProps } from '../OverridableComponent';
import { CreateSlotsAndSlotProps, SlotProps } from '../utils/types';
export interface IconContainerProps extends React.HTMLAttributes<HTMLSpanElement> {
value: number;
}
export interface RatingPropsSizeOverrides {}
export interface RatingRootSlotPropsOverrides {}
export interface RatingLabelSlotPropsOverrides {}
export interface RatingIconSlotPropsOverrides {}
export interface RatingDecimalSlotPropsOverrides {}
export interface RatingSlots {
/**
* The component used for the root slot.
* @default 'span'
*/
root: React.ElementType;
/**
* The component used for the label slot.
* @default 'label'
*/
label: React.ElementType;
/**
* The component used for the icon slot.
* @default 'span'
*/
icon: React.ElementType;
/**
* The component used for the decimal slot.
* @default 'span'
*/
decimal: React.ElementType;
}
export type RatingSlotsAndSlotProps = CreateSlotsAndSlotProps<
RatingSlots,
{
/**
* Props forwarded to the root slot.
* By default, the available props are based on the span element.
*/
root: SlotProps<'span', RatingRootSlotPropsOverrides, RatingOwnerState>;
/**
* Props forwarded to the label slot.
* By default, the available props are based on the label element.
*/
label: SlotProps<'label', RatingLabelSlotPropsOverrides, RatingOwnerState>;
/**
* Props forwarded to the icon slot.
* By default, the available props are based on the span element.
*/
icon: SlotProps<'span', RatingIconSlotPropsOverrides, RatingOwnerState>;
/**
* Props forwarded to the decimal slot.
* By default, the available props are based on the span element.
*/
decimal: SlotProps<'span', RatingDecimalSlotPropsOverrides, RatingOwnerState>;
}
>;
export interface RatingOwnProps extends RatingSlotsAndSlotProps {
/**
* Override or extend the styles applied to the component.
*/
classes?: Partial<RatingClasses> | undefined;
/**
* The default value. Use when the component is not controlled.
* @default null
*/
defaultValue?: number | undefined;
/**
* If `true`, the component is disabled.
* @default false
*/
disabled?: boolean | undefined;
/**
* The icon to display when empty.
* @default <StarBorder fontSize="inherit" />
*/
emptyIcon?: React.ReactNode;
/**
* The label read when the rating input is empty.
* @default 'Empty'
*/
emptyLabelText?: React.ReactNode;
/**
* Accepts a function which returns a string value that provides a user-friendly name for the current value of the rating.
* This is important for screen reader users.
*
* For localization purposes, you can use the provided [translations](https://mui.com/material-ui/guides/localization/).
* @param {number} value The rating label's value to format.
* @returns {string}
* @default function defaultLabelText(value) {
* return `${value || '0'} Star${value !== 1 ? 's' : ''}`;
* }
*/
getLabelText?: ((value: number) => string) | undefined;
/**
* If `true`, only the selected icon will be highlighted.
* @default false
*/
highlightSelectedOnly?: boolean | undefined;
/**
* The icon to display.
* @default <Star fontSize="inherit" />
*/
icon?: React.ReactNode;
/**
* Maximum rating.
* @default 5
*/
max?: number | undefined;
/**
* The name attribute of the radio `input` elements.
* This input `name` should be unique within the page.
* Being unique within a form is insufficient since the `name` is used to generate IDs.
*/
name?: string | undefined;
/**
* Callback fired when the value changes.
* @param {React.SyntheticEvent} event The event source of the callback.
* @param {number|null} value The new value.
*/
onChange?: ((event: React.SyntheticEvent, value: number | null) => void) | undefined;
/**
* Callback function that is fired when the hover state changes.
* @param {React.SyntheticEvent} event The event source of the callback.
* @param {number} value The new value.
*/
onChangeActive?: ((event: React.SyntheticEvent, value: number) => void) | undefined;
/**
* The minimum increment value change allowed.
* @default 1
*/
precision?: number | undefined;
/**
* Removes all hover effects and pointer events.
* @default false
*/
readOnly?: boolean | undefined;
/**
* The size of the component.
* @default 'medium'
*/
size?: OverridableStringUnion<'small' | 'medium' | 'large', RatingPropsSizeOverrides> | undefined;
/**
* The system prop that allows defining system overrides as well as additional CSS styles.
*/
sx?: SxProps<Theme> | undefined;
/**
* The rating value.
*/
value?: number | null | undefined;
}
export interface RatingOwnerState extends Omit<RatingProps, 'slots' | 'slotProps'> {}
export type RatingTypeMap<
AdditionalProps = {},
RootComponent extends React.ElementType = 'span',
> = {
props: AdditionalProps & RatingOwnProps;
defaultComponent: RootComponent;
};
declare const Rating: OverridableComponent<RatingTypeMap>;
export type RatingProps<
RootComponent extends React.ElementType = RatingTypeMap['defaultComponent'],
AdditionalProps = {},
> = OverrideProps<RatingTypeMap<AdditionalProps, RootComponent>, RootComponent> & {
component?: React.ElementType | undefined;
};
Post-install acceptance
Run strict types, production build and real interactions. Check keyboard labels/focus, disabled/error/read-only semantics where natively supported, both themes, narrow screens and reduced motion. Verify callbacks against the real host data; do not declare installation complete from copying a prompt. Initialization fixtures also require server HTML and warning-free hydration.
Source and license
https://github.com/mui/material-ui/tree/809a7717b4c050ba3f69b75300689f07c050a16e
MIT · @mui/material@9.4.0. Vendor originals and license are preserved. Full original upstream prose remains in vendor/docs and is not represented as fully translated.