Blazor Rating Input
The Blazor Bootstrap RatingInput component lets users select or display a score using icons. The examples below cover read-only fractional values, custom icons, sizes, colors and disabled.
INFO
RatingInput renders Bootstrap Icons. Reference the Bootstrap Icons stylesheet in your app, because Blazor Bootstrap does not bundle it.
Basic usage #
RatingInput lets users pick a score by clicking an icon or using the arrow keys.
How to use:
This demo binds an
How to use:
- Add
RatingInputand setTValuetoint,int?,decimal, ordecimal?. - Bind the score with
@bind-Value. - Optionally set
MaxValueto change the number of icons (default 5). - Give the group an accessible name with
aria-labeloraria-labelledby.
int score out of 5.
Read-only fractional values #
Set
How to use:
This demo shows three read-only averages.
ReadOnly to display a score that users cannot change. Fractional values are shown to the nearest half, and assistive technology announces the exact value.
How to use:
- Set
ReadOnly="true". - Bind a
decimalvalue such as4.3m. - Expect the display to round to the nearest half: 4.3 shows 4½ and 4.2 shows 4.
Custom icons #
Replace the default stars with any Bootstrap icon.
How to use:
This demo uses hearts and circles.
How to use:
- Set
FilledIconNamefor selected items. - Set
EmptyIconNamefor unselected items. - Set
HalfIconNamefor half-filled items shown for fractional values.
Sizes #
Change the icon size with the
How to use:
This demo shows each size.
Size parameter.
How to use:
- Set
SizetoRatingInputSize.Small,RatingInputSize.Default, orRatingInputSize.Large.
Colors #
Change the icon color with the
How to use:
This demo shows the theme colors.
Color parameter. The default is RatingInputColor.Warning.
How to use:
- Set
Colorto aRatingInputColorvalue such asRatingInputColor.Primary. - Use
RatingInputColor.Noneto inherit the surrounding text color.
Disabled #
A disabled rating input cannot be focused or changed.
How to use:
This demo toggles the disabled state.
How to use:
- Set
Disabled="true".
Allow clear #
With
How to use:
This demo binds an
AllowClear, clicking the selected icon again clears the value.
How to use:
- Set
AllowClear="true". - Click the selected icon to clear it. The value becomes
nullfor nullable types and0otherwise.
int? value.
Allow half #
With
How to use:
This demo binds a
AllowHalf, users can select half values. This works only with decimal and decimal?; integer types throw an exception.
How to use:
- Set
TValuetodecimalordecimal?. - Set
AllowHalf="true". - Click the left half of an icon, or use the arrow keys, to select .5 values.
decimal value in half steps.
EditForm validation #
RatingInput takes part in
How to use:
This demo requires a score before the form can be submitted.
EditForm validation like other form inputs.
How to use:
- Place
RatingInputinside anEditFormwith aDataAnnotationsValidator. - Bind a model property with
@bind-Value. - Add a
ValidationMessagefor the property.
Events: ValueChanged #
ValueChanged fires once for each change made by the user, and never when the component is read-only or disabled.
How to use:
- Set
Valueand handleValueChanged. - Update your field in the handler.