bysages

Rating Group

Forms

About

An accessible star-rating control with keyboard support, half-star precision, and a hidden form input, for collecting a 1-to-N rating from a user.

Built with React and Tailwind. Copy the prompt and paste it into Claude Code, Cursor or Lovable: your agent adds Rating Group to your project and fits it to your theme.

Code

How Rating Group is used: the demo's code. The component's own source comes with a free account.

Usage.tsx

"use client";

import RatingGroup from "@/components/ui/rating-group";

function Star() {
  return (
    <svg
      viewBox="0 0 24 24"
      width={16}
      height={16}
      fill="currentColor"
      aria-hidden="true"
    >
      <path d="M12 2.5l2.9 6.1 6.7.9-4.9 4.6 1.2 6.6-5.9-3.2-5.9 3.2 1.2-6.6L2.4 9.5l6.7-.9z" />
    </svg>
  );
}

export default function RatingGroupDisabledDemo() {
  return (
    <div className="flex items-center justify-center p-10">
      <RatingGroup.Root defaultValue={3} disabled count={5}>
        <RatingGroup.Label>Frozen</RatingGroup.Label>
        <RatingGroup.Control>
          <RatingGroup.Context>
            {({ items }: { items: number[] }) =>
              items.map((item) => (
                <RatingGroup.Item key={item} index={item}>
                  <Star />
                </RatingGroup.Item>
              ))
            }
          </RatingGroup.Context>
          <RatingGroup.HiddenInput />
        </RatingGroup.Control>
      </RatingGroup.Root>
    </div>
  );
}

Dependencies

More by bysages

View all
  • Switch

    Switch

    18
  • Avatar Group

    Avatar Group

    14
  • Typography

    Typography

    12
  • Spinner

    Spinner

    7
  • Block UI

    Block UI

    2
  • Clipboard

    Clipboard

  • Date Input

    Date Input

  • Grid

    Grid

More in Forms

View all
  • Premium Auth

    Premium Auth

    593
  • Contact Form

    Contact Form

    28
  • Form

    Form

    4
  • Login 1

    Login 1

    70
  • Book A Demo 1

    Book A Demo 1

    94
  • Contact Card

    Contact Card

    1.1K
  • HeroUI Field Error

    HeroUI Field Error

    13
  • Form [react-aria-components]

    Form [react-aria-components]

    19