Skip to content
Okaapiأوكابي
Framework for the code
Theme
Okaapi on GitHub

Chapter 05 Choices

Rating

Stars out of five, to pick a score or to show one. Picking uses real radio buttons, so Tab reaches the stars, arrow keys move between them and a screen reader says 3 stars, 3 of 5. Filled stars are solid and empty ones an outline, so the shape tells them apart, not only colour.

Use it in Angular
import { RatingComponent } from '@okaapi-ui/angular';
// The value is a number, or null before a pick. Works with formControlName, [formControl] and ngModel.

Pick a score

How was the food?
Angular
<ui-rating label="How was the food?" formControlName="food" />

Show a score

Read as one image with the score in words. A score with a fraction fills to the nearest star; the words keep the exact number.

4.6 from 212 orders
Angular
<ui-rating [value]="4.6" readonly />
<span>4.6 from 212 orders</span>

In Arabic

ما رأيك في الأكل؟
Angular
<ui-rating label="ما رأيك في الأكل؟" [starLabel]="star" formControlName="food" />

star = (n: number) => n === 1 ? 'نجمة واحدة' : n === 2 ? 'نجمتان' : `${n.toLocaleString('ar-EG')} نجوم`;

When to use something else

If you needUse
An exact numberNumber field
Show a score the reader cannot changeMeter

Inputs

NameTypeDefaultWhat it does
labelstring — Names the stars, as the fieldset legend. Required when people pick.
maxnumber5How many stars.
starLabel(stars: number) => string`${n} stars` from labelsThe name of one star, read by screen readers. Translate it.
scoreLabel(value, max) => string`${v} out of ${m} stars` from labelsThe read-only score in words. Translate it.
readonlybooleanfalseOnly shows [value]; nothing to pick.
valuenumber — The score to show when readonly. A form control sets it otherwise.

Keyboard and screen readers

KeysWhat they do
Tab Reach the group, on the chosen option.
Arrow keys Move the choice to the next or previous option.
  • Real radio buttons, read as 3 stars, 3 of 5.
  • Filled stars are solid and empty ones an outline, so shape tells them apart.