Rating

Rate something with stars, in whole or half steps.

Installation

Import the class, and @use the entry point in your global styles: without it the component renders unstyled.

import { Component } from '@angular/core';
import { WrRating } from 'ngwr/rating';

@Component({ imports: [WrRating] })
export class MyComponent {}

Basic

Bind a number | null with [(value)] or any Angular form.

<wr-rating [(value)]="score" />

Half stars

step="0.5" allows half stars.

<wr-rating [(value)]="score" step="0.5" />

Custom count

count sets the number of stars.

<wr-rating [(value)]="score" [count]="10" />

Read-only

Shows a rating that cannot be changed.

<wr-rating [value]="4.5" step="0.5" [readonly]="true" />

Keyboard

Arrows move one step, Home / End jump to 0 and the maximum, Delete / Backspace clears.

Gotchas

  • A value above count is drawn as full stars but stays in the model. Flag it with a max() rule.

API

NameDescriptionTypeDefault
countTotal number of slots.number5
stepStep granularity — 1 for whole stars, 0.5 for halves.0.5 | 11
readonlyRead-only — value is displayed but not interactive.booleanfalse
disabledDisable interaction. Bound automatically from the field's disabled state when used with [formField].booleanfalse
sizeControl size — scales the icons + gaps.WrRatingSize'md'
ariaLabelAccessible label. Falls back to rating.label, then 'Rating'.string | nullnull
valueThe rating. Bound by [formField], or two-way via [(value)].number | nullnull
(touch)Emitted on blur so a bound field can mark itself touched.void—

CSS variables

Set these on the component's selector or a wrapper, not on :root: the defaults are declared on ngwr/rating's own element.

VariableDefaultDeclared on
--wr-rating-emptyvar(--wr-border-base).wr-rating
--wr-rating-filledvar(--wr-color-warning, #ffba00).wr-rating
--wr-rating-font-familyvar(--wr-font-family-base).wr-rating
--wr-rating-gap0.125rem.wr-rating +2 variant overrides
--wr-rating-row-radiusvar(--wr-border-radius-sm).wr-rating__row
--wr-rating-size1.25rem.wr-rating +2 variant overrides

Dependencies

Built onForm

See also