Rating
A row of stars for picking a score from 1 to `max`.
<arc-rating>Overview
Rating renders max stars (5 by default) for scores like a product review or a satisfaction survey. Filled stars use the accent color with a glow, and empty stars are outlines. Hovering fills every star up to the one under the pointer, so you see the score before you click.
A value of 0 means unrated. It's the starting value, it submits nothing, and screen readers hear "No rating". Clicking the star that's already selected clears the rating back to 0.
The star group is one tab stop with the slider role. Arrow right or up adds a star, arrow left or down removes one, Home clears to 0, and End jumps to max. Every change from a click or a key fires arc-change with { value }.
disabled dims the stars to 50% and blocks input. readonly blocks input but leaves the stars at full strength, for showing a rating someone already gave.
Guidelines
Do
- Set `readonly` to show an existing rating
- Show the score as text next to the stars, for example "4 out of 5"
- Give each rating its own `label` when a page has more than one
Don't
- Don't use it for yes-or-no choices. Use Toggle or Checkbox
- Don't set `max` above 10. Past that, people can't count the stars without reading them one by one
- Don't use it for exact numbers. Use Slider or NumberInput
Features
- `aria-valuetext` reads "3 of 5", or "No rating" at 0
- `label` sets the accessible name, which defaults to "Rating"
Preview
Usage
This component needs JavaScript. Use the Web Component or a framework wrapper.
<arc-rating value="3" max="5"></arc-rating>import { Rating } from '@arclux/arc-ui-react';
export default function Example() {
return (
<Rating value={3} max={5} />
);
}<script setup>
import { Rating } from '@arclux/arc-ui-vue';
</script>
<template>
<Rating :value="3" :max="5" />
</template><script>
import { Rating } from '@arclux/arc-ui-svelte';
</script>
<Rating value={3} max={5} />import { Component } from '@angular/core';
import { Rating } from '@arclux/arc-ui-angular';
@Component({
imports: [Rating],
template: `
<arc-rating [value]="3" [max]="5"></arc-rating>
`,
})
export class MyComponent {}import { Rating } from '@arclux/arc-ui-solid';
export default function Example() {
return (
<Rating value={3} max={5} />
);
}import { Rating } from '@arclux/arc-ui-preact';
export default function Example() {
return (
<Rating value={3} max={5} />
);
}API
namestring''labelstring''- Accessible name for the control. Several ratings on one page are indistinguishable without it. Defaults to "Rating".
disabledbooleanfalse- Disables interaction, reducing opacity to 40% and blocking pointer events.
valuenumber0- Current rating value, 0 to
max. **0 means unrated**; it is a legal state of the control, not a rating of zero: it submits nothing, announces as "No rating", and is what Home and a left-arrow at the first star return to. Clicking the star that is already selected also clears back to it. Reflected as an attribute and updated on user interaction. maxnumber5- Maximum number of stars to render. Determines the upper bound of the rating scale.
readonlybooleanfalse- Prevents interaction while maintaining full visual appearance. Useful for displaying existing ratings.
size'sm' | 'md' | 'lg''md'- Control size.
mdis the default;smandlgscale the star glyphs. formAssociatedbooleantruepropertiesobject{ // flag(), unlike `disabled`. The exclusion in props.js is specifically // about form-associated *platform* semantics: a `disabled` content // attribute that is merely present makes the element actually disabled // per the HTML spec, and formDisabledCallback assigns the property back, // so no converter can win. Neither of these is platform-mapped: // `required` is enforced by _computeValidity() below and `readonly` by // each component's own interaction handlers, so the stock converter buys // nothing here and costs the usual bug: `required="false"` read as true, // blocking submission of a form the author meant to leave optional. // Finding #48's shape, across all 26 form controls at once. required: flag(false), readonly: flag(false), }- Lit merges static properties up the prototype chain, so every consumer
gets these without declaring them.
requiredparticipates in constraint validation below;readonlyreflects for styling and is enforced by each component's interaction handlers (the mixin can't know which gestures mutate state). autoValidatesbooleantrue- Components that run their own constraint-validation logic (pattern checks, range checks) opt out of the automatic required sync by overriding this to false, and own the whole validity flag set instead.
formvalidityvalidationMessagerequiredbooleanfalse
Methods
checkValidity()boolean- Whether the control currently satisfies its constraints, per the native
constraint-validation API. Fires
invalidon the element when it does not, and reports nothing to the user. reportValidity()boolean- As checkValidity(), but also shows the browser's validation message against the control when it fails.
Events
arc-changedetail:{ value: number }- Fired when the rating value changes