Appica UIUI 1.1.0

Rating

A score input built from a row of stars, or any icon you choose, with support for fractional values.

Usage

Rating renders a radiogroup of icon buttons: one per item, filling from the start of the row up to the current value. Moving the pointer across the row sweeps the fill up to the rating a click would set, and lifts the icon under the cursor. The preview always lands on a step boundary, so it never promises a value the click won't deliver; what stays continuous is the mask animating there, not the value. Holding the pointer (or Space) presses the icon down for as long as you hold it, and it springs back on release. The accent color comes from the inherited text color, so any text-* utility recolors the whole control. Every animation is skipped when the user prefers reduced motion.

Examples

Default

Set the initial rating with defaultValue (uncontrolled), or drive it yourself with value + onValueChange. 0 means unrated.

Icons

The star is built in, so @appica/ui-react carries no icon dependency. For any other shape pass icon={{ empty, filled }} - two 24x24 currentColor SVGs, typically a matching outline and solid pair from @appica/icons-react. filled doubles as the muted base in the filled variant, so both layers stay in register.

Variants

variant="filled" (the default) draws unrated items as muted solid icons, which keeps the row's visual weight steady as it fills. variant="outline" draws them as line icons in the accent color for a lighter look.

Orientation

orientation="vertical" stacks the items in a column, filling from the top down. The pointer preview follows the cursor's vertical position, and / step through the items either way.

Sizes

size takes any icon size rather than a fixed set: a number is read as pixels, and a string is used verbatim, so size="1em" makes the row follow the surrounding font size. The button padding is a sixth of size on every side (4px at the 24px default), so the hit area and the gap between icons grow with the icon rather than staying fixed.

Fractions

Lower step to allow partial items. step is the granularity of both the click and the hover preview, so step={0.5} previews and selects half icons; the mask still sweeps smoothly between those stops rather than jumping. A value finer than step renders exactly as given, which is what read-only averages need.

Color

The accent is inherited, not a prop, so a text-* class on the root recolors the fill and the outline together. Unrated items in the filled variant keep their muted background color.

Read only

readOnly renders a non-interactive display: no buttons, no hover preview, and the whole row is exposed to assistive tech as a single labeled image ("4.3 out of 5" unless you pass your own aria-label). Pair it with a small step to show an average.

Controlled with labels

onHoverChange reports the step-snapped rating under the pointer (and null when it leaves), so a "Terrible → Excellent" caption follows what a click would select rather than the committed value. clearable lets a second click on the current item reset the rating to 0.

In a form

name renders a hidden input carrying the current value, so a Rating submits with the rest of the form and needs no controlled state. Name it with a <span id> plus aria-labelledby rather than FieldLabel: that emits a <label for>, which doesn't associate with a role="radiogroup".

RTL

Every Appica UI component supports right-to-left layouts out of the box. Set the dir attribute on a container (commonly your <html> element) so CSS logical properties resolve correctly, and wrap your tree in DirectionProvider so direction-aware behavior (roving focus, popup placement, and the like) follows the same direction.

In RTL the first item sits on the right, items fill right to left, and / swap roles.

For setup details and caveats, see the RTL guide.

قيّم هذا المنتج
ممتاز١٬٢٨٤ تقييمًا

API reference

Rating is a single element: a <div> wrapping one <button role="radio"> per item. It forwards ref, aria-*, and the remaining <div> attributes to the root.

The root carries data-slot="rating" plus data-disabled / data-readonly; each item carries data-slot="rating-item" and data-checked when it holds the current value.

Accessibility

  • An interactive Rating renders a <div role="radiogroup"> with one <button role="radio"> per item. Name it with aria-label or aria-labelledby.
  • Each item is named by itemAriaLabel, which defaults to the rating that item selects ("3 of 5"). The item holding the current value is aria-checked.
  • The group is a single tab stop: Tab moves focus to the rated item (or the first one), then / step to the next item and / to the previous one, by step. Home jumps to the lowest rating and End to the highest, and Space or Enter selects the focused item. Only / mirror in RTL. The root carries aria-orientation.
  • Fractional ratings are announced at item granularity: with step={0.5}, arrowing to 2.5 keeps the third item checked. Use readOnly when the exact average matters - it exposes the row as one image labeled "4.3 out of 5".
  • disabled blocks interaction and dims the control; readOnly drops the buttons entirely rather than presenting inert ones.
  • The hover fill sweep, the icon lift, and the press-and-release scale all honor prefers-reduced-motion.

© 2026 Appica UI. A free component library, crafted by the Appica team.