0.7.4 gives the Ambient pack weather. A page names one feed URL on its own site, and the pack sets data-weather from it, uses its sunrise and sunset for dawn and dusk, and never shows a stale observation. Helpers for producing the feed from Open-Meteo are included. Ambient p…
Voting + live results with single/multi-choice and closed state. Per-option counts and own-vote flag; presentational, mirrors the reaction-bar author-owned-state pattern.
Overview
<poll-wc> is a voting + live-results primitive. Authors render options as <button data-option data-count [data-mine]> children with an optional <span slot="question">. The component renders the question, the option list with result bars, and a live total-vote count.
Like <reaction-bar>, the component is presentational: it emits poll-wc:vote and lets authors make the backend call. After the server confirms, authors call setCount(option, count, { mine }) to update the chip.
When to use which primitive
Use this
When
<poll-wc>
Question + labeled voting options + live result bars + per-user vote flag.
Renders charts from data. <poll-wc> combines voting with result visualization in one widget.
Author surface
Single-choice poll
1234567
<poll-wc><spanslot="question">When should we ship?</span><buttondata-option="friday"data-count="12">Friday</button><buttondata-option="next-mon"data-count="33"data-mine>Next Monday</button><buttondata-option="next-fri"data-count="8">Next Friday</button><buttondata-option="never"data-count="2">Never</button></poll-wc>
Each option carries a stable data-option id (sent in events), the current vote data-count, and an optional data-mine flag for the current user's vote. The button content is the visible label; inline markup inside it (<strong>, an icon) is kept. Each option shows its count and its share of the total, for example 33 · 60%.
Without JavaScript: enhance a native form
Bare buttons do nothing without JavaScript. For a poll that still works then, author an ordinary form inside <poll-wc>. It submits to your server as is; when the component upgrades it replaces the form with the button form:
<legend> becomes the question.
Each <input type="radio"> or type="checkbox" becomes an option: value → data-option, data-count is copied, checked → data-mine, and the <label> content (wrapping, or linked with for) becomes the option label.
Any checkbox makes the poll data-multi; <fieldset disabled> makes it data-closed.
Everything else in the form (submit button, an <output> with server-rendered totals) is dropped, so it can carry no-JS-only content.
Form fallback
1234567891011
<poll-wc><formaction="/polls/theme"method="post"><fieldset><legend>Default theme for new sites?</legend><label><inputtype="radio"name="vote"value="light"data-count="18"> Light</label><label><inputtype="radio"name="vote"value="dark"data-count="27"> Dark</label><label><inputtype="radio"name="vote"value="system"data-count="41"checked> Follow the system</label><buttontype="submit">Vote</button></fieldset></form></poll-wc>
Multi-choice
Set data-multi to allow voting for multiple options. ARIA shifts from radiogroup + radio to group + checkbox.
Multi-choice
1234567
<poll-wcdata-multi><spanslot="question">Which features matter to you? (pick any)</span><buttondata-option="dark"data-count="80"data-mine>Dark mode</button><buttondata-option="i18n"data-count="55">i18n</button><buttondata-option="offline"data-count="40"data-mine>Offline</button><buttondata-option="oauth"data-count="30">OAuth</button></poll-wc>
Closed state
Set data-closed for results-only display (no voting). Use poll.close() / poll.open() to toggle programmatically when a deadline passes; the component fires poll-wc:closed-change.
Closed poll
123456
<poll-wcdata-closed><spanslot="question">Best win this quarter?</span><buttondata-option="ship"data-count="22">Shipping VB 1.0</button><buttondata-option="onboard"data-count="9">Onboarding revamp</button><buttondata-option="docs"data-count="14">Docs rewrite</button></poll-wc>
Wiring the backend
<poll-wc> never talks to a server and stores nothing. De-duplicating votes and remembering who voted are your server's job (a session, account or signed cookie) — render data-mine from that on page load. The component only guards against double submits on the client:
When a vote is emitted, the option gets data-pending and the option group aria-busy="true". Further clicks are ignored — for the whole poll in single-choice mode, for that option in multi-choice mode.
setCount() or setCounts() clears the flag. Call it when the request fails too, with the old values, to roll back. In single-choice mode any setCount() releases the poll.
Single-choice with confirmation and rollback
123456789101112131415161718
const poll = document.querySelector('poll-wc');poll.addEventListener('poll-wc:vote', async (e) => {const { option, action, count, mine } = e.detail;// Switching options emits a `remove` for the old choice, then an `add`.// The two handlers run concurrently, so each request must be independent// (or switch to one PUT /vote request on the `add` and ignore `remove`).try {const res = awaitfetch(`/polls/123/votes/${encodeURIComponent(option)}`, {method: action === 'add' ? 'POST' : 'DELETE', });if (!res.ok) thrownewError(`HTTP ${res.status}`);const { count: newCount } = await res.json(); poll.setCount(option, newCount, { mine: action === 'add' }); } catch { poll.setCount(option, count, { mine }); // roll back, clears data-pending }});
Clicking your current selection again → poll-wc:vote with action: "remove" (un-vote).
Clicking a different option → first emits action: "remove" for your previous choice, then action: "add" for the new one. Two events fire in that order.
Multi-choice mode treats each option independently:
Clicking an option toggles its own state. No cross-option events.
Accessibility
Single-choice: options live in a role="radiogroup" with role="radio" + aria-checked on each option.
Multi-choice: options live in a role="group" with role="checkbox" + aria-checked on each option.
Group name: the option group is named by the question (aria-labelledby). Without a question, an aria-label on the host moves onto the group (the host itself has no role and cannot be named); with neither, the group is labelled Poll (data-label-poll).
Total readout: the total-vote count lives in an <output> with aria-live="polite", so screen readers announce it on changes.
Per-option label: derived aria-label like Next Monday, 33 votes, 60%, your choice, formatted with Intl.NumberFormat and Intl.PluralRules for the nearest lang.
Hidden counts:data-hide-counts removes counts, percentages and bars, for sighted and screen-reader users alike. The total still shows.
Closed / disabled: options get aria-disabled="true"; focus and arrow keys still work for browsing. The total reads 45 votes · closed as real text.
Keyboard, single-choice (APG radio group): one Tab stop (roving tabindex). Arrow keys move focus between options and never vote; Left/Right follow reading direction (flipped in RTL), and Home / End jump to first / last. Space or Enter votes for the focused option, or withdraws the vote if it is already your choice. This departs from the APG radio group, where moving focus also checks the option: a vote is sent to your server, so it has to be an explicit action.
Keyboard, multi-choice (APG checkbox): every option is a Tab stop; Space / Enter toggles it. Arrow keys are not used.
Forced colors: bars become a Highlight strip along the bottom of each option, and your own choice gets a thicker border.