Skip to content
navius

Rating

A star rating built on the WAI-ARIA radio pattern: a radiogroup of radio stars with roving focus, optional half values and pointer hover preview.

Value: 3.5

Features

  • A role="radiogroup" of role="radio" stars with roving tabindex; the value logic lives on the root, so arrows move focus and value together.
  • AllowHalf adds pointer half-zones and 0.5 keyboard steps; each star paints from data-state (full / half / empty), computed from the hover preview or the committed value.
  • AllowClear lets re-selecting the current value (or arrowing below 1) clear to unrated; Label supplies each star's accessible name.
  • Controlled via @bind-Value (a decimal?), uncontrolled via DefaultValue; a hidden input mirrors the value into form submission when Name is set.

Installation

Reference the Navius.Primitives package for the headless primitive, or vendor a styled version with the CLI: navius add copies the styled zits/ui component plus the brain files it depends on.

Anatomy

Provide your own star items, or let the root auto-render Max of them when you give it no children.

API Reference

NaviusRating. Owns the value, the keyboard model and the hover preview. Renders a div with role=radiogroup. Value is two-way bindable.

Prop Type Default
Value decimal? -
ValueChanged EventCallback<decimal?> -
DefaultValue decimal? -
Max int 5
AllowHalf bool false
AllowClear bool true
ReadOnly bool false
Disabled bool false
Required bool false
Invalid bool false
Name string? -
Label Func<decimal, string>? -
Dir string? -
ChildContent RenderFragment? -
…attributes IDictionary<string, object>? -
Data attribute Values
[data-navius-rating] Present on the group
[data-disabled] Present when disabled
[data-readonly] Present when read-only

NaviusRatingItem. One star; its index is assigned by registration order. Renders a button with role=radio (plus two aria-hidden half-zones under AllowHalf).

Prop Type Default
ChildContent RenderFragment? -
…attributes IDictionary<string, object>? -
Data attribute Values
[data-navius-rating-item] Present on each star
[data-state] "full" | "half" | "empty" (from hover preview or value)
[data-index] The 1-based star index
[data-value] The whole value this star selects
[data-checked] / [data-unchecked] Whether this star holds the value
[data-highlighted] Present while covered by a hover preview
[data-readonly] / [data-disabled] Mirrors the group state

Accessibility

Implements the radio group WAI-ARIA APG pattern with roving tabindex: only the checked star (or the first when unrated) is in the Tab order. The star holding a fractional value announces the real value (a 3.5 reads "3.5 stars"). The group is labelled "Rating" unless you supply an aria-label / aria-labelledby. This behavior is covered by the browser test suite and an axe-core WCAG gate in CI.

Key Description
Arrow Up / Arrow Right Raises the rating by one step (0.5 with AllowHalf; mirrored under rtl).
Arrow Down / Arrow Left Lowers the rating by one step, clearing below 1 when AllowClear.
Home / End Sets the rating to 1 / Max.
1-9 Jumps directly to that whole-star rating (capped at Max).
Backspace / Delete Clears to unrated when AllowClear.
Space / Enter Activates the focused star.