Skip to content
ProLifetime access for $199, paid once, every future release included
Truffle UI

Poll

ProNew

A supplied-data poll that becomes its own results: single or multiple choice, image options, colored appearances and exact percentages and vote counts.

Installation

pnpm dlx shadcn@latest add @viewport/poll

First time? Add the @viewport registry to components.json. Setup takes one minute.

Usage

The code behind the preview above comes with Truffle Pro.

Props

PropTypeDefault
question*string

The question, rendered as the poll's heading.

—
options*PollOption[]—
descriptionstring

A line of supporting text under the question.

—
multipleboolean

Let people tick several options and confirm with a Vote button. Single choice votes on the first press.

false
maxnumber

With `multiple`, the most options one person may tick.

—
appearance"card" | "plain" | "gradient"

`card` sits on the card token, `plain` has no surface, `gradient` paints the two `gradient` colors behind white text.

"card"
accentstring

Any CSS color. Tints the options, the result bars and the chosen outline.

"#1672f3"
gradient[string, string]

Top and bottom colors of the `gradient` appearance.

["#94006d", "#3d48e4"]
defaultVotedstring[]

Option ids this visitor has voted for before, already included in `votes`. Starts the poll on its results.

—
onVote(ids: string[]) => void | Promise<unknown>

Called with the chosen ids. Return a promise to show the pending state; reject it to show the error and let them retry.

—
allowChangeboolean

Offer “Change vote” under the results.

false
showCountsboolean

Show each option's vote count next to its label in the results.

true
closedboolean

Voting has ended: results only, nothing to press.

false
loadingboolean

Show placeholder rows while the options load.

false
localestring

Locale for grouping digits in vote counts.

"en-US"
classNamestring—

Accessibility

  • Options are real buttons grouped under the question; multiple choice exposes them as checkboxes with a Vote button.
  • After voting, focus moves to the results list and a live region reads every share; each row reads as “350 votes, 35%, your vote”.
  • Your choice is marked with an outline and a check, never by color alone.
  • A failed vote is announced as an alert and the options stay ready to retry.
  • Result bars use transform-only fills and numbers update without a React re-render per frame; both appear at their final value under reduced motion.