Input
Choose a whole-star rating with keyboard or pointer. The group is named by the question and the parent owns the value. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.
"use client"
import * as React from "react"
import { RatingInput } from "@/components/ui/rating"
export function RatingInputExample() {
const [score, setScore] = React.useState(0)
return (
<div className="flex w-full max-w-md flex-col gap-6">
<div className="flex flex-col gap-2">
<p id="rating-demo-label" className="text-label-sm text-strong-950">
How was your experience?
</p>
<RatingInput aria-labelledby="rating-demo-label" value={score} onValueChange={setScore} />
<p className="text-paragraph-sm text-sub-600" aria-live="polite">
{score ? `You chose ${score} out of 5.` : "No rating yet."}
</p>
</div>
</div>
)
}