enes

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.

Form Control Attributes

The root is the control element. HTML attributes, class and ref apply to that element. There is no separate wrapper API.

Component Props

NameTypeDefaultDescription
value bindablenumber0The current rating. Fractions are drawn in quarters until the user rates.
maxnumber5The number of items displayed. Must be a whole number greater than 1.
step1 | 0.51The precision of the rating. 0.5 allows half-filled items.
size'small' | 'medium' | 'large' | 'extra-large''extra-large'The size of the rating items.
iconFilledComponentThe icon of a filled item. Falls back to a filled star. Partially filled items are clipped, so it also works with half steps.
iconOutlineComponentThe 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) => voidCalled when the user changes the rating.
wrapperRef bindableHTMLDivElement | nullThe DOM reference of the radiogroup element.
wrapperAttributesHTMLAttributesThe 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
Edit this Doc View as Markdown