form fields
<tc-rating>
Star rating input with optional half-star precision, keyboard nav, hover preview, and a read-only display mode.
import
"@ra9/tan-compose-kit/rating"
Props
| Name | Type | Default | Description |
|---|---|---|---|
value | number | 0 | Current rating. Reflects to the `value` attribute. |
max | number | 5 | Total number of stars. |
readonly | boolean | false | Display-only mode. Renders as `role="img"`. |
allowHalf | boolean | false | Allow 0.5 increments. Click the left half of a star for a half rating. |
size | "sm" | "md" | "lg" | "md" | Star size — 18 / 24 / 32 px. |
ariaLabel | string | "Rating" | Accessible label. |
Events
| Event | Detail | When |
|---|---|---|
tc-change | { value: number, previous: number } | Fires when the user picks a new rating (click or keyboard). |
CSS variables
| Variable | Default | Description |
|---|---|---|
--tc-rating-fill | var(--tc-color-warning, #d7a52f) | Filled star color. |
--tc-rating-track | var(--tc-color-rule, #ece5d3) | Empty star color. |
Examples
Basic
Half-stars
Read-only display
Pair with a count for a typical product card.
Custom max
Listening for change
Accessibility
- Interactive ratings use
role="slider"witharia-valuenow / valuemin / valuemax / valuetext. Keyboard support:←/→(or↑/↓) adjust by step,Home/Endjump to 0 / max. - Read-only ratings use
role="img"with the value baked intoaria-label. - Clicking the current value clears the rating, in case users want to undo.
- Star fills use a clip-path for the half state — at any zoom level the half is exactly 50%.