Forms
TwRating
TwRating is a Blazor star rating component. Bind Value, set Min and Max, rate in whole or half steps and swap in any icon.
Last updated
Please be aware this component is new, may have bugs and/or be subject to change. Please report any bugs at
https://github.com/twblazor/twblazor/issues.
Basic usage
Bind
Value with @bind-Value. The rating is a group of native radio inputs, so it is one Tab stop and the arrow keys change the value.You rated it 4 out of 5.
Whole and half steps
The type of
T sets the precision: an integer rates in whole icons, while double, decimal or float rate in half icons. Hover over the first half of an icon to pick the half.Value: 3
Value: 3.5
Rounding
A value between steps is displayed rounded to the nearest half, or whole, icon. Set
Rounding to change how: AwayFromZero (the default) rounds to the nearest, ToNegativeInfinity always rounds down and ToPositiveInfinity always rounds up. The bound value is never rewritten.Rated 3.5 out of 5
Rated 3.5 out of 5
Rated 4 out of 5
Icons and colors
Any
Icon works: a half step clips the filled icon to half its width. Set EmptyIcon to an outline icon to give unfilled steps a different shape as well as a different color, and Color to change the fill.Sizes
Use
Size to pick small, medium (the default) or large icons.Min & max
Max sets the number of icons. Min is the lowest value that can be picked: while it is 0 the rating can be cleared by clicking the selected icon again, or by choosing No rating from the keyboard.Value: 7 / 10
Value: 1
Animation
Hovering grows an icon slightly and picking a value makes the newly filled icons pop. Set
DisableAnimation to turn both off. They are always off for anyone whose system asks for reduced motion.Disabled & readonly
Disabled dims the rating and locks it. ReadOnly keeps its colors and is announced as a single image, such as "Rated 4.5 out of 5", which suits showing a review score.Rated 4.5 out of 5
Validation
Set
Invalid and ErrorMessage to show an error. The message is tied to the group with aria-describedby, so screen readers read it with the rating.Please pick a rating.
Theme configuration
Styling is controlled by
TwBlazorTheme.Components (a TwRatingTheme), configured via the
AddTwBlazor() options callback described on the Get Started page.
Every property is a set of Tailwind classes, so changes are picked up by your own Tailwind build.
| Property | Type | Controls |
|---|---|---|
Base |
string | |
EmptyFocusRing |
string | |
Item |
string | |
ItemFocusRing |
string | |
ItemHover |
string | |
Visual |
string | |
Empty |
string | |
Clip |
string | |
Filled |
string | |
Pop |
string | |
Input |
string | |
HalfTarget |
string | |
FullTarget |
string | |
Disabled |
string | |
Small |
string | |
Medium |
string | |
Large |
string |
Global Theme Configuration
These reuse shared design tokens configured once on
TwBlazorTheme, rather than being unique to this component.
| Property | Type | Controls |
|---|---|---|
Colors |
TwBlazorPalette |
Full reference: TwRatingTheme on the API docs.