Accent color
# Rating
## Description
Ratings show people’s opinions of a product, helping others make more informed purchasing decisions. People can also rate products they’ve purchased.
## Parameters
| Name | Type | Default Value | Description |
| :--- | :--- | :------------ | :---------- |
| AllowZeroStars | `bool` | false | Allow the initial rating value be 0. Note that a value of 0 still won't be selectable by mouse or keyboard. |
| AriaLabelFormat | `string?` | null | Optional label format for each individual rating star (not the rating control as a whole) that will be read by screen readers. |
| Classes | `BitRatingClassStyles?` | null | Custom CSS classes for different parts of the BitRating. |
| GetAriaLabel | `Func<double, double, string>?` | null | Optional callback to set the aria-label for rating control in readOnly mode. Also used as a fallback aria-label if ariaLabel prop is not provided. |
| Max | `int` | 5 | Maximum rating. Must be >= min (0 if AllowZeroStars is true, 1 otherwise). |
| SelectedIcon | `BitIconInfo?` | null | Icon for selected rating elements using external icon libraries (e.g. FontAwesome, Bootstrap Icons). Takes precedence over SelectedIconName when both are set. |
| SelectedIconName | `string?` | FavoriteStarFill | Custom icon name for selected rating elements (Fluent UI). For external icon libraries, use SelectedIcon instead. |
| Size | `BitSize?` | null | Size of rating elements. |
| Styles | `BitRatingClassStyles?` | null | Custom CSS styles for different parts of the BitRating. |
| UnselectedIcon | `BitIconInfo?` | null | Icon for unselected rating elements using external icon libraries (e.g. FontAwesome, Bootstrap Icons). Takes precedence over UnselectedIconName when both are set. |
| UnselectedIconName | `string?` | FavoriteStar | Custom icon name for unselected rating elements (Fluent UI). For external icon libraries, use UnselectedIcon instead. |
| DefaultValue | `TValue?` | null | The default value of the input to be used in uncontrolled mode (i.e. when the Value is not bound), typically used alongside the OnChange callback. |
| DisplayName | `string?` | null | Gets or sets the display name for this field. |
| InputHtmlAttributes | `IReadOnlyDictionary<string, object>?` | null | Gets or sets a collection of additional attributes that will be applied to the created element. |
| Name | `string?` | null | Gets or sets the name of the element. Allows access by name from the associated form. |
| NoValidate | `bool` | false | Disables the validation of the input. |
| OnChange | `EventCallback<TValue?>` | | Callback for when the input value changes. |
| ReadOnly | `bool` | false | Makes the input read-only. |
| Required | `bool` | false | Makes the input required. |
| Value | `TValue?` | null | Gets or sets the value of the input. This should be used with two-way binding. |
| AriaLabel | `string?` | null | Gets or sets the accessible label for the component, used by assistive technologies. |
| Class | `string?` | null | Gets or sets the CSS class name(s) to apply to the rendered element. |
| Dir | `BitDir?` | null | Gets or sets the text directionality for the component's content. |
| ForceAnimation | `bool` | false | Gets or sets a value indicating whether the component's animations play at their full duration even when reduced motion is requested. |
| HtmlAttributes | `Dictionary<string, object>` | new Dictionary<string, object>() | Captures additional HTML attributes to be applied to the rendered element, in addition to the component's parameters. |
| Id | `string?` | null | Gets or sets the unique identifier for the component's root element. |
| IsEnabled | `bool` | true | Gets or sets a value indicating whether the component is enabled and can respond to user interaction. |
| Style | `string?` | null | Gets or sets the CSS style string to apply to the rendered element. |
| TabIndex | `string?` | null | Gets or sets the tab order index for the component when navigating with the keyboard. |
| Visibility | `BitVisibility` | BitVisibility.Visible | Gets or sets the visibility state (visible, hidden, or collapsed) of the component. |
## Public Members
| Name | Type | Default Value | Description |
| :--- | :--- | :------------ | :---------- |
| InputElement | `ElementReference` | | The ElementReference of the input element. |
| FocusAsync() | `() => ValueTask` | | Gives focus to the input element. |
| FocusAsync(bool preventScroll) | `(bool preventScroll) => ValueTask` | | Gives focus to the input element. |
| UniqueId | `Guid` | Guid.NewGuid() | Gets the readonly unique identifier for the component's root element, assigned when the component instance is constructed. |
| RootElement | `ElementReference` | | Gets the reference to the root HTML element associated with this component. |
## Enums
### BitSize Enum
| Name | Value | Description |
| :--- | :--- | :---------- |
| Small | 0 | Display rating icon using small size. |
| Medium | 1 | Display rating icon using medium size. |
| Large | 2 | Display rating icon using large size. |
### BitVisibility Enum
| Name | Value | Description |
| :--- | :--- | :---------- |
| Visible | 0 | The content of the component is visible. |
| Hidden | 1 | The content of the component is hidden, but the space it takes on the page remains (visibility:hidden). |
| Collapsed | 2 | The component is hidden (display:none). |
### BitDir Enum
| Name | Value | Description |
| :--- | :--- | :---------- |
| Ltr | 0 | Ltr (left to right) is to be used for languages that are written from the left to the right (like English). |
| Rtl | 1 | Rtl (right to left) is to be used for languages that are written from the right to the left (like Arabic). |
| Auto | 2 | Auto lets the user agent decide. It uses a basic algorithm as it parses the characters inside the element until it finds a character with a strong directionality, then applies that directionality to the whole element. |
## Sub Classes
### BitRatingClassStyles Properties
| Name | Type | Default Value | Description |
| :--- | :--- | :------------ | :---------- |
| Root | `string?` | null | Custom CSS classes/styles for the root element of the rating. |
| Button | `string?` | null | Custom CSS classes/styles for the rating's button. |
| IconContainer | `string?` | null | Custom CSS classes/styles for the rating icon container. |
| SelectedIcon | `string?` | null | Custom CSS classes/styles for the rating selected icon. |
| UnselectedIcon | `string?` | null | Custom CSS classes/styles for the rating unselected icon. |
### BitIconInfo Properties
Represents icon information for rendering icons. Supports built-in Fluent UI icons and external icon libraries (FontAwesome, Bootstrap Icons, etc.). Use BitIconInfo.Css("fa-solid fa-star"), BitIconInfo.Fa("solid star"), or BitIconInfo.Bi("star-fill") for external icons.
| Name | Type | Default Value | Description |
| :--- | :--- | :------------ | :---------- |
| Name | `string?` | null | Gets or sets the name of the icon. |
| BaseClass | `string?` | null | Gets or sets the base CSS class for the icon. For external icon libraries like FontAwesome, you might set this to "fa" or leave empty. |
| Prefix | `string?` | null | Gets or sets the CSS class prefix used before the icon name. For external icon libraries, you might set this to "fa-" or leave empty. |
## Examples
\n**Basic**:
```razor
```
\n**Visibility**:
```razor
Visible: [ ]
Hidden: [ ]
Collapsed: [ ]
```
\n**Style & Class**:
```razor
```
\n**Max value**:
```razor
```
\n**Icons**:
```razor
```
\n**Size**:
```razor
```
\n**Binding**:
```razor
Changed Value: @onChangeValue
```
```csharp
private double oneWayBinding = 0;
private double twoWayBinding = 3;
private double onChangeValue;
```
\n**Validation**:
```razor
Submit
```
```csharp
public class BitRatingDemoFormModel
{
[Range(typeof(double), "1", "5", ErrorMessage = "Your rate must be between {1} and {2}")]
public double Value { get; set; }
}
public BitRatingDemoFormModel ValidationModel = new();
private void HandleValidSubmit() { }
private void HandleInvalidSubmit() { }
```
\n**External Icons**:
```razor
```
\n**RTL**:
```razor
```