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 RatingGroupDemo() {
  return (
    <div className="flex items-center justify-center p-10">
      <RatingGroup.Root defaultValue={3} count={5}>
        <RatingGroup.Label>Rating</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

    6
  • Block UI

    Block UI

    2
  • Clipboard

    Clipboard

  • Date Input

    Date Input

  • Grid

    Grid

More in Forms

View all
  • Premium Auth

    Premium Auth

    583
  • Login 1

    Login 1

    70
  • Form

    Form

    142
  • Form

    Form

    22
  • Login Card

    Login Card

    36
  • Form

    Form

    3
  • Contact Card

    Contact Card

    1.1K
  • Book A Demo 4

    Book A Demo 4

    67