Rating

A row of stars (or any icon) for a score from 1 to max, picked by pointer or keyboard, or shown read-only as an average.

  • vig-rating
Import
import { Rating } from '@vigdx/ui/rating';

Basic

Bind [(value)] to a number | null signal; null means not rated. Hovering previews a value without changing it.

Your rating

Value: 3

Half steps, clearing, icons and sizes

allowHalf picks half icons (the half under the pointer, from the inline start) and steps the arrows by 0.5. clearable clears the rating when the current value is picked again or Delete is pressed. max sets the number of icons, icon any registered glyph, size the scale ( sm , md , lg ).

Half steps

Clearable

Pick the current rating again, or press Delete, to clear it.

Out of ten

Favorite

Read-only, disabled and error

readonly shows a fixed rating, which may be fractional (an average fills part of an icon); it stays focusable and is announced, e.g. "3.7 of 5". Disabled ratings leave the tab order. Errors show once the field is touched and invalid.

Average (read-only)

From 128 reviews

Disabled

Required
Required

This field is required.

Signal Forms

vig-rating implements FormValueControl<number | null> . A schema max() sets the number of icons; other rules show their message once the rating is touched.

How was your stay?
Required

Valid: no · none

Reactive Forms

Import VigValueAccessor next to the component to use formControlName , [formControl] or ngModel .

Service
Required

4 · pristine

Styling hooks

Internal elements carry a stable data-part and the component's data-scope; both are public API, so removing one is a breaking change. Select a part by both, e.g. [data-scope="rating"][data-part="label"] { … }: the pair stays within this component when kit components nest, and also reaches parts in overlay panels, which render outside the host. State is exposed through aria-* and, where listed, a data-state; literal values are checked by the API gate, values computed from the component's state follow its documented types. Other data-* attributes listed below (such as data-opening while an overlay animates) are API too. See Customizing.

Scope: [data-scope="rating"]

Rating styling hooks
Part Element data-state
label The visible label ( aria-labelledby of the control). —
control The role="slider" row of icons; preview while a pointer hovers. preview
item One icon cell; its state is how much of the icon is filled. full, partial, empty
fill The solid copy of the icon, clipped to the filled share from the inline start. —
hint The vig-hint (a display: contents host; style its text part). —
disabled-reason The vig-hint with the disabled reason ( display: contents ). —
error The vig-field-error (a display: contents host; style its message part). —

Accessibility

  • One role="slider", as in the APG rating slider example, not a radio group: a single tab stop, half steps and clearing map onto one number (a radio group would need two radios per icon plus a "none" radio), and screen readers announce the value as "3 of 5" through aria-valuetext (labels.valueLabel), or "No rating" (labels.emptyLabel).
  • Right and Up raise the rating, Left and Down lower it (Left and Right swap under RTL), Page Up and Page Down move by a whole icon, Home and End jump to the lowest and highest rating. With clearable the slider's minimum is 0 ("No rating"): Home, stepping below the lowest rating, Delete and Backspace clear it; without it the minimum is the lowest rating.
  • Filled icons are solid, empty ones outlined in --color-border-control: the state reads from the shape, also in forced-colors mode, and both hold 3:1 against the page. The filled color is the --color-rating token.
  • Each icon cell is at least 24px (44px on touch screens). The hover preview is for mouse and pen only.
  • readonly keeps the rating focusable with aria-readonly. The slider role has no aria-required, so required adds a visually hidden "Required" to the description.

API

Rating

vig-rating component

A star rating: pick a whole (or, with allowHalf, half) number of icons out of max. clearable lets the user take the rating back by picking the current value again (or with Delete). readonly shows a fixed rating that is still announced ("3.5 of 5") and may be fractional, e.g. an average.

Example :
<vig-rating label="Your rating" [(value)]="stars" clearable />

It is one role="slider" (the APG rating slider): a single tab stop whose arrows step by one icon (or half), mirrored under RTL, Home and End jump to the ends; with clearable, Home and stepping below the lowest rating clear it. Pointers preview the value on hover. Works with Signal Forms and, through VigValueAccessor, with Reactive Forms and ngModel.

Rating props
Name Type Default Description
allowHalfbooleanfalse

Lets the user pick half icons; arrows then step by 0.5.

clearablebooleanfalse

Picking the current value again (or pressing Delete) clears the rating.

dirtybooleanfalse
—
disabledbooleanfalse
—
disabledReasonsreadonly WithOptionalFieldTree<DisabledReason>[][]
—
errorMessagesRecord<string, string>—
—
errorsreadonly ValidationError.WithOptionalFieldTree[][]
—
hiddenbooleanfalse
—
hideLabelbooleanfalse

Keeps the label for assistive tech only.

hintstring | undefinedundefined
—
iconstring'star'

Name of a registered vig-icon glyph; filled icons fill its outline.

invalidbooleanfalse
—
label required string—
—
labelsPartial<RatingLabels>—

Texts (i18n); locale defaults.

maxnumber | undefined5

The number of icons, the highest rating (default 5). number | undefined to match the FormValueControl contract, which binds a schema's max().

namestring''
—
pendingbooleanfalse
—
readonlybooleanfalse
—
requiredbooleanfalse
—
sizeFieldSize'md'
—
touchedbooleanfalse
—
value model number | nullnull

The rating, null while unrated.

Are you sure?