Skip to content
Browse docs and components

Poll

poll

A question to vote on that turns into its results in place: bars grow to each share, the percentages roll and always total 100, and your choice is marked. Single or multiple choice, on real radios and checkboxes.

Responsive

Install

$npxshadcnadd@forme/poll

Adds the component, its registry dependencies, and the token stylesheet you import once.

API reference

Read from the source, so it is the API of the file you install. A prop marked * is required.

Poll

A question with a vote, and what everyone said.

PropTypeDefaultDescription
question*ReactNode—
options*readonly PollOption[]—
descriptionReactNode—
votesReadonly<Record<string, number>>{}Everyone else's votes, by option id. The poll counts the person's own vote itself, so the bars move the moment they vote rather than after a round trip.
multiplebooleanfalseAllow more than one choice: checkboxes instead of radios.
defaultValuereadonly string[][]The person's choice, for a poll they have already answered.
defaultVotedbooleanfalseStart on the results: they voted in an earlier visit.
showResultsbooleanfalseShow the results before voting, too.
onVote(ids: string[]) => void | Promise<void>—Called with the chosen ids. Return a promise and the button waits for it.
submitLabelstring"Vote"
classNamestring—