Showcase

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.
API Documentation
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:
  1. Add RatingInput and set TValue to int, int?, decimal, or decimal?.
  2. Bind the score with @bind-Value.
  3. Optionally set MaxValue to change the number of icons (default 5).
  4. Give the group an accessible name with aria-label or aria-labelledby.
This demo binds an int score out of 5.

Read-only fractional values #

Set 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:
  1. Set ReadOnly="true".
  2. Bind a decimal value such as 4.3m.
  3. Expect the display to round to the nearest half: 4.3 shows 4½ and 4.2 shows 4.
This demo shows three read-only averages.

Custom icons #

Replace the default stars with any Bootstrap icon.
How to use:
  1. Set FilledIconName for selected items.
  2. Set EmptyIconName for unselected items.
  3. Set HalfIconName for half-filled items shown for fractional values.
This demo uses hearts and circles.

Sizes #

Change the icon size with the Size parameter.
How to use:
  1. Set Size to RatingInputSize.Small, RatingInputSize.Default, or RatingInputSize.Large.
This demo shows each size.

Colors #

Change the icon color with the Color parameter. The default is RatingInputColor.Warning.
How to use:
  1. Set Color to a RatingInputColor value such as RatingInputColor.Primary.
  2. Use RatingInputColor.None to inherit the surrounding text color.
This demo shows the theme colors.

Disabled #

A disabled rating input cannot be focused or changed.
How to use:
  1. Set Disabled="true".
This demo toggles the disabled state.

Allow clear #

With AllowClear, clicking the selected icon again clears the value.
How to use:
  1. Set AllowClear="true".
  2. Click the selected icon to clear it. The value becomes null for nullable types and 0 otherwise.
This demo binds an int? value.

Allow half #

With AllowHalf, users can select half values. This works only with decimal and decimal?; integer types throw an exception.
How to use:
  1. Set TValue to decimal or decimal?.
  2. Set AllowHalf="true".
  3. Click the left half of an icon, or use the arrow keys, to select .5 values.
This demo binds a decimal value in half steps.

EditForm validation #

RatingInput takes part in EditForm validation like other form inputs.
How to use:
  1. Place RatingInput inside an EditForm with a DataAnnotationsValidator.
  2. Bind a model property with @bind-Value.
  3. Add a ValidationMessage for the property.
This demo requires a score before the form can be submitted.

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:
  1. Set Value and handle ValueChanged.
  2. Update your field in the handler.
This demo logs each change.

Rejoining the server...

Rejoin failed... trying again in seconds.

Failed to rejoin.
Please retry or reload the page.

The session has been paused by the server.

Failed to resume the session.
Please reload the page.