Vanilla Breeze v0.7.4

Vanilla Breeze v0.7.4 released

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…

Read the release notes

poll-wc

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 thisWhen
<poll-wc>Question + labeled voting options + live result bars + per-user vote flag.
<reaction-bar>Many small emoji icons toggled per-user — no question, no result chart.
<star-rating>Single 1–N rating, form-associated. Polls have arbitrary labelled options and don't submit with a form.
<form> + <input type="radio">Plain form input with no live results.
<chart-wc>Renders charts from data. <poll-wc> combines voting with result visualization in one widget.

Author surface

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.

Multi-choice

Set data-multi to allow voting for multiple options. ARIA shifts from radiogroup + radio to group + checkbox.

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.

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 vs multi event semantics

Single-choice mode handles option switching atomically:

  • 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.

Attributes

AttributeTypeDefaultDescription
aria-labelstring—Group label when there is no question; moved onto the option group.
data-multibooleanfalseAllow multiple selections.
data-closedbooleanfalseRead-only — show results, no voting.
data-hide-countsbooleanfalseHide per-option counts, percentages and bars (visually and from assistive tech).
disabledbooleanfalseDisables voting (dimmed, aria-disabled). Live: toggling it updates immediately.
data-label-vote / data-label-votesstringvote / votesCount noun; Intl.PluralRules picks the singular for the one category.
data-label-your-choicestringyour choiceAppended to the option's accessible name when data-mine is set.
data-label-closedstringclosedAppended to the total when closed.
data-label-pollstringPollFallback group name with no question and no aria-label.

Per-option attributes (on <button data-option>)

AttributeDescription
data-optionStable identifier sent in events (required).
data-countCurrent vote count.
data-mineCurrent user voted for this option.
data-pendingOutput: a vote for this option is in flight (cleared by setCount / setCounts).

Events

EventBubblesDetail
poll-wc:voteyes{ option, action: 'add'|'remove', count, mine }
poll-wc:closed-changeyes{ closed }

JavaScript API

MemberDescription
setCount(option, count, { mine })Update a single option after the server confirms (or roll back on failure). Clears data-pending.
setCounts(counts, { mine })Bulk-update from a server snapshot. mine can be a string (single-choice) or string[] (multi). Clears every data-pending.
open() / close()Toggle data-closed programmatically.
totalVotesSum of all option counts.
myVotesArray of option ids the current user voted for.

See also

↑