Rating

A score in stars, or any icon: one control, whole or half stars, read out by your words. Not rated is null — a Signal Forms field.

FormsExperimental

Usage

Usage

3 out of 5

import { Component, ViewEncapsulation, signal } from '@angular/core';import { ScRating, ScRatingIcon } from '@semantic-components/ui';import { SiStarIcon } from '@semantic-icons/lucide-icons';
/** A score out of five, read out by your value text; your icon, once: the rating draws the stars. */@Component({  selector: 'app-rating-usage-demo',  imports: [ScRating, ScRatingIcon, SiStarIcon],  template: `    <div class="flex flex-col items-center gap-2">

Anatomy

The rating holds the score, takes the focus and draws the stars: your icon, written once — for each star twice, empty and full, the full one drawn up to the star's fill.

import { ScRating, ScRatingIcon } from '@semantic-components/ui';
<div scRating [formField]="…" valueText="{value} out of {max} stars">  <ng-template scRatingIcon>    <svg siStarIcon></svg>  </ng-template></div>

Accessibility

  • WAI-ARIA's rating slider: one tab stop, a native range input out of sight (its focus ring on the stars). In a field it takes the field's id: the label ties to it by for. → and ↑ raise it by its step, ← and ↓ lower it (mirrored right to left), Home and End go to the lowest and highest scores. Deselectable, Delete takes the score back.
  • Read out by your valueText ("{value} out of {max} stars": "3.5 out of 5 stars"), named by its field's label or aria-label. The stars themselves are hidden from screen readers.
  • Read-only, it is an image named by its value text, for any score (4.2). The empty and full stars differ by fill, not only colour.
  • A hover previews (not on touch: a tap picks at once); a press on the left half of a star gives a half, with step 0.5.

Examples

Halves

3.5 out of 5

import { Component, ViewEncapsulation, signal } from '@angular/core';import { ScRating, ScRatingIcon } from '@semantic-components/ui';import { SiStarIcon } from '@semantic-icons/lucide-icons';
/** By halves (step 0.5): the left half of a star gives a half, the arrows move by halves. */@Component({  selector: 'app-half-rating-demo',  imports: [ScRating, ScRatingIcon, SiStarIcon],  template: `    <div class="flex flex-col items-center gap-2">

Form

{
  "stars": null
}
import { JsonPipe } from '@angular/common';import { Component, ViewEncapsulation, signal } from '@angular/core';import { FormField, form, required } from '@angular/forms/signals';import {  ScField,  ScFieldErrors,  ScFrame,  ScLabel,  ScRating,  ScRatingIcon,

Read-only

4.2 · 128 reviews
import { Component, ViewEncapsulation } from '@angular/core';import { ScRating, ScRatingIcon } from '@semantic-components/ui';import { SiStarIcon } from '@semantic-icons/lucide-icons';
/** Read-only: any score (4.2), an image named by its value text. */@Component({  selector: 'app-readonly-rating-demo',  imports: [ScRating, ScRatingIcon, SiStarIcon],  template: `    <div class="flex items-center gap-2">

Disabled

import { Component, ViewEncapsulation, signal } from '@angular/core';import { ScRating, ScRatingIcon } from '@semantic-components/ui';import { SiStarIcon } from '@semantic-icons/lucide-icons';
/** Disabled: out of the tab order, no press or key changes it. */@Component({  selector: 'app-disabled-rating-demo',  imports: [ScRating, ScRatingIcon, SiStarIcon],  template: `    <div

Deselectable

3 out of 5

import { Component, ViewEncapsulation, signal } from '@angular/core';import { ScRating, ScRatingIcon } from '@semantic-components/ui';import { SiStarIcon } from '@semantic-icons/lucide-icons';
/** Deselectable: a press on the score given, Delete or Backspace takes it back (null). */@Component({  selector: 'app-deselectable-rating-demo',  imports: [ScRating, ScRatingIcon, SiStarIcon],  template: `    <div class="flex flex-col items-center gap-2">

Other icons

import { Component, ViewEncapsulation, signal } from '@angular/core';import { ScRating, ScRatingIcon } from '@semantic-components/ui';import { SiHeartIcon } from '@semantic-icons/lucide-icons';
/** Any icon, and a colour of yours on the rating (the full stars). */@Component({  selector: 'app-icons-rating-demo',  imports: [ScRating, ScRatingIcon, SiHeartIcon],  template: `    <div

Size and colour

import { Component, ViewEncapsulation, signal } from '@angular/core';import { ScRating, ScRatingIcon } from '@semantic-components/ui';import { SiStarIcon } from '@semantic-icons/lucide-icons';
/** Bigger icons (a size of yours on the icon) and amber stars (a colour on the rating). */@Component({  selector: 'app-size-rating-demo',  imports: [ScRating, ScRatingIcon, SiStarIcon],  template: `    <div

RTL

import { Dir } from '@angular/cdk/bidi';import { Component, LOCALE_ID, ViewEncapsulation, signal } from '@angular/core';import { ScRating, ScRatingIcon } from '@semantic-components/ui';import { SiStarIcon } from '@semantic-icons/lucide-icons';
/** In a right-to-left page: from the right, ← raises it, the left half of a star its far half. */@Component({  selector: 'app-rtl-rating-demo',  imports: [Dir, ScRating, ScRatingIcon, SiStarIcon],  template: `

API reference

Each part takes class, merged over the style (cn: a later class wins).

PartSelectorDescription
ScRatingdiv[scRating] A slider (an image, read-only): value, a number or null while not rated (two-way, or a [formField]); count (5); step (1, or 0.5 for halves); deselectable; readonly; disabled; valueText ({value}, {max}, in LOCALE_ID). exportAs scRating: shown(), text().
ScRatingIconng-template[scRatingIcon] Your icon, once, in an ng-template: drawn for each star twice — empty (muted), and full over it up to the star's fill (--sc-rating-fill, 0 to 1), in the rating's colour (text-primary; yours by class). Context: the star (1 for the first) and full, for a different icon per layer. Unsized icons size-5.