Rating
A rating lets users give a value to an item by selecting one of a row of stars. It supports half-filled stars, four sizes and a custom number of items.
Usage
<script>
import { Rating } from 'fluentui-svelte';
let value = $state(3);
</script>
<Rating bind:value /> Bind the value
Use bind:value to read the rating the user picks.
3
Half stars
Set step to 0.5 to let users pick half-filled stars.
Quarter stars
Until the user rates, a fractional value is drawn in quarters, which is handy to show an average. Once the user picks a star, the rating snaps to the step.
Size
Use size to choose between small, medium, large and extra-large.
Shape
Use iconFilled and iconOutline to replace the stars with any other icon component. Both fall back to the star when omitted, and partially filled items are clipped, so custom shapes also work with a step of 0.5.
Max
Use max to change the number of stars.
Item label
Use itemLabel to customize the accessible label of each radio input.
Component Props
| Name | Type | Default | Description |
|---|---|---|---|
value bindable | number | 0 | The current rating. Fractions are drawn in quarters until the user rates. |
max | number | 5 | The number of items displayed. Must be a whole number greater than 1. |
step | 1 | 0.5 | 1 | The precision of the rating. 0.5 allows half-filled items. |
size | 'small' | 'medium' | 'large' | 'extra-large' | 'extra-large' | The size of the rating items. |
iconFilled | Component | The icon of a filled item. Falls back to a filled star. Partially filled items are clipped, so it also works with half steps. | |
iconOutline | Component | The icon of an empty item. Falls back to an outlined star. | |
itemLabel | (rating: number) => string | (rating) => `${rating}` | Generates the accessible label of the radio input for a rating value. |
onChange | (value: number) => void | Called when the user changes the rating. | |
wrapperRef bindable | HTMLDivElement | null | The DOM reference of the radiogroup element. | |
wrapperAttributes | HTMLAttributes | The attributes to spread on the radiogroup element. This is where its aria-label, aria-labelledby, aria-invalid, id and class go. | |
HTMLInputAttributes without type, value, checked, max, step, size, style, aria-label, aria-invalid, children |

