# Rokkit Rating Component > Interactive star rating component with keyboard navigation and customizable icons. The Rating component provides an accessible way to display and collect ratings, with support for custom icons, hover effects, and keyboard navigation. ## Quick Start ```svelte

You rated: {rating} out of 5

``` ## Core Concepts ### Value Range Rating uses integer values from 0 to max: ```svelte ``` ### Custom Max Change the maximum rating value: ```svelte ``` ### Custom Icons Override filled and empty state icons: ```svelte ``` ## Props | Prop | Type | Default | Description | |------|------|---------|-------------| | `value` | `number` | `0` | Current rating (use `bind:value`) | | `max` | `number` | `5` | Maximum rating value | | `disabled` | `boolean` | `false` | Disables interaction | | `stateIcons` | `object` | `defaultStateIcons.rating` | Custom icons | | `placeholder` | `string` | `'Rating'` | Accessible label prefix | | `id` | `string` | `null` | Element ID | | `name` | `string` | `null` | Form input name | | `tabindex` | `number` | `0` | Tab index | | `onchange` | `function` | `undefined` | Change event handler | ### State Icons Object ```javascript const stateIcons = { filled: 'icon-class-for-filled', empty: 'icon-class-for-empty' } ``` ## Keyboard Navigation | Key | Action | |-----|--------| | `ArrowRight` / `ArrowUp` | Increase rating | | `ArrowLeft` / `ArrowDown` | Decrease rating | | `0-9` | Set rating directly | ## Component Structure ``` [data-rating] └── [data-rating-item] // Repeated for each star └── [data-filled] // Present when star is filled ``` ## Data Attributes for Styling | Attribute | Element | Purpose | |-----------|---------|---------| | `[data-rating]` | Root | Main container | | `[data-rating][data-rating-disabled]` | Root | Disabled state | | `[data-rating-item]` | Item | Individual star | | `[data-rating-item][data-filled]` | Item | Star is filled/selected | | `[data-rating-item][data-hovering]` | Item | Hover state | ### Styling Example ```css [data-rating] { display: inline-flex; gap: 4px; cursor: pointer; user-select: none; } [data-rating][data-rating-disabled] { opacity: 0.5; cursor: not-allowed; } [data-rating-item] { font-size: 1.5rem; color: var(--surface-400); transition: color 0.15s, transform 0.15s; } [data-rating-item][data-filled] { color: var(--warning-500); } [data-rating-item][data-hovering] { color: var(--warning-400); transform: scale(1.1); } [data-rating]:focus-visible { outline: 2px solid var(--primary-500); outline-offset: 4px; border-radius: 4px; } ``` ## Accessibility - Uses `role="radiogroup"` on container - Each star has `role="option"` - `aria-checked` indicates selection - `aria-label` provides context (e.g., "Rating 3 out of 5") - Full keyboard navigation - Hidden input for form submission ## Import ```javascript // Named import import { Rating } from '@rokkit/ui' // Default import import Rating from '@rokkit/ui/rating' ``` ## TypeScript Types ```typescript interface RatingProps { value?: number max?: number disabled?: boolean stateIcons?: { filled: string empty: string } placeholder?: string id?: string name?: string tabindex?: number onchange?: (event: { value: number }) => void } ``` ## Examples ### Basic Rating ```svelte

Rating: {rating}/5

``` ### Product Rating ```svelte
{productRating} out of 5 stars
``` ### Custom Scale ```svelte ``` ### Heart Rating ```svelte ``` ### Emoji Rating ```svelte ``` ### Read-Only Display ```svelte {#each reviews as review}
{review.name}
{/each} ``` ### Form Integration ```svelte
``` ### With Change Handler ```svelte ``` ### Compact Rating ```svelte
4.0 (128 reviews)
``` ## Related Components - **Icon** - Used for rating stars - **ProgressBar** - For displaying percentages - **Range** - For selecting numeric values