Skip to content
Vertical Jump Designs-uiFront-End Studio
Get Pro

v3.9 is out.

Pro (paid add-on)

Polls

Pro

PollBuilder is a ready-made form for creating a poll, with a live preview beside it. PollResultsChart shows the results as a chart with a data table. Both work with the free [Poll](/docs/components/poll).

Part of Pro

This page documents part of @vjdesigns-pro/ui, the paid add-on package. Using it needs a Pro license and @vjdesigns/vjdesigns-ui 3.8.0 or later. Like the free package, it works in both modes, every brand, all 32 languages and right to left. Install it as described in Account forms.

Example

PollBuilder asks for the question, 2 to 10 options, whether people can pick more than one (and how many), an end date, and when results show. It catches empty and duplicate options, and onSubmit gets a PollDefinition that you can pass straight to the free Poll.

tsx
import { PollBuilder } from "@vjdesigns-pro/ui";
import { Poll } from "@vjdesigns/vjdesigns-ui";

<PollBuilder title="Create a poll" onSubmit={savePoll} onSuccess={setPoll} />

// The PollDefinition it returns passes straight to the free Poll:
<Poll {...poll} options={withVoteCounts(poll.options)} onVote={vote} />

Building a poll

  • Options can be added, removed and reordered with buttons, so no dragging is needed.
  • showPreview shows a live Poll beside the form, in the bars or compact layout (previewLayout).
  • minOptions, maxOptions, allowMultiple and allowEndDate set what the form offers, and defaultValue starts from a template or a draft.
  • Return an error from onSubmit to show a server error.

Results chart

PollResultsChart takes the same options you pass to Poll and draws them as a donut (parts of the whole, with the total in the middle) or a bar chart (easier to compare close results). It's one of the Pro charts, so it has a legend, keyboard access and a data table.

tsx
<PollResultsChart
  title="When should the summer league play?"
  description="Saturday morning won by a wide margin."
  options={options}
  kind="bar"
/>

Accessible by default

  • Moving an option keeps focus on it and announces its new place ("Moved to position 2 of 4"); removing one moves focus to a neighbor and announces it.
  • Each move and remove button is named for its option ("Move option 3 up").
  • The form lists problems in an error summary, and the preview is a labeled region.

Props

PollBuilder

A ready-made "create a poll" form: the question, 2 to 10 options (add, remove, and reorder them with buttons), multiple choice with a limit, an end date, and when results show, beside a live Poll preview. Validates required and duplicate options, and returns a PollDefinition you can pass straight to Poll.

PollBuilder props
PropTypeDefault
onSubmitRequired

Calls your backend with the new poll.

(poll: PollDefinition) => PollSubmitResult | Promise<PollSubmitResult>—
onSuccess

Called after onSubmit succeeds, with the poll sent.

(poll: PollDefinition) => void—
defaultValue

Prefilled poll, e.g. a template or a draft.

Partial<PollDefinition>—
minOptions

Fewest options.

number2
maxOptions

Most options.

number10
allowMultiple

Offer "Allow multiple choices".

booleantrue
allowEndDate

Offer an end date.

booleantrue
showPreview

Show a live Poll preview beside the form.

booleantrue
previewLayout

Layout of the preview poll.

"bars""compact""bars"
title

Heading. Pass null for none.

ReactNode"Create a poll"
description

Text under the heading.

ReactNode—
headingLevel

Heading level.

1234562
submitLabel

Submit button text.

ReactNode"Create poll"
variant

card: a raised card. plain: no frame.

"card""plain""card"
className

Class name for the root.

string—
style

Style for the root.

CSSProperties—

PollResultsChart

A poll's results as an accessible Pro chart: a donut (with the total in the middle) or a bar chart, with a legend, keyboard-explorable marks, and a data table. For dashboards and detailed results views.

PollResultsChart props
PropTypeDefault
titleRequired

The chart's title, e.g. the poll question. Names the figure.

string—
description

One-sentence takeaway under the title.

ReactNode—
optionsRequired

The poll's options with their vote counts (the same array you pass to Poll).

readonly PollOption[]—
kind

donut: parts of the whole, with the total in the middle. bar: easier to compare close results.

"donut""bar""donut"
defaultShowTable

Show the data table instead of the chart at first.

booleanfalse
className

Class name for the figure.

string—
style

Style for the figure.

CSSProperties—

PollDefinition

A poll as PollBuilder creates it. Spread it straight into Poll: <Poll {...definition} />.

PollDefinition props
PropTypeDefault
questionRequiredstring—
optionsRequired

The choices, in order. values are stable ids ("option-1", ...).

{ value: string; label: string; }[]—
multipleRequiredboolean—
maxChoices

With multiple: the most choices per voter.

number—
endsAt

ISO date ("YYYY-MM-DD"): voting closes at the end of that day.

string—
showResultsRequired"after-vote""always""never"—

PollSubmitResult

What a PollBuilder onSubmit handler returns. Return nothing when it worked; error for one message above the form, and/or fieldErrors by field name (question, endsAt, maxChoices).

PollSubmitResult props
PropTypeDefault
errorReactNode—
fieldErrorsFormErrors—