투표
답변, 게시물, 댓글의 점수를 독자가 1점 올리거나 내릴 수 있는 컴포넌트입니다.
이 페이지의 내용
투표 컴포넌트는 독자가 답변, 게시물, 댓글의 점수를 1점 올리거나 내릴 수 있게 합니다. 두 화살표는 같은 그룹에 속한 네이티브 라디오 버튼이며, 눈에 띄지 않는 정사각형 버튼으로 표시됩니다. 두 버튼 사이의 점수는 CSS 카운터로 표시되므로 스크립트 없이도 버튼을 누르면 숫자가 바뀝니다.
투표
<article class="sheet max-w(440) w-full flex items-start gap-sm p(12)"> <fieldset class="vote" aria-label="Vote on this answer" style="--votes: 41"> <input type="radio" class="vote-up" name="answer-vote" value="up" aria-label="Upvote"> <output class="vote-score"></output> <input type="radio" class="vote-down" name="answer-vote" value="down" aria-label="Downvote"> </fieldset> <div class="flex flex-col gap(4) pt(6) pr(8)"> <p class="m(0) text-sm font-medium fg-text-strong">Put the focus ring on the group</p> <p class="m(0) text-sm fg-text-body"> A mask cuts the element it is drawn on, ring and all. Draw the ring on the container while one of its inputs has focus. </p> </div></article><article className="sheet max-w(440) w-full flex items-start gap-sm p(12)"> <fieldset className="vote" aria-label="Vote on this answer" style={{ '--votes': '41' } as React.CSSProperties}> <input type="radio" className="vote-up" name="answer-vote" value="up" aria-label="Upvote" /> <output className="vote-score"></output> <input type="radio" className="vote-down" name="answer-vote" value="down" aria-label="Downvote" /> </fieldset> <div className="flex flex-col gap(4) pt(6) pr(8)"> <p className="m(0) text-sm font-medium fg-text-strong">Put the focus ring on the group</p> <p className="m(0) text-sm fg-text-body"> A mask cuts the element it is drawn on, ring and all. Draw the ring on the container while one of its inputs has focus. </p> </div></article><article class="sheet max-w(440) w-full flex items-start gap-sm p(12)"> <fieldset class="vote" aria-label="Vote on this answer" style="--votes: 41"> <input type="radio" class="vote-up" name="answer-vote" value="up" aria-label="Upvote"> <output class="vote-score"></output> <input type="radio" class="vote-down" name="answer-vote" value="down" aria-label="Downvote"> </fieldset> <div class="flex flex-col gap(4) pt(6) pr(8)"> <p class="m(0) text-sm font-medium fg-text-strong">Put the focus ring on the group</p> <p class="m(0) text-sm fg-text-body"> A mask cuts the element it is drawn on, ring and all. Draw the ring on the container while one of its inputs has focus. </p> </div></article><template> <article class="sheet max-w(440) w-full flex items-start gap-sm p(12)"> <fieldset class="vote" aria-label="Vote on this answer" style="--votes: 41"> <input type="radio" class="vote-up" name="answer-vote" value="up" aria-label="Upvote"> <output class="vote-score"></output> <input type="radio" class="vote-down" name="answer-vote" value="down" aria-label="Downvote"> </fieldset> <div class="flex flex-col gap(4) pt(6) pr(8)"> <p class="m(0) text-sm font-medium fg-text-strong">Put the focus ring on the group</p> <p class="m(0) text-sm fg-text-body"> A mask cuts the element it is drawn on, ring and all. Draw the ring on the container while one of its inputs has focus. </p> </div> </article></template>#점수
그룹의 --votes에는 현재 독자의 투표를 제외한 점수를 설정합니다. 위쪽 화살표가 선택되면 1점이 더해지고 아래쪽 화살표가 선택되면 1점이 빠집니다. 페이지에서 독자가 어느 쪽에 투표했는지 알고 있다면 해당 화살표를 선택하고 나머지 독자의 투표만 반영한 점수를 설정합니다. vote-score 요소를 비워 두면 카운터가 점수를 표시하며, 음수에는 마이너스 기호(−)를 사용합니다. 1점 단위로 표시하기에는 점수가 너무 크다면 1.4k처럼 표시할 텍스트를 요소 안에 직접 작성합니다.
#가로 배치
vote-horizontal은 점수 양옆에 화살표를 배치합니다. 댓글 아래에 여러 동작을 한 줄로 배치할 때 사용할 수 있습니다. 점수 영역은 숫자 세 자리 너비를 유지하므로 점수가 바뀌어도 화살표가 움직이지 않습니다.
가로 배치
<div class="card max-w(480) mx-auto"> <ol class="thread"> <li class="thread-item"> <span class="thread-avatar"><span class="avatar">KJ</span></span> <div class="thread-body"> <p class="thread-header"> <span class="thread-author">Katherine Johnson</span> <time class="thread-meta" datetime="2026-11-12T10:54">12m</time> </p> <p class="thread-text"> The figures in the second table are right. The third needs another pass. </p> <div class="flex items-center gap(4) mt(6) ml(-8)"> <fieldset class="vote vote-horizontal" aria-label="Vote on this comment" style="--votes: 12"> <input type="radio" class="vote-up" name="comment-vote" value="up" aria-label="Upvote" checked> <output class="vote-score"></output> <input type="radio" class="vote-down" name="comment-vote" value="down" aria-label="Downvote"> </fieldset> <button type="button" class="btn btn-quiet btn-sm">Reply</button> </div> </div> </li> </ol></div><div className="card max-w(480) mx-auto"> <ol className="thread"> <li className="thread-item"> <span className="thread-avatar"><span className="avatar">KJ</span></span> <div className="thread-body"> <p className="thread-header"> <span className="thread-author">Katherine Johnson</span> <time className="thread-meta" dateTime="2026-11-12T10:54">12m</time> </p> <p className="thread-text"> The figures in the second table are right. The third needs another pass. </p> <div className="flex items-center gap(4) mt(6) ml(-8)"> <fieldset className="vote vote-horizontal" aria-label="Vote on this comment" style={{ '--votes': '12' } as React.CSSProperties}> <input type="radio" className="vote-up" name="comment-vote" value="up" aria-label="Upvote" defaultChecked /> <output className="vote-score"></output> <input type="radio" className="vote-down" name="comment-vote" value="down" aria-label="Downvote" /> </fieldset> <button type="button" className="btn btn-quiet btn-sm">Reply</button> </div> </div> </li> </ol></div><div class="card max-w(480) mx-auto"> <ol class="thread"> <li class="thread-item"> <span class="thread-avatar"><span class="avatar">KJ</span></span> <div class="thread-body"> <p class="thread-header"> <span class="thread-author">Katherine Johnson</span> <time class="thread-meta" datetime="2026-11-12T10:54">12m</time> </p> <p class="thread-text"> The figures in the second table are right. The third needs another pass. </p> <div class="flex items-center gap(4) mt(6) ml(-8)"> <fieldset class="vote vote-horizontal" aria-label="Vote on this comment" style="--votes: 12"> <input type="radio" class="vote-up" name="comment-vote" value="up" aria-label="Upvote" checked> <output class="vote-score"></output> <input type="radio" class="vote-down" name="comment-vote" value="down" aria-label="Downvote"> </fieldset> <button type="button" class="btn btn-quiet btn-sm">Reply</button> </div> </div> </li> </ol></div><template> <div class="card max-w(480) mx-auto"> <ol class="thread"> <li class="thread-item"> <span class="thread-avatar"><span class="avatar">KJ</span></span> <div class="thread-body"> <p class="thread-header"> <span class="thread-author">Katherine Johnson</span> <time class="thread-meta" datetime="2026-11-12T10:54">12m</time> </p> <p class="thread-text"> The figures in the second table are right. The third needs another pass. </p> <div class="flex items-center gap(4) mt(6) ml(-8)"> <fieldset class="vote vote-horizontal" aria-label="Vote on this comment" style="--votes: 12"> <input type="radio" class="vote-up" name="comment-vote" value="up" aria-label="Upvote" checked> <output class="vote-score"></output> <input type="radio" class="vote-down" name="comment-vote" value="down" aria-label="Downvote"> </fieldset> <button type="button" class="btn btn-quiet btn-sm">Reply</button> </div> </div> </li> </ol> </div></template>#상태
기본 상태에서는 배경 없이 옅은 잉크색 윤곽선으로 화살표를 표시합니다. 포인터를 올리면 작은 판처럼 떠오르고, 누르는 동안에는 오목하게 들어가며, 선택되면 잉크색으로 채워집니다. 위쪽과 아래쪽 화살표는 색상 대신 방향으로 구분합니다. 독자 본인의 게시물처럼 투표할 수 없는 점수를 표시하려면 fieldset을 비활성화합니다. 화살표는 흐려지고 점수는 그대로 표시됩니다.
상태
<fieldset class="vote" aria-label="Vote on this answer" style="--votes: 3"> <input type="radio" class="vote-up" name="vote-down-state" value="up" aria-label="Upvote"> <output class="vote-score"></output> <input type="radio" class="vote-down" name="vote-down-state" value="down" aria-label="Downvote" checked></fieldset><fieldset class="vote" aria-label="Vote on this answer" style="--votes: -2"> <input type="radio" class="vote-up" name="vote-negative" value="up" aria-label="Upvote"> <output class="vote-score"></output> <input type="radio" class="vote-down" name="vote-negative" value="down" aria-label="Downvote"></fieldset><fieldset class="vote" aria-label="Votes on your answer" disabled> <input type="radio" class="vote-up" name="vote-own" value="up" aria-label="Upvote"> <output class="vote-score">1.4k</output> <input type="radio" class="vote-down" name="vote-own" value="down" aria-label="Downvote"></fieldset><> <fieldset className="vote" aria-label="Vote on this answer" style={{ '--votes': '3' } as React.CSSProperties}> <input type="radio" className="vote-up" name="vote-down-state" value="up" aria-label="Upvote" /> <output className="vote-score"></output> <input type="radio" className="vote-down" name="vote-down-state" value="down" aria-label="Downvote" defaultChecked /> </fieldset> <fieldset className="vote" aria-label="Vote on this answer" style={{ '--votes': '-2' } as React.CSSProperties}> <input type="radio" className="vote-up" name="vote-negative" value="up" aria-label="Upvote" /> <output className="vote-score"></output> <input type="radio" className="vote-down" name="vote-negative" value="down" aria-label="Downvote" /> </fieldset> <fieldset className="vote" aria-label="Votes on your answer" disabled> <input type="radio" className="vote-up" name="vote-own" value="up" aria-label="Upvote" /> <output className="vote-score">1.4k</output> <input type="radio" className="vote-down" name="vote-own" value="down" aria-label="Downvote" /> </fieldset></><fieldset class="vote" aria-label="Vote on this answer" style="--votes: 3"> <input type="radio" class="vote-up" name="vote-down-state" value="up" aria-label="Upvote"> <output class="vote-score"></output> <input type="radio" class="vote-down" name="vote-down-state" value="down" aria-label="Downvote" checked></fieldset><fieldset class="vote" aria-label="Vote on this answer" style="--votes: -2"> <input type="radio" class="vote-up" name="vote-negative" value="up" aria-label="Upvote"> <output class="vote-score"></output> <input type="radio" class="vote-down" name="vote-negative" value="down" aria-label="Downvote"></fieldset><fieldset class="vote" aria-label="Votes on your answer" disabled> <input type="radio" class="vote-up" name="vote-own" value="up" aria-label="Upvote"> <output class="vote-score">1.4k</output> <input type="radio" class="vote-down" name="vote-own" value="down" aria-label="Downvote"></fieldset><template> <fieldset class="vote" aria-label="Vote on this answer" style="--votes: 3"> <input type="radio" class="vote-up" name="vote-down-state" value="up" aria-label="Upvote"> <output class="vote-score"></output> <input type="radio" class="vote-down" name="vote-down-state" value="down" aria-label="Downvote" checked> </fieldset> <fieldset class="vote" aria-label="Vote on this answer" style="--votes: -2"> <input type="radio" class="vote-up" name="vote-negative" value="up" aria-label="Upvote"> <output class="vote-score"></output> <input type="radio" class="vote-down" name="vote-negative" value="down" aria-label="Downvote"> </fieldset> <fieldset class="vote" aria-label="Votes on your answer" disabled> <input type="radio" class="vote-up" name="vote-own" value="up" aria-label="Upvote"> <output class="vote-score">1.4k</output> <input type="radio" class="vote-down" name="vote-own" value="down" aria-label="Downvote"> </fieldset></template>#투표 취소
라디오 버튼은 다시 눌러도 선택이 해제되지 않으므로 스크립트 없이는 투표를 바꿀 수만 있습니다. vote 동작을 사용하면 선택된 화살표를 다시 누르거나 해당 화살표에서 스페이스바를 눌러 투표를 취소할 수 있습니다. 점수는 --votes에 설정한 값으로 돌아갑니다.
투표 취소
<fieldset class="vote" id="vote-clear" aria-label="Vote on this answer" style="--votes: 7"> <input type="radio" class="vote-up" name="vote-clear" value="up" aria-label="Upvote" checked> <output class="vote-score"></output> <input type="radio" class="vote-down" name="vote-clear" value="down" aria-label="Downvote"></fieldset><script type="module"> import { attach } from '@master/ui/behaviors' attach()</script>import { useEffect, useRef } from 'react'import { attach } from '@master/ui/behaviors'export function Example() { const root = useRef<HTMLFieldSetElement>(null) useEffect(() => attach(root.current!), []) return ( <fieldset ref={root} className="vote" id="vote-clear" aria-label="Vote on this answer" style={{ '--votes': '7' } as React.CSSProperties}> <input type="radio" className="vote-up" name="vote-clear" value="up" aria-label="Upvote" defaultChecked /> <output className="vote-score"></output> <input type="radio" className="vote-down" name="vote-clear" value="down" aria-label="Downvote" /> </fieldset> )}<script> import { attach } from '@master/ui/behaviors'</script><fieldset class="vote" id="vote-clear" aria-label="Vote on this answer" style="--votes: 7" {@attach attach}> <input type="radio" class="vote-up" name="vote-clear" value="up" aria-label="Upvote" checked> <output class="vote-score"></output> <input type="radio" class="vote-down" name="vote-clear" value="down" aria-label="Downvote"></fieldset><script setup>import { onMounted, onUnmounted, ref } from 'vue'import { attach } from '@master/ui/behaviors'const root = ref(null)let detachonMounted(() => { detach = attach(root.value) })onUnmounted(() => detach?.())</script><template> <fieldset ref="root" class="vote" id="vote-clear" aria-label="Vote on this answer" style="--votes: 7"> <input type="radio" class="vote-up" name="vote-clear" value="up" aria-label="Upvote" checked> <output class="vote-score"></output> <input type="radio" class="vote-down" name="vote-clear" value="down" aria-label="Downvote"> </fieldset></template>#접근성
aria-label또는<legend>를 사용해 그룹에 이름을 지정하고, 위쪽과 아래쪽 라디오 버튼에는 각각 ‘추천’과 ‘비추천’이라는 이름을 지정합니다.- 점수를
<output>에 넣습니다. 스크린 리더는 읽기 순서상 두 화살표 사이에서 점수를 읽고, 투표로 점수가 바뀌면 새 점수를 상태 메시지로 알립니다. - 화살표의 포커스 링은 온전히 표시됩니다. 화살표 기호를 가상 요소에 그리므로 마스크가 링을 잘라내지 않습니다. 일반적인 라디오 그룹과 마찬가지로 방향키를 누르면 두 라디오 버튼 사이에서 선택이 이동합니다.
- 각 화살표 버튼의 크기는 포인터 종류와 관계없이 32px이며, 터치스크린에서는 버튼을 포함한 조작 영역의 크기가 44px입니다. 강제 색상 모드에서는 화살표 기호에 버튼 텍스트 색상을 사용하고, 선택된 화살표에는 강조 색상을 사용합니다.
#클래스
| 클래스 | 설명 |
|---|---|
vote | 그룹은 aria-label 또는 legend로 이름을 지정한 fieldset에 배치합니다. 위쪽 화살표, 점수, 아래쪽 화살표를 세로로 쌓습니다. --votes에는 사용자의 투표를 제외한 점수를 설정하세요. |
vote-horizontal | 댓글 아래 작업 버튼 행에서 점수 양옆에 화살표를 배치합니다. 점수는 숫자 세 자리 너비를 유지합니다.적용할 클래스는 vote입니다 |
vote-up | 위쪽 화살표는 접근 가능한 이름이 "Upvote"인 라디오 버튼입니다. 은은한 32px 정사각형으로 표시되며, 선택되면 화살표가 전경색으로 채워집니다 |
vote-score | 요소가 비어 있으면 카운터가 --votes 값을 표시합니다. 위쪽 또는 아래쪽 화살표가 선택되면 각각 1을 더하거나 뺍니다. output 요소에서는 점수가 바뀔 때 스크린 리더가 변경된 점수를 읽습니다. 요소에 1.2k 같은 텍스트가 있으면 그 텍스트를 대신 표시합니다. |
vote-down | 아래쪽 화살표는 위쪽 화살표와 같은 name을 사용하는 라디오 버튼입니다. 접근 가능한 이름은 "Downvote"입니다. |
#사용자 지정 속성
| 속성 | 기본값 | 설명 |
|---|---|---|
--votes | 0 | 사용자 본인의 투표를 제외한 점수입니다. 선택된 화살표에 따라 1을 더하거나 뺍니다 |
--vote-size | 2rem | 각 화살표가 차지하는 정사각형의 한 변 길이. 터치 화면에서는 그 둘레의 조작 영역이 44px |