StylishRating

fun StylishRating(value: Int, onValueChange: (Int) -> Unit, modifier: Modifier = Modifier, max: Int = 5, enabled: Boolean = true, size: Dp = 28.dp, filledColor: Color = MaterialTheme.colorScheme.primary, emptyColor: Color = MaterialTheme.colorScheme.surfaceVariant, interactionSource: MutableInteractionSource? = null)

A star rating selector for choosing a value from 1 to max stars.

Renders a row of max star icons; the first value stars are tinted with filledColor and the rest with emptyColor. Tapping the n-th star calls onValueChange with n. The value is hoisted — the caller owns the state — so the rating never changes itself.

Each star is announced as a radio button via semantics with selected set per star, and the row carries a contentDescription summarizing the rating (e.g. 評価 3 / 5), matching the web rating-group accessibility pattern. When enabled is false the stars reject pointer input and are announced as disabled.

The star row follows the web focus-visible pattern: when a star is focused (keyboard navigation), a focus ring (see Modifier.stylishFocusRing) is drawn around that star. The rating uses no animation, so reduced-motion settings need no special handling.

Testing

The root carries the default test tag stylish_rating for UI tests. Callers can override it by passing their own Modifier.testTag(...) in modifier.

Parameters

value

The current rating between 0 and max. Values outside the range are coerced for display.

onValueChange

Called with the new rating (1-based) when a star is tapped.

modifier

Modifier applied to the Row root.

max

The number of stars displayed. Defaults to 5.

enabled

When false, the stars reject pointer input and are announced as disabled.

size

The edge length of each star's touch target. Defaults to 28.dp.

filledColor

Tint of stars at or below value. Defaults to MaterialTheme.colorScheme.primary.

emptyColor

Tint of stars above value. Defaults to MaterialTheme.colorScheme.surfaceVariant.

interactionSource

The MutableInteractionSource shared by all stars, used to observe focus interactions (driving the focus ring). When null, an internal one is remembered.