Skip to content

shadcn.io is an independent project built on shadcn/ui

Free

Rating Dialog for Svelte

A rating dialog with five empty stars, an optional comment, and Submit Rating kept off until a star is picked.

UI library: Ark UI

Rate Experience opens How was your experience? Five stars sit under Rating, and none are filled, so Submit Rating is off. An optional comment field is under the stars, with Cancel beside the button.

Use it for a quick score plus an optional note. Ask for the score alone in a Popover if a dialog is too heavy. In Svelte, Ark UI does not store the rating.

Preview

Preview width

Installation

MCP · Pro
Make your AI a shadcn expert
Your agent installs components, builds pages and restyles your app from one prompt, in Claude Code, Cursor or VS Code.
Part of Pro

Anatomy

Dialog anatomy: content, title, description, close, footer

Usage

<Dialog><DialogTrigger>{#snippet asChild(props)}<Button {...props()} variant="outline">Rate Experience</Button>{/snippet}</DialogTrigger><DialogContent class="sm:max-w-lg"><DialogHeader><DialogTitle>How was your experience?</DialogTitle><DialogDescription>Please rate your experience and share any additional feedback.</DialogDescription></DialogHeader><FieldGroup><Field><FieldLabel>Rating</FieldLabel><Rating class="**:data-[slot=rating-item-indicator]:size-8" name="rating" onValueChange={handleValueChange} value={rating} /></Field><Field><FieldLabel>Additional feedback (optional)</FieldLabel><Textarea class="min-h-25" name="comment" placeholder="Tell us more about your experience..." /></Field></FieldGroup><DialogFooter><DialogClose>{#snippet asChild(props)}<Button {...props()} variant="outline">Cancel</Button>{/snippet}</DialogClose><Button disabled={rating === 0}>Submit Rating</Button></DialogFooter></DialogContent></Dialog>

FAQ

Does the rating preview on hover?

Yes. Rating highlights the stars under the pointer before a click and handles the arrow keys, so there's no hover state to manage.

How is the rating stored?

The rating is controlled: onValueChange passes the new value, and Submit Rating takes disabled while it's 0.

Can I allow half stars?

Yes, set allowHalf on Rating.

How are the stars made larger?

The stars use the theme's warning color, and a class on Rating sets their size: **:data-[slot=rating-item-indicator]:size-8.

Should a low rating require a comment?

It helps: when the rating is 1 or 2, require the comment and ask what went wrong.

Does Submit Rating close the dialog?

Cancel is a DialogClose, so it does. Submit Rating doesn't; close the dialog from your handler after sending. Pass open and update it in onOpenChange, which receives { open }.

API Reference

Dialog

No extra props in this demo. The rest is on the Dialog page.

Button

Sets props, variant="outline" and disabled={rating === 0}. The rest is on the Button page.

Field

No extra props in this demo. The rest is on the Field page.

Rating

Sets name="rating", onValueChange={handleValueChange} and value={rating}. The rest is on the Rating page.

Textarea

Sets name="comment" and placeholder="Tell us more about your experience...". The rest is on the Textarea page.