@akhatmirzo/ui

Rating

Star rating with keyboard support, half values, hover preview and a read-only mode for reviews.

Import

import { Rating } from '@akhatmirzo/ui';

When to use

  • Rating a product, service or courier — users give feedback in a single click.
  • Showing an average score in a review list — use readOnly (fractions are drawn exactly: 4.3 → 4 full stars and 0.3 of the next).
  • When you need an exact number or a wide scale (0–100), a Slider works better.
  • For options with distinct meanings ("Bad / OK / Good"), use a SegmentedControl or a RadioGroup.

Half values

With allowHalf the left half of each star gives x.5 and the right half gives x; the arrow keys move in 0.5 steps. Half stars are drawn with clip-path.

3.5 / 5

Read-only

readOnly isn't interactive: the element is read as a single image with role="img" and aria-label="4.5 / 5". The value isn't rounded — 3.7 is drawn as exactly 3.7 stars.

  • Dilnoza

    Yetkazib berish tez, sifat zo'r.

  • Jasur

    O'lchami biroz katta keldi.

Color, icon and size

  • color — the filled star color: warning (default), primary, danger. Empty stars use the text-muted color.
  • icon — any icon instead of the built-in star (an SVG painted with currentColor).
  • size — sm 16px, md 20px (default), lg 28px.
  • max — the number of stars (default 5).

Clearing and Field

With allowClear (default true), clicking the selected star again resets the value to 0. For a required rating set allowClear={false}. Inside a Field the label names the group and the description goes into aria-describedby.

1 dan 5 gacha baholang

Props

Other <div> attributes and ref go to the root element.

PropTypeDefaultDescription
valuenumber—Value (controlled)
defaultValuenumber0Initial value
onValueChange(value: number) => void—Called when the value changes
maxnumber5Number of stars
allowHalfbooleanfalse0.5 steps
allowClearbooleantrueClicking the selected value again resets it to 0
readOnlybooleanfalseDisplay only: role="img" + aria-label
disabledboolean—Disabled state (not focusable)
size'sm' | 'md' | 'lg''md'Star size 16 / 20 / 28px
iconReactNodestar SVGIcon instead of the star
color'warning' | 'primary' | 'danger''warning'Filled star color
labels{ value?: (value: number, max: number) => string; group?: string }'${v} / ${max}', 'Baho'Radio and read-only name; group name (without Field or aria-label)

Data attributes

AttributeWhereValue
data-sizerootsm · md · lg
data-hoverrootpresent while hovering the stars
data-readonlyrootpresent in readOnly
data-disabledrootpresent when disabled
data-stateradiochecked · unchecked
data-statestarfull · partial · empty

Keyboard

KeyAction
TabEnter the group (on the selected star)
→ ↑ / ← ↓Increase / decrease by one step (and select)
Home / EndLowest (1 or 0.5) / highest value
Space / EnterSelect the focused star (again — clear)

Accessibility

  • Interactive — role="radiogroup", each value is a role="radio" (aria-checked, aria-label="3 / 5"); with allowHalf each star holds two radios. Roving tabindex: one Tab stop for the whole group.
  • Name. The Field label via aria-labelledby, otherwise aria-label or labels.group ("Baho").
  • readOnly — role="img" with aria-label (labels.value); the stars are aria-hidden.
  • Disabled — aria-disabled; the radios aren't focusable.

On this page