A poll's options as buttons, each filled by its share of the votes, the reader's own vote pressed.
<ul class="cap-poll" data-cap="poll" aria-label="Next book" id="pl-open">
<li><button type="button" class="cap-poll-option" data-votes="3" aria-pressed="true"><span class="cap-poll-label">Field notes</span><span class="cap-poll-count" aria-live="polite" aria-atomic="true">3<span class="cap-sr-only"> votes</span></span></button></li>
<li><button type="button" class="cap-poll-option" data-votes="1" aria-pressed="false"><span class="cap-poll-label">Annual report</span><span class="cap-poll-count" aria-live="polite" aria-atomic="true">1<span class="cap-sr-only"> vote</span></span></button></li>
<li><button type="button" class="cap-poll-option" data-votes="0" aria-pressed="false"><span class="cap-poll-label">Release notes</span><span class="cap-poll-count" aria-live="polite" aria-atomic="true">0<span class="cap-sr-only"> votes</span></span></button></li>
</ul>
Copy
View code
Installation
HTML and CSS React
// package.json: "capsomer": "github:DrDustinEdwards/capsomer#v0.152.2"
import "capsomer/tokens.css";
import "capsomer/base.css";
import "capsomer/poll.css";
import { enhance } from "capsomer/behavior/poll";
enhance();Copy
import "capsomer/tokens.css";
import "capsomer/poll.css";
import { Poll } from "capsomer/react/poll";Copy
Usage
<ul class="cap-poll" data-cap="poll" aria-label="Next book">
<li>
<button type="button" class="cap-poll-option" data-votes="3" aria-pressed="true">
<span class="cap-poll-label">Field notes</span>
<span class="cap-poll-count" aria-live="polite" aria-atomic="true">3<span class="cap-sr-only"> votes</span></span>
</button>
</li>
</ul>Copy
Examples
Closed
<ul class="cap-poll" data-cap="poll" aria-label="Meeting day" id="pl-closed">
<li><button type="button" class="cap-poll-option" data-votes="5" aria-pressed="false" disabled><span class="cap-poll-label">Tuesday</span><span class="cap-poll-count" aria-live="polite" aria-atomic="true">5<span class="cap-sr-only"> votes</span></span></button></li>
<li><button type="button" class="cap-poll-option" data-votes="5" aria-pressed="true" disabled><span class="cap-poll-label">Thursday</span><span class="cap-poll-count" aria-live="polite" aria-atomic="true">5<span class="cap-sr-only"> votes</span></span></button></li>
</ul>
Copy
No votes yet
<ul class="cap-poll" data-cap="poll" aria-label="Snack" id="pl-none">
<li><button type="button" class="cap-poll-option" data-votes="0" aria-pressed="false"><span class="cap-poll-label">Tea</span><span class="cap-poll-count" aria-live="polite" aria-atomic="true">0<span class="cap-sr-only"> votes</span></span></button></li>
<li><button type="button" class="cap-poll-option" data-votes="0" aria-pressed="false"><span class="cap-poll-label">Coffee</span><span class="cap-poll-count" aria-live="polite" aria-atomic="true">0<span class="cap-sr-only"> votes</span></span></button></li>
</ul>
Copy
API reference
Poll Prop Type Required Does optionsPollOption[]Yes minestring[]The reader's own vote or votes. onVote(id: string) => voidclosedbooleanpendingbooleanlabelstring
Functions Function Signature Does shares(votes: number[]): number[]The poll's one piece of behavior: each option's share of the votes as --share, through the CSSOM, so the page keeps style-src 'self'. Server-rendered options carry data-votes; the module reads them and sets the shares from the total. setShares(poll: ParentNode): voidenhance(root?: ParentNode): () => void
CSS variables
Parts and data attributes Class Is .cap-pollthe root .cap-poll-counta part .cap-poll-labela part .cap-poll-optiona part
State Read from :disabledthe platform :hoverthe platform [aria-pressed="true"]an attribute
Accessibility
Key Does Tab Moves from option to option Enter, Space Votes for the option
Pressed: an accent edge, bold and a stronger fill, not color alone; forced colors: a Highlight outline.