packages/react-components/react-rating/library/docs/Spec.md
A Rating component allows users to provide a rating for a particular item.
This component displays a set of stars or other symbols that represent the rating value. Users can interact with the component to select a rating by clicking on the stars or using touch gestures.
The existing components are:
Rating| Component | Purpose |
|---|---|
Rating | Displays interactive RatingItems. |
RatingDisplay | Displays read only RatingItems and value and count labels |
RatingItem | Represents a single rating item. |
root - The root element of the Rating. The default HTML element is a div.root - The root element of the RatingDisplay. The default HTML element is a div.valueText - The slot that renders the value of the RatingDisplay. The default HTML element is a span.countText - The slot that renders a figure representing the total number of ratings. The default HTML element is a span.root - The root element of the RatingItem. The default element is a span.selectedIcon - The icon displayed when the rating value is greater than or equal to the item's value. The default element is a div.unselectedIcon - The icon displayed when the rating value is less than the item's value. The default element is a div.halfValueInput - The Radio input slot used for half star precision. The default element is an input.fullValueInput - The Radio input slot used for full star precision. The default element is an input.Basic Rating example. This will render an interactive Rating with 5 stars:
import { Rating } from '@fluentui/react-components';
function App() {
return <Rating />;
}
Basic RatingDisplay example. This will render a read only RatingDisplay with 5 stars:
import { RatingDisplay } from '@fluentui/react-components';
function App() {
return <RatingDisplay />;
}
Basic RatingItem example. This will render a standalone RatingItem. It is recommended to be used inside a Rating or RatingDisplay:
import { RatingItem } from '@fluentui/react-components';
function App() {
return <RatingItem />;
}
Basic Rating structure.
<!-- Container for Rating -->
<div class="fui-Rating">
<!-- Container for RatingItem -->
<span class="fui-RatingItem">
<!-- Input slot -->
<input />
<!-- Icon slot -->
<div class="fui-RatingItem">
<svg>...</svg>
</div>
</span>
</div>
Basic RatingDisplay structure.
<!-- Container for RatingDisplay -->
<div class="fui-RatingDisplay">
<!-- Container for RatingItem -->
<span class="fui-RatingItem">
<!-- Icon slot -->
<div class="fui-RatingItem">
<svg>...</svg>
</div>
</span>
<!--Value label slot-->
<span>...</span>
<!-- Count label slot -->
<span>...</span>
</div>
See MIGRATION.md.
Display - Rating will be used to render 5 or more interactive RatingItems, while RatingDisplay will be used to render non-interactive RatingItems.
color prop controls the color of a Rating or RatingDisplaymax prop sets how many RatingItems there are in the Rating or RatingDisplaysize prop will allow the user to specify the size of the element.iconFilled and iconOutline slots to render custom RatingItems.RatingDisplay, you can pass in filled icons to the icon prop to render custom RatingItems.The Rating can be interactive or non-iteractive depending on the use case
Keyboard - Can use arrow keys.
Mouse
RatingItemRatingItemTouch
RatingItemroot slot role is radiogroup and the RatingItems input slots' roles are radio.name prop to associate all RatingItems with a specific Rating. If a name is not provided, one is generated for that Rating.root slot role is set to img and all RatingItems have aria-hidden set to true.RatingDisplay has an arialabelledby prop pointing to the id of the countText slot or valueText slot.