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

v3.9 is out.

Data display

Poll

Free15.9 KB gzipped

A poll with two phases: voting (a question with choices) and results (each choice's share, printed as a percentage, with bars). Four layouts: bars, cards, compact, and versus for two choices head to head. The poll is UI only: it reports votes through onVote and shows the counts you pass in options; storing votes and enforcing one vote per person is up to your server.

Accessibility: WCAG 2.2 AA · No A or AA violations in light or dark mode · Keys: Tab, Enter, Space and 1 more · Full report

More in Pro

This Poll is free. The paid Pro add-on adds PollBuilder, a create-a-poll form whose result passes straight to Poll, and PollResultsChart, the results as a chart with a data table.

Import

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

Importing only Poll adds about 15.9 KB of minified, gzipped JavaScript to your app (React not included). The stylesheet is shared by every component and loaded once: 75.1 KB gzipped.

Examples

Basic

A single-choice poll votes as soon as a choice is pressed, then shows each share as a percentage with a bar. Focus moves to the results and they're announced. The poll is UI only: you store the votes and pass the counts back in options.

When should the summer league play?

tsx
import { useState } from "react";
import { Poll, type PollOption } from "@vjdesigns/vjdesigns-ui";

function addVotes(options: PollOption[], values: string[]) {
  return options.map((option) =>
    values.includes(option.value) ? { ...option, votes: (option.votes ?? 0) + 1 } : option,
  );
}

export function Basic() {
  const [options, setOptions] = useState<PollOption[]>([
    { value: "fri", label: "Friday night", votes: 14 },
    { value: "sat", label: "Saturday morning", votes: 22 },
    { value: "sun", label: "Sunday afternoon", votes: 9 },
  ]);
  return (
    <div style={{ width: "100%", maxWidth: "30rem" }}>
      <Poll
        question="When should the summer league play?"
        options={options}
        onVote={(values) => setOptions((current) => addVotes(current, values))}
      />
    </div>
  );
}

Multiple choice

multiple uses checkboxes and a Vote button, and maxChoices caps the picks. allowChangeVote adds a "Change vote" button to the results, and endsAt shows how long voting stays open.

Which sessions should we add?

Choose up to 2 options

tsx
import { useState } from "react";
import { Poll, type PollOption } from "@vjdesigns/vjdesigns-ui";

function addVotes(options: PollOption[], values: string[]) {
  return options.map((option) =>
    values.includes(option.value) ? { ...option, votes: (option.votes ?? 0) + 1 } : option,
  );
}

export function MultipleChoice() {
  const [options, setOptions] = useState<PollOption[]>([
    { value: "shooting", label: "Shooting clinic", votes: 31 },
    { value: "defense", label: "Defense drills", votes: 18 },
    { value: "conditioning", label: "Conditioning", votes: 12 },
    { value: "film", label: "Film study", votes: 9 },
  ]);
  return (
    <div style={{ width: "100%", maxWidth: "30rem" }}>
      <Poll
        question="Which sessions should we add?"
        options={options}
        multiple
        maxChoices={2}
        allowChangeVote
        endsAt="2026-12-31"
        onVote={(values) => setOptions((current) => addVotes(current, values))}
      />
    </div>
  );
}

Cards

The cards layout shows each choice with an image or icon from media.

Pick next season's jersey

tsx
import { useState } from "react";
import {
  HeartIcon,
  HomeIcon,
  Poll,
  StarIcon,
  type PollOption,
} from "@vjdesigns/vjdesigns-ui";

function addVotes(options: PollOption[], values: string[]) {
  return options.map((option) =>
    values.includes(option.value) ? { ...option, votes: (option.votes ?? 0) + 1 } : option,
  );
}

export function Cards() {
  const [options, setOptions] = useState<PollOption[]>([
    { value: "home", label: "Home jersey", votes: 40, media: <HomeIcon size="lg" /> },
    { value: "star", label: "Star jersey", votes: 27, media: <StarIcon size="lg" /> },
    { value: "heart", label: "Heart jersey", votes: 16, media: <HeartIcon size="lg" /> },
  ]);
  return (
    <div style={{ width: "100%", maxWidth: "40rem" }}>
      <Poll
        layout="cards"
        question="Pick next season's jersey"
        options={options}
        onVote={(values) => setOptions((current) => addVotes(current, values))}
      />
    </div>
  );
}

Versus

versus puts exactly two choices head to head, with one split bar for the results.

Zone or man to man?

tsx
import { useState } from "react";
import { Poll, type PollOption } from "@vjdesigns/vjdesigns-ui";

function addVotes(options: PollOption[], values: string[]) {
  return options.map((option) =>
    values.includes(option.value) ? { ...option, votes: (option.votes ?? 0) + 1 } : option,
  );
}

export function Versus() {
  const [options, setOptions] = useState<PollOption[]>([
    { value: "zone", label: "Zone defense", votes: 48 },
    { value: "man", label: "Man to man", votes: 52 },
  ]);
  return (
    <div style={{ width: "100%", maxWidth: "30rem" }}>
      <Poll
        layout="versus"
        question="Zone or man to man?"
        options={options}
        onVote={(values) => setOptions((current) => addVotes(current, values))}
      />
    </div>
  );
}

Saving votes

When onVote returns a promise, the poll shows a loading state until it settles; if it rejects, the choice stays and voting can be tried again. compact is a denser list.

Will you sign up for the fall season?

tsx
import { useState } from "react";
import { Poll, type PollOption } from "@vjdesigns/vjdesigns-ui";

function addVotes(options: PollOption[], values: string[]) {
  return options.map((option) =>
    values.includes(option.value) ? { ...option, votes: (option.votes ?? 0) + 1 } : option,
  );
}

export function SavingVotes() {
  const [options, setOptions] = useState<PollOption[]>([
    { value: "yes", label: "Yes", votes: 120 },
    { value: "no", label: "No", votes: 35 },
    { value: "unsure", label: "Not sure yet", votes: 22 },
  ]);
  return (
    <div style={{ width: "100%", maxWidth: "30rem" }}>
      <Poll
        layout="compact"
        question="Will you sign up for the fall season?"
        options={options}
        onVote={async (values) => {
          await new Promise((resolve) => setTimeout(resolve, 1200));
          setOptions((current) => addVotes(current, values));
        }}
      />
    </div>
  );
}

Closed

closed ends voting and shows the final results, marking the winner. computePollResults() gives you the same shares, rounded so they add up to exactly 100.

Most valuable player

  • Ava ThompsonWinner44%, 211 votes
  • Marcus Lee36%, 173 votes
  • Jordan Diaz20%, 96 votes

Ava Thompson 44%, Marcus Lee 36%, Jordan Diaz 20%

tsx
import {
  Poll,
  Stack,
  Text,
  computePollResults,
  type PollOption,
} from "@vjdesigns/vjdesigns-ui";

export function Closed() {
  const options: PollOption[] = [
    { value: "a", label: "Ava Thompson", votes: 211 },
    { value: "b", label: "Marcus Lee", votes: 173 },
    { value: "c", label: "Jordan Diaz", votes: 96 },
  ];
  const results = computePollResults(options);
  return (
    <Stack gap={3} style={{ width: "100%", maxWidth: "30rem" }}>
      <Poll question="Most valuable player" options={options} closed />
      <Text tone="muted" size="sm">
        {results.map((result) => `${result.label} ${result.percent}%`).join(", ")}
      </Text>
    </Stack>
  );
}

Right to left

The first example again, inside a right-to-left LocaleProvider (Arabic). Layout, spacing and arrow icons mirror, and the components' built-in text is translated. The example's own text stays in English.

Basic

When should the summer league play?

tsx
import { LocaleProvider } from "@vjdesigns/vjdesigns-ui";
import ar from "@vjdesigns/vjdesigns-ui/locales/ar";

// Basic is the "Basic" example above.
<LocaleProvider locale="ar" messages={ar}>
  <Basic />
</LocaleProvider>

API reference

Poll

New in 3.8.4
Poll props
PropTypeDefault
questionRequired

The question, rendered as a heading (see headingLevel).

ReactNode—
optionsRequired

The choices, with their vote counts. Update votes after onVote, including the new vote.

PollOption[]—
layout

Layout of both phases. versus needs exactly two options.

"bars""cards""compact""versus""bars"
multiple

Allow more than one choice (checkboxes).

booleanfalse
maxChoices

With multiple: the most choices one voter can pick.

number—
value

The viewer's choice (controlled). After voting, it marks "Your vote" in the results.

string[]—
defaultValue

Initial choice (uncontrolled).

string[][]
onValueChange

Called when the viewer's choice changes, before or as they vote.

(value: string[]) => void—
voted

Whether the viewer has voted (controlled). Use with onVotedChange.

boolean—
defaultVoted

Initial voted state (uncontrolled), e.g. true when the server says they already voted.

booleanfalse
onVotedChange

Called when the voted state changes (after a vote, or on "Change vote").

(voted: boolean) => void—
onVote

Called with the chosen values when the viewer votes. Return a promise to show a loading state; if it rejects, the poll stays in the voting phase (show your own error message).

(values: string[]) => void | Promise<void>—
submitMode

button: choose, then press Vote. instant: clicking a choice votes (single choice only; each choice is a button).

"button""instant""instant" for a single choice, "button" with `multiple`
showResults

When results show: after-vote, always (results only, no voting), or never (only once the poll is closed, which avoids bandwagon voting).

"after-vote""always""never""after-vote"
closed

The poll is over: voting is off and the final results show. Also true once endsAt passes.

booleanfalse
endsAt

When voting ends: an ISO date ("2026-12-01", the end of that day) or date-time. Shown as "Ends in 3 days".

string—
totalVotes

Total votes, when it differs from the sum of votes (e.g. multiple choice counts voters).

number—
allowChangeVote

Show a "Change vote" button in the results while the poll is open.

booleanfalse
highlightWinner

Mark the sole leader with a "Leading" (or "Winner") tag and bold label.

booleantrue
headingLevel

Heading level of the question.

234563
size

Text and control size.

"sm""md""lg""md"
labels

Overrides the built-in text (vote button, tags, footer, announcements). Localize it here.

Partial<{ vote: string; changeVote: string; yourVote: string; leading: string; winner: string; finalResults: string; versus: string; }>—

Also accepts native <div> attributes, plus className, style and ref.

See what changed in each version in the Changelog.

Accessibility report

Poll targets WCAG 2.2 AA. Below: a live axe-core audit of this page's examples, Lighthouse scores for the page in both modes, the accessibility behavior built into the component, and the checks only a person can do.

axe-core audit (live)

Running accessibility audit

Checking the examples above…

Lighthouse audit

Light mode

Score 100

36 passed · 0 failed · 29 not applicable · 10 to check by hand

Dark mode

Score 100

36 passed · 0 failed · 29 not applicable · 10 to check by hand

Lighthouse 13.5.0 audits the whole docs page (header and sidebar included), not just the examples, in English. Last run 11/27/2026. Some failed audits carry no weight in the score, so a page can score 100 and still list one.

Built-in behavior

Keyboard

Keyboard
KeyAction
TabMoves through the choices (instant voting: each is a button; with a Vote button: one radio group, or each checkbox), the Vote button and, in the results, "Change vote".
EnterSpaceInstant voting: votes for the focused choice. Otherwise Space checks a choice and Enter or the Vote button votes.
Arrow keysSingle choice with a Vote button: moves between the radios.

After a vote, the choices are replaced by the results, so focus moves to the results group and they're announced ("Vote recorded" and each share). With maxChoices, the remaining choices are disabled once the limit is reached, and the limit is in the group's description.

Roles and states

Roles and states
ElementRoleStates and properties
QuestionheadingLevel from headingLevel (3); names the choices and the results
Choices (button voting)group (<fieldset>)aria-labelledby (the question), aria-describedby ("Choose up to 2 options")
Choice (instant voting)buttonaria-pressed on the recorded choice
Resultsgrouparia-labelledby (the question), tabindex="-1" to receive focus; a list named "Results"
Vote announcementstatusThe library's shared polite live region (aria-live="polite"): "Vote recorded." and the results
Bars, split bar and medianonearia-hidden; every share is printed as text

Manual checks

Automated tools find roughly a third of accessibility issues. Test these in your app, with your content.

Manual accessibility checks
CheckWhat to testWCAG 2.2
KeyboardEvery action works with Tab, Shift+Tab, Enter, Space and the arrow keys, and focus never gets stuck.2.1.1 (A), 2.1.2 (A)
FocusFocus moves in a logical order, is always visible, and isn't hidden behind sticky headers.2.4.3 (A), 2.4.7 (AA), 2.4.11 (AA), 2.4.13 (AAA)
Screen readersNames, roles and states are announced correctly, and status changes are announced without moving focus.1.3.1 (A), 4.1.2 (A), 4.1.3 (AA)
ColorMeaning never depends on color alone; your own colors meet contrast in both modes.1.4.1 (A), 1.4.3 (AA), 1.4.11 (AA), 1.4.6 (AAA)
Zoom and reflowAt 200% text size and at 320px wide (400% zoom), nothing is cut off and no sideways scrolling is needed.1.4.4 (AA), 1.4.10 (AA), 1.4.12 (AA)
Pointer targetsClick and tap targets are at least 24×24px (44×44px for AAA), or spaced so they don't overlap.2.5.8 (AA), 2.5.5 (AAA)
MotionAnimations respect the reduced-motion setting.2.3.3 (AAA)