Data display
Poll
Free15.9 KB gzippedA 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
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
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.
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.
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
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?
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?
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.
Ava Thompson 44%, Marcus Lee 36%, Jordan Diaz 20%
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
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| Prop | Type | Default |
|---|---|---|
questionRequiredThe question, rendered as a heading (see | ReactNode | — |
optionsRequiredThe choices, with their vote counts. Update | PollOption[] | — |
layoutLayout of both phases. | "bars""cards""compact""versus" | "bars" |
multipleAllow more than one choice (checkboxes). | boolean | false |
maxChoicesWith | number | — |
valueThe viewer's choice (controlled). After voting, it marks "Your vote" in the results. | string[] | — |
defaultValueInitial choice (uncontrolled). | string[] | [] |
onValueChangeCalled when the viewer's choice changes, before or as they vote. | (value: string[]) => void | — |
votedWhether the viewer has voted (controlled). Use with | boolean | — |
defaultVotedInitial voted state (uncontrolled), e.g. | boolean | false |
onVotedChangeCalled when the voted state changes (after a vote, or on "Change vote"). | (voted: boolean) => void | — |
onVoteCalled 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""instant" | "instant" for a single choice, "button" with `multiple` |
showResultsWhen results show: | "after-vote""always""never" | "after-vote" |
closedThe poll is over: voting is off and the final results show. Also true once | boolean | false |
endsAtWhen voting ends: an ISO date ("2026-12-01", the end of that day) or date-time. Shown as "Ends in 3 days". | string | — |
totalVotesTotal votes, when it differs from the sum of | number | — |
allowChangeVoteShow a "Change vote" button in the results while the poll is open. | boolean | false |
highlightWinnerMark the sole leader with a "Leading" (or "Winner") tag and bold label. | boolean | true |
headingLevelHeading level of the question. | 23456 | 3 |
sizeText and control size. | "sm""md""lg" | "md" |
labelsOverrides 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)
Checking the examples above…
Lighthouse audit
Light mode
Score 10036 passed · 0 failed · 29 not applicable · 10 to check by hand
Dark mode
Score 10036 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
| Key | Action |
|---|---|
| Tab | Moves 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". |
| EnterSpace | Instant voting: votes for the focused choice. Otherwise Space checks a choice and Enter or the Vote button votes. |
| Arrow keys | Single 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
| Element | Role | States and properties |
|---|---|---|
| Question | heading | Level 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) | button | aria-pressed on the recorded choice |
| Results | group | aria-labelledby (the question), tabindex="-1" to receive focus; a list named "Results" |
| Vote announcement | status | The library's shared polite live region (aria-live="polite"): "Vote recorded." and the results |
| Bars, split bar and media | none | aria-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.
| Check | What to test | WCAG 2.2 |
|---|---|---|
| Keyboard | Every 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) |
| Focus | Focus 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 readers | Names, 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) |
| Color | Meaning 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 reflow | At 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 targets | Click 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) |
| Motion | Animations respect the reduced-motion setting. | 2.3.3 (AAA) |