Rating

Material Design 3-styled rating web component (lit-material-rating): a row of icons for reading or picking a value.

  • 2.6 KB gzipped
  • @lit-material/rating 0.0.3
  • Renders on the server

Example

Install

npm install @lit-material/rating @lit-material/tokens
import "@lit-material/rating";

Link @lit-material/tokens/css/index.css once per page for the colour, type and shape tokens. Install guide

API

<lit-material-rating>

A row of icons for reading or picking a value — built on a real native <input type="range"> for keyboard (arrows/Home/End/PageUp/PageDown), pointer dragging, value clamping/stepping, and ARIA slider semantics, styled invisibly on top of the custom-drawn icon row — the same pattern lit-material-slider uses.

Properties

PropertyAttributeTypeDefaultDescription
valuevaluenumber0
maxmaxnumber5
precisionprecision1 | 0.51The smallest step a user can pick: 1 (whole icons only) or 0.5 (half icons too). Doesn't constrain value itself — a readonly display can show any fraction.
readonlyreadonlybooleanfalseNon-interactive display of value — distinct from disabled: still perceivable/labeled, just not a control.
disableddisabledbooleanfalse
namenamestring""
formformstring | undefinednone
labellabelstring"Rating"Accessible label — required in interactive mode (there's no visible text label), and prefixed onto the readonly role="img" announcement.

Events

EventDescription
changeBubbles once the value change is committed (matches native <input>).
inputBubbles live as the value changes while dragging/pressing a key (matches native <input>).

CSS parts

PartDescription
ratingThe container.
iconsThe row of icon elements.
iconA single icon's wrapper.
inputThe native <input type="range"> (interactive mode only).

Source on GitHub npm