網站導覽

v2.1.0
內文

表情回應

用表情符號回應訊息。每個表情都顯示回應人數,按一下即可加入。

本頁內容

表情回應是讀者留在訊息下方的表情符號,旁邊會顯示有多少人用了同一個表情。每個回應都是平面的膠囊形控制項,採用膠囊標籤的底色,內含原生核取方塊。按一下即可加入自己的回應,再按一下即可收回。人數由 CSS 計數器依核取狀態增減,無須腳本。

表情回應

<ol class="max-w(400) w-full mx-auto m(0) p(0)">  <li class="message">    <span class="avatar avatar-sm message-avatar">      <img class="avatar-image" src="/demo/portrait-1.svg" alt="Ada">    </span>    <div class="message-bubble">The new previews are live. Have a look before the review.</div>    <div class="reaction-group" role="group" aria-label="Reactions to Ada's message">      <label class="reaction" style="--count: 3">        <input type="checkbox" class="reaction-input" name="reaction" value="👍" aria-label="Thumbs up, 3 others" checked>        <span class="reaction-emoji" aria-hidden="true">👍</span>        <span class="reaction-count" aria-hidden="true"></span>      </label>      <label class="reaction" style="--count: 2">        <input type="checkbox" class="reaction-input" name="reaction" value="🎉" aria-label="Party popper, 2 others">        <span class="reaction-emoji" aria-hidden="true">🎉</span>        <span class="reaction-count" aria-hidden="true"></span>      </label>      <label class="reaction" style="--count: 1">        <input type="checkbox" class="reaction-input" name="reaction" value="👀" aria-label="Eyes, 1 other">        <span class="reaction-emoji" aria-hidden="true">👀</span>        <span class="reaction-count" aria-hidden="true"></span>      </label>    </div>    <span class="message-meta">Ada · 14:03</span>  </li>  <li class="message message-sent">    <div class="message-bubble">On it. The dark ones look right.</div>    <div class="reaction-group" role="group" aria-label="Reactions to your message">      <label class="reaction" style="--count: 1">        <input type="checkbox" class="reaction-input" name="reaction-reply" value="❤️" aria-label="Heart, 1 other">        <span class="reaction-emoji" aria-hidden="true">❤️</span>        <span class="reaction-count" aria-hidden="true"></span>      </label>    </div>  </li></ol>
<ol className="max-w(400) w-full mx-auto m(0) p(0)">  <li className="message">    <span className="avatar avatar-sm message-avatar">      <img className="avatar-image" src="/demo/portrait-1.svg" alt="Ada" />    </span>    <div className="message-bubble">The new previews are live. Have a look before the review.</div>    <div className="reaction-group" role="group" aria-label="Reactions to Ada's message">      <label className="reaction" style={{ '--count': '3' } as React.CSSProperties}>        <input type="checkbox" className="reaction-input" name="reaction" value="👍" aria-label="Thumbs up, 3 others" defaultChecked />        <span className="reaction-emoji" aria-hidden="true">👍</span>        <span className="reaction-count" aria-hidden="true"></span>      </label>      <label className="reaction" style={{ '--count': '2' } as React.CSSProperties}>        <input type="checkbox" className="reaction-input" name="reaction" value="🎉" aria-label="Party popper, 2 others" />        <span className="reaction-emoji" aria-hidden="true">🎉</span>        <span className="reaction-count" aria-hidden="true"></span>      </label>      <label className="reaction" style={{ '--count': '1' } as React.CSSProperties}>        <input type="checkbox" className="reaction-input" name="reaction" value="👀" aria-label="Eyes, 1 other" />        <span className="reaction-emoji" aria-hidden="true">👀</span>        <span className="reaction-count" aria-hidden="true"></span>      </label>    </div>    <span className="message-meta">Ada · 14:03</span>  </li>  <li className="message message-sent">    <div className="message-bubble">On it. The dark ones look right.</div>    <div className="reaction-group" role="group" aria-label="Reactions to your message">      <label className="reaction" style={{ '--count': '1' } as React.CSSProperties}>        <input type="checkbox" className="reaction-input" name="reaction-reply" value="❤️" aria-label="Heart, 1 other" />        <span className="reaction-emoji" aria-hidden="true">❤️</span>        <span className="reaction-count" aria-hidden="true"></span>      </label>    </div>  </li></ol>
<ol class="max-w(400) w-full mx-auto m(0) p(0)">  <li class="message">    <span class="avatar avatar-sm message-avatar">      <img class="avatar-image" src="/demo/portrait-1.svg" alt="Ada">    </span>    <div class="message-bubble">The new previews are live. Have a look before the review.</div>    <div class="reaction-group" role="group" aria-label="Reactions to Ada's message">      <label class="reaction" style="--count: 3">        <input type="checkbox" class="reaction-input" name="reaction" value="👍" aria-label="Thumbs up, 3 others" checked>        <span class="reaction-emoji" aria-hidden="true">👍</span>        <span class="reaction-count" aria-hidden="true"></span>      </label>      <label class="reaction" style="--count: 2">        <input type="checkbox" class="reaction-input" name="reaction" value="🎉" aria-label="Party popper, 2 others">        <span class="reaction-emoji" aria-hidden="true">🎉</span>        <span class="reaction-count" aria-hidden="true"></span>      </label>      <label class="reaction" style="--count: 1">        <input type="checkbox" class="reaction-input" name="reaction" value="👀" aria-label="Eyes, 1 other">        <span class="reaction-emoji" aria-hidden="true">👀</span>        <span class="reaction-count" aria-hidden="true"></span>      </label>    </div>    <span class="message-meta">Ada · 14:03</span>  </li>  <li class="message message-sent">    <div class="message-bubble">On it. The dark ones look right.</div>    <div class="reaction-group" role="group" aria-label="Reactions to your message">      <label class="reaction" style="--count: 1">        <input type="checkbox" class="reaction-input" name="reaction-reply" value="❤️" aria-label="Heart, 1 other">        <span class="reaction-emoji" aria-hidden="true">❤️</span>        <span class="reaction-count" aria-hidden="true"></span>      </label>    </div>  </li></ol>
<template>  <ol class="max-w(400) w-full mx-auto m(0) p(0)">    <li class="message">      <span class="avatar avatar-sm message-avatar">        <img class="avatar-image" src="/demo/portrait-1.svg" alt="Ada">      </span>      <div class="message-bubble">The new previews are live. Have a look before the review.</div>      <div class="reaction-group" role="group" aria-label="Reactions to Ada's message">        <label class="reaction" style="--count: 3">          <input type="checkbox" class="reaction-input" name="reaction" value="👍" aria-label="Thumbs up, 3 others" checked>          <span class="reaction-emoji" aria-hidden="true">👍</span>          <span class="reaction-count" aria-hidden="true"></span>        </label>        <label class="reaction" style="--count: 2">          <input type="checkbox" class="reaction-input" name="reaction" value="🎉" aria-label="Party popper, 2 others">          <span class="reaction-emoji" aria-hidden="true">🎉</span>          <span class="reaction-count" aria-hidden="true"></span>        </label>        <label class="reaction" style="--count: 1">          <input type="checkbox" class="reaction-input" name="reaction" value="👀" aria-label="Eyes, 1 other">          <span class="reaction-emoji" aria-hidden="true">👀</span>          <span class="reaction-count" aria-hidden="true"></span>        </label>      </div>      <span class="message-meta">Ada · 14:03</span>    </li>    <li class="message message-sent">      <div class="message-bubble">On it. The dark ones look right.</div>      <div class="reaction-group" role="group" aria-label="Reactions to your message">        <label class="reaction" style="--count: 1">          <input type="checkbox" class="reaction-input" name="reaction-reply" value="❤️" aria-label="Heart, 1 other">          <span class="reaction-emoji" aria-hidden="true">❤️</span>          <span class="reaction-count" aria-hidden="true"></span>        </label>      </div>    </li>  </ol></template>
按一下表情即可加入回應,再按一下即可收回。

將 reaction-group 放在訊息泡泡後方。群組放在收到的訊息下方時,與泡泡的起始端對齊;放在送出的訊息下方時,則與泡泡的結束端對齊。用 aria-label 為群組命名。畫面上有多則訊息時,請說明這組表情回應的是誰的訊息。

#回應人數

在每個表情回應上設定 --count,填入其他人的回應人數,不包含讀者本人。膠囊以這個數字作為計數器的起點,核取後加一,因此讀者已加入的表情回應會比 --count 多顯示一人。將 reaction-count 留空,計數器就會填入數字。如果人數太多,不適合逐一計數,可在裡面填入 1.2k 等文字,畫面便會改為顯示這段文字。

#狀態

平時,表情回應是帶有一道外框的平面膠囊,人數以低對比色顯示。指標移到上方時,外框會更明顯。按下時,膠囊會下沉,表情符號也會跟著往內壓。加入回應後,元件會套用元件庫的選取樣式,以文字色繪製細框,底色帶有淡淡的文字色,人數則以高對比文字色顯示。核取方塊停用時,例如討論串已關閉,膠囊會維持平面,表情符號也會淡化。

狀態

<div class="reaction-group" role="group" aria-label="Reactions">  <label class="reaction" style="--count: 2">    <input type="checkbox" class="reaction-input" name="reaction-states" value="👏" aria-label="Clapping, 2 others">    <span class="reaction-emoji" aria-hidden="true">👏</span>    <span class="reaction-count" aria-hidden="true"></span>  </label>  <label class="reaction" style="--count: 2">    <input type="checkbox" class="reaction-input" name="reaction-states" value="❤️" aria-label="Heart, 2 others" checked>    <span class="reaction-emoji" aria-hidden="true">❤️</span>    <span class="reaction-count" aria-hidden="true"></span>  </label>  <label class="reaction">    <input type="checkbox" class="reaction-input" name="reaction-states" value="🔥" aria-label="Fire, 1,214 others">    <span class="reaction-emoji" aria-hidden="true">🔥</span>    <span class="reaction-count" aria-hidden="true">1.2k</span>  </label>  <label class="reaction" style="--count: 4">    <input type="checkbox" class="reaction-input" name="reaction-states" value="👍" aria-label="Thumbs up, 4 others" disabled>    <span class="reaction-emoji" aria-hidden="true">👍</span>    <span class="reaction-count" aria-hidden="true"></span>  </label></div>
<div className="reaction-group" role="group" aria-label="Reactions">  <label className="reaction" style={{ '--count': '2' } as React.CSSProperties}>    <input type="checkbox" className="reaction-input" name="reaction-states" value="👏" aria-label="Clapping, 2 others" />    <span className="reaction-emoji" aria-hidden="true">👏</span>    <span className="reaction-count" aria-hidden="true"></span>  </label>  <label className="reaction" style={{ '--count': '2' } as React.CSSProperties}>    <input type="checkbox" className="reaction-input" name="reaction-states" value="❤️" aria-label="Heart, 2 others" defaultChecked />    <span className="reaction-emoji" aria-hidden="true">❤️</span>    <span className="reaction-count" aria-hidden="true"></span>  </label>  <label className="reaction">    <input type="checkbox" className="reaction-input" name="reaction-states" value="🔥" aria-label="Fire, 1,214 others" />    <span className="reaction-emoji" aria-hidden="true">🔥</span>    <span className="reaction-count" aria-hidden="true">1.2k</span>  </label>  <label className="reaction" style={{ '--count': '4' } as React.CSSProperties}>    <input type="checkbox" className="reaction-input" name="reaction-states" value="👍" aria-label="Thumbs up, 4 others" disabled />    <span className="reaction-emoji" aria-hidden="true">👍</span>    <span className="reaction-count" aria-hidden="true"></span>  </label></div>
<div class="reaction-group" role="group" aria-label="Reactions">  <label class="reaction" style="--count: 2">    <input type="checkbox" class="reaction-input" name="reaction-states" value="👏" aria-label="Clapping, 2 others">    <span class="reaction-emoji" aria-hidden="true">👏</span>    <span class="reaction-count" aria-hidden="true"></span>  </label>  <label class="reaction" style="--count: 2">    <input type="checkbox" class="reaction-input" name="reaction-states" value="❤️" aria-label="Heart, 2 others" checked>    <span class="reaction-emoji" aria-hidden="true">❤️</span>    <span class="reaction-count" aria-hidden="true"></span>  </label>  <label class="reaction">    <input type="checkbox" class="reaction-input" name="reaction-states" value="🔥" aria-label="Fire, 1,214 others">    <span class="reaction-emoji" aria-hidden="true">🔥</span>    <span class="reaction-count" aria-hidden="true">1.2k</span>  </label>  <label class="reaction" style="--count: 4">    <input type="checkbox" class="reaction-input" name="reaction-states" value="👍" aria-label="Thumbs up, 4 others" disabled>    <span class="reaction-emoji" aria-hidden="true">👍</span>    <span class="reaction-count" aria-hidden="true"></span>  </label></div>
<template>  <div class="reaction-group" role="group" aria-label="Reactions">    <label class="reaction" style="--count: 2">      <input type="checkbox" class="reaction-input" name="reaction-states" value="👏" aria-label="Clapping, 2 others">      <span class="reaction-emoji" aria-hidden="true">👏</span>      <span class="reaction-count" aria-hidden="true"></span>    </label>    <label class="reaction" style="--count: 2">      <input type="checkbox" class="reaction-input" name="reaction-states" value="❤️" aria-label="Heart, 2 others" checked>      <span class="reaction-emoji" aria-hidden="true">❤️</span>      <span class="reaction-count" aria-hidden="true"></span>    </label>    <label class="reaction">      <input type="checkbox" class="reaction-input" name="reaction-states" value="🔥" aria-label="Fire, 1,214 others">      <span class="reaction-emoji" aria-hidden="true">🔥</span>      <span class="reaction-count" aria-hidden="true">1.2k</span>    </label>    <label class="reaction" style="--count: 4">      <input type="checkbox" class="reaction-input" name="reaction-states" value="👍" aria-label="Thumbs up, 4 others" disabled>      <span class="reaction-emoji" aria-hidden="true">👍</span>      <span class="reaction-count" aria-hidden="true"></span>    </label>  </div></template>

#新增表情回應

reaction-add 是列尾帶有臉部圖示和加號的圓形按鈕,用來開啟頁面的表情符號選擇器。選擇器是由低調的方形按鈕組成的彈出面板,每個按鈕都包含一個 reaction-emoji。緊接在按鈕後方的彈出面板開啟時,按鈕會維持下沉狀態。選取表情符號即可加入回應。如果還沒有人用過該表情,頁面也要新增對應的膠囊,因此選擇器需要幾行腳本處理這一步。本頁其餘功能都無須腳本。

新增表情回應

<div class="reaction-group" id="reactions" role="group" aria-label="Reactions">  <label class="reaction" style="--count: 4">    <input type="checkbox" class="reaction-input" name="reaction" value="👍" aria-label="Thumbs up, 4 others">    <span class="reaction-emoji" aria-hidden="true">👍</span>    <span class="reaction-count" aria-hidden="true"></span>  </label>  <label class="reaction" style="--count: 1">    <input type="checkbox" class="reaction-input" name="reaction" value="🚀" aria-label="Rocket, 1 other">    <span class="reaction-emoji" aria-hidden="true">🚀</span>    <span class="reaction-count" aria-hidden="true"></span>  </label>  <button type="button" class="reaction-add" popovertarget="reaction-picker" aria-label="Add a reaction"></button>  <div class="popover p(4)" id="reaction-picker" popover>    <div class="grid grid-cols(6) gap(2)">      <button type="button" class="btn btn-quiet btn-square btn-sm" value="👍" aria-label="Thumbs up">        <span class="reaction-emoji" aria-hidden="true">👍</span>      </button>      <button type="button" class="btn btn-quiet btn-square btn-sm" value="❤️" aria-label="Heart">        <span class="reaction-emoji" aria-hidden="true">❤️</span>      </button>      <button type="button" class="btn btn-quiet btn-square btn-sm" value="😂" aria-label="Laughing">        <span class="reaction-emoji" aria-hidden="true">😂</span>      </button>      <button type="button" class="btn btn-quiet btn-square btn-sm" value="🎉" aria-label="Party popper">        <span class="reaction-emoji" aria-hidden="true">🎉</span>      </button>      <button type="button" class="btn btn-quiet btn-square btn-sm" value="👀" aria-label="Eyes">        <span class="reaction-emoji" aria-hidden="true">👀</span>      </button>      <button type="button" class="btn btn-quiet btn-square btn-sm" value="🚀" aria-label="Rocket">        <span class="reaction-emoji" aria-hidden="true">🚀</span>      </button>    </div>  </div></div><script>const picker = document.getElementById('reaction-picker')const reactions = document.getElementById('reactions')picker.addEventListener('click', function (event) {  const option = event.target.closest('button')  if (!option) return  let input = Array.from(reactions.querySelectorAll('.reaction-input')).find(function (each) { return each.value === option.value })  if (!input) {    const reaction = document.createElement('label')    const emoji = document.createElement('span')    const count = document.createElement('span')    input = document.createElement('input')    reaction.className = 'reaction'    input.type = 'checkbox'    input.className = 'reaction-input'    input.name = 'reaction'    input.value = option.value    input.setAttribute('aria-label', option.getAttribute('aria-label') + ', no others')    emoji.className = 'reaction-emoji'    emoji.textContent = option.value    emoji.setAttribute('aria-hidden', 'true')    count.className = 'reaction-count'    count.setAttribute('aria-hidden', 'true')    reaction.append(input, emoji, count)    reactions.insertBefore(reaction, reactions.querySelector('.reaction-add'))  }  if (!input.checked) input.click()  picker.hidePopover()})</script>
開啟選擇器,選取這一列尚未出現的表情符號。

#在討論串中

在討論串中,表情回應列接在留言文字後方,與文字的間距比段落之間稍大。

在討論串中

<div class="card max-w(480) mx-auto">  <ol class="thread">    <li class="thread-item">      <span class="thread-avatar"><span class="avatar">GH</span></span>      <div class="thread-body">        <p class="thread-header">          <span class="thread-author">Grace Hopper</span>          <time class="thread-meta" datetime="2026-11-12T09:12">2h</time>        </p>        <p class="thread-text">          The contracts ship on Tuesday, the framework components the week after.        </p>        <div class="reaction-group" role="group" aria-label="Reactions to Grace Hopper's comment">          <label class="reaction" style="--count: 5">            <input type="checkbox" class="reaction-input" name="reaction-thread" value="👍" aria-label="Thumbs up, 5 others">            <span class="reaction-emoji" aria-hidden="true">👍</span>            <span class="reaction-count" aria-hidden="true"></span>          </label>          <label class="reaction" style="--count: 2">            <input type="checkbox" class="reaction-input" name="reaction-thread" value="🚀" aria-label="Rocket, 2 others" checked>            <span class="reaction-emoji" aria-hidden="true">🚀</span>            <span class="reaction-count" aria-hidden="true"></span>          </label>        </div>      </div>      <ol class="thread-replies">        <li class="thread-item">          <span class="thread-avatar"><span class="avatar avatar-sm">AL</span></span>          <div class="thread-body">            <p class="thread-header">              <span class="thread-author">Ada Lovelace</span>              <time class="thread-meta" datetime="2026-11-12T10:05">1h</time>            </p>            <p class="thread-text">Then the release notes go out on Monday.</p>          </div>        </li>      </ol>    </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">GH</span></span>      <div className="thread-body">        <p className="thread-header">          <span className="thread-author">Grace Hopper</span>          <time className="thread-meta" dateTime="2026-11-12T09:12">2h</time>        </p>        <p className="thread-text">          The contracts ship on Tuesday, the framework components the week after.        </p>        <div className="reaction-group" role="group" aria-label="Reactions to Grace Hopper's comment">          <label className="reaction" style={{ '--count': '5' } as React.CSSProperties}>            <input type="checkbox" className="reaction-input" name="reaction-thread" value="👍" aria-label="Thumbs up, 5 others" />            <span className="reaction-emoji" aria-hidden="true">👍</span>            <span className="reaction-count" aria-hidden="true"></span>          </label>          <label className="reaction" style={{ '--count': '2' } as React.CSSProperties}>            <input type="checkbox" className="reaction-input" name="reaction-thread" value="🚀" aria-label="Rocket, 2 others" defaultChecked />            <span className="reaction-emoji" aria-hidden="true">🚀</span>            <span className="reaction-count" aria-hidden="true"></span>          </label>        </div>      </div>      <ol className="thread-replies">        <li className="thread-item">          <span className="thread-avatar"><span className="avatar avatar-sm">AL</span></span>          <div className="thread-body">            <p className="thread-header">              <span className="thread-author">Ada Lovelace</span>              <time className="thread-meta" dateTime="2026-11-12T10:05">1h</time>            </p>            <p className="thread-text">Then the release notes go out on Monday.</p>          </div>        </li>      </ol>    </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">GH</span></span>      <div class="thread-body">        <p class="thread-header">          <span class="thread-author">Grace Hopper</span>          <time class="thread-meta" datetime="2026-11-12T09:12">2h</time>        </p>        <p class="thread-text">          The contracts ship on Tuesday, the framework components the week after.        </p>        <div class="reaction-group" role="group" aria-label="Reactions to Grace Hopper's comment">          <label class="reaction" style="--count: 5">            <input type="checkbox" class="reaction-input" name="reaction-thread" value="👍" aria-label="Thumbs up, 5 others">            <span class="reaction-emoji" aria-hidden="true">👍</span>            <span class="reaction-count" aria-hidden="true"></span>          </label>          <label class="reaction" style="--count: 2">            <input type="checkbox" class="reaction-input" name="reaction-thread" value="🚀" aria-label="Rocket, 2 others" checked>            <span class="reaction-emoji" aria-hidden="true">🚀</span>            <span class="reaction-count" aria-hidden="true"></span>          </label>        </div>      </div>      <ol class="thread-replies">        <li class="thread-item">          <span class="thread-avatar"><span class="avatar avatar-sm">AL</span></span>          <div class="thread-body">            <p class="thread-header">              <span class="thread-author">Ada Lovelace</span>              <time class="thread-meta" datetime="2026-11-12T10:05">1h</time>            </p>            <p class="thread-text">Then the release notes go out on Monday.</p>          </div>        </li>      </ol>    </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">GH</span></span>        <div class="thread-body">          <p class="thread-header">            <span class="thread-author">Grace Hopper</span>            <time class="thread-meta" datetime="2026-11-12T09:12">2h</time>          </p>          <p class="thread-text">            The contracts ship on Tuesday, the framework components the week after.          </p>          <div class="reaction-group" role="group" aria-label="Reactions to Grace Hopper's comment">            <label class="reaction" style="--count: 5">              <input type="checkbox" class="reaction-input" name="reaction-thread" value="👍" aria-label="Thumbs up, 5 others">              <span class="reaction-emoji" aria-hidden="true">👍</span>              <span class="reaction-count" aria-hidden="true"></span>            </label>            <label class="reaction" style="--count: 2">              <input type="checkbox" class="reaction-input" name="reaction-thread" value="🚀" aria-label="Rocket, 2 others" checked>              <span class="reaction-emoji" aria-hidden="true">🚀</span>              <span class="reaction-count" aria-hidden="true"></span>            </label>          </div>        </div>        <ol class="thread-replies">          <li class="thread-item">            <span class="thread-avatar"><span class="avatar avatar-sm">AL</span></span>            <div class="thread-body">              <p class="thread-header">                <span class="thread-author">Ada Lovelace</span>                <time class="thread-meta" datetime="2026-11-12T10:05">1h</time>              </p>              <p class="thread-text">Then the release notes go out on Monday.</p>            </div>          </li>        </ol>      </li>    </ol>  </div></template>

#無障礙設計

  • 以文字寫出表情符號名稱和其他人的回應人數,作為每個核取方塊的名稱,例如 aria-label="Thumbs up, 3 others"。再用 aria-hidden="true" 對輔助技術隱藏表情符號和人數。讀者是否也有回應由核取狀態表示,因此每次按下後,名稱仍然正確。
  • 別依賴畫面上的人數讓螢幕閱讀器讀出數字。瀏覽器引擎在計算無障礙名稱和描述時會略過 CSS 計數器產生的文字。在 Chromium 中,核取方塊的名稱取自標籤文字,不包含計數器產生的數字。
  • 為群組和 reaction-add 命名,後者可命名為「新增表情回應」。選擇器中的每個按鈕都以表情符號的名稱命名,並對輔助技術隱藏表情符號本身。
  • 整個膠囊都是操作目標,尺寸為 28px;在觸控螢幕上,膠囊維持原本的尺寸,操作目標則在周圍擴至 44px。在強制色彩模式下,膠囊仍有外框,已加入的回應則以醒目提示色顯示較粗的外框。

#平台注意事項

以 text-box: trim-both cap alphabetic 將人數文字的文字框裁切至大寫字母高度。這樣膠囊就能以數字本身置中,讓數字與表情符號的中央對齊。瀏覽器未套用這項設定時,數字與中央的偏差仍在半個像素以內。Chromium 和 Safari 支援 text-box。

#類別

類別說明
reaction-group回應列使用設有 role="group" 和無障礙名稱的元素,空間不足時會換行。用於訊息時放在訊息泡泡下方並與其對齊,用於討論串時則放在文字下方。
reaction每個表情回應是 28px 的膠囊,內含 reaction-input、表情符號和計數。將 --count 設為其他使用者的回應數。
reaction-input記錄使用者本人是否已加上表情回應的核取方塊。它以透明方式覆蓋整個膠囊,無障礙名稱應包含表情符號和其他回應者的人數,例如「讚,另有 3 人」
reaction-emoji表情符號可用 span 內的字元,或用圖片並將類別加在 img 上。輸入控制項已有無障礙名稱時,請對輔助科技隱藏表情符號。也適用於選擇器按鈕上的表情符號
reaction-count元素沒有內容時,計數器會顯示 --count 的值。使用者加上自己的表情回應時,計數加 1。元素已有文字(例如 1.2k)時,直接顯示該文字
reaction-add列尾的圓形按鈕,帶有臉部和加號圖示,用來開啟頁面的表情符號選擇器。緊接在按鈕後的 popover 開啟時,按鈕會維持按下的外觀。

#自訂屬性

屬性預設值說明
--count0給出這項回應的其他人數。核取方塊勾選時,也會計入讀者自己的回應。設定於 reaction

#原始碼

@master/ui/components/reaction.css
/* * Reaction: an emoji answer to a message, with how many gave it. * Each reaction is a <label> around a native checkbox, so a press, Space and the form all work as they do for a * checkbox. The count is a CSS counter: the pill starts it at --count, the reactions of everyone else, and a * checked box adds one, so the number is right after every press with no script. Engines leave a counter out of * an accessible name, so the box is named in words (the emoji and the others' count) and the pill's drawing is * hidden from assistive technology; the checked state says whether the reader is one of them. * At rest a reaction is a flat pill of the chip tone on one contour; under a press it sinks into a well and the * emoji is pushed in with it; given, it takes the selected language of the library: an ink hairline, a faint * tint of ink and the count in strong ink. * Geometry: a 28px pill with true half circles at its ends; on a touch screen its target reaches 44px above and below it. The emoji is 16px and stands * as far from the start as from the top and bottom, so it is concentric with the round end; the count's figures * are tabular, and trimmed to their cap height where text-box is supported, so flex centres the figures rather * than the line around them (elsewhere they stand within half a pixel of the middle). * A count written in the markup (1.2k) replaces the counter, for numbers too large to count by one. * Under a message the row stands under the bubble, and in a thread under the words. */@layer components.ui {  /* The row of reactions, with the button that adds one at its end. */  .reaction-group {    display: flex;    flex-wrap: wrap;    align-items: center;    gap: .375rem;    min-width: 0;    margin: 0;    padding: 0;    border: 0;    /*     * A finger's target reaches 8px over and under a pill. Rows that wrap stand that far apart twice over, so     * a target of the second row does not lie on the foot of the pill above it; one row is drawn as it was.     */    @media (pointer: coarse) {      row-gap: 1rem;    }  }  /* Under a message the row stands where the bubble does: at the start of a received row, at the end of a sent one. */  .message .reaction-group {    grid-column: 2;    margin-block-start: .125rem;  }  .message-sent .reaction-group {    grid-column: 1;    justify-content: flex-end;  }  .message:not(.message-sent, :has(.message-avatar)) .reaction-group {    grid-column: 1 / -1;  }  /* In a thread it follows the words, a little further from them than one paragraph from the next. */  .thread-body .reaction-group {    margin-block-start: .375rem;  }  .reaction {    --reaction-height: 1.75rem;    --reaction-emoji-size: 1rem;    --count: 0;    position: relative;    display: inline-flex;    flex: none;    align-items: center;    gap: .25rem;    height: var(--reaction-height);    margin: 0;    padding-block: 0;    padding-inline: calc((var(--reaction-height) - var(--reaction-emoji-size)) / 2) .5rem;    border-radius: 999px;    corner-shape: round;    background: var(--color-surface-chip);    color: var(--color-text-muted);    box-shadow: inset 0 0 0 .5px var(--color-line-contour);    font: var(--font-weight-control) .78125rem/1 var(--font-family-sans);    font-feature-settings: inherit;    font-variant-numeric: tabular-nums;    white-space: nowrap;    vertical-align: middle;    counter-reset: reaction var(--count);    user-select: none;    -webkit-user-select: none;    -webkit-tap-highlight-color: transparent;    cursor: pointer;    touch-action: manipulation;    transition-property: background-color, box-shadow, color;    transition-duration: var(--duration-quick);    transition-timing-function: var(--easing-glide);    @media (hover: hover) {      &:hover:not(:has(.reaction-input:disabled)) {        color: var(--color-text-body);        box-shadow: inset 0 0 0 .5px var(--color-line-mark);      }    }    /* Given: the reader's own reaction is counted, and the pill takes an ink hairline over a faint tint of ink. */    &:has(.reaction-input:checked) {      counter-increment: reaction;      background: color-mix(in oklab, var(--color-text-strong) 10%, transparent);      color: var(--color-text-strong);      box-shadow: inset 0 0 0 .5px var(--color-text-strong), 0 0 0 .5px color-mix(in oklab, var(--color-text-strong) 22%, transparent);      @media (hover: hover) {        &:hover:not(:has(.reaction-input:disabled)) {          background: color-mix(in oklab, var(--color-text-strong) 13%, transparent);          color: var(--color-text-strong);          box-shadow: inset 0 0 0 .5px var(--color-text-strong), 0 0 0 .5px color-mix(in oklab, var(--color-text-strong) 22%, transparent);        }      }    }    /*     * Pressed: the pill sinks into a well and the emoji is pushed in with it, given or not, so a tap is     * answered before the state changes.     */    &:active:not(:has(.reaction-input:disabled)) {      background: var(--color-surface-inset);      box-shadow: var(--shadow-pressed);      transition-duration: var(--duration-press);      .reaction-emoji {        scale: .88;        transition-duration: var(--duration-press);      }    }    &:has(.reaction-input:focus-visible) {      @apply --focus-ring;    }    &:has(.reaction-input:disabled) {      background: var(--color-surface-inset);      color: var(--color-text-disabled);      box-shadow: var(--shadow-flat);      cursor: not-allowed;      .reaction-emoji {        opacity: .6;      }    }    /* Given and disabled: the hairline stays, in the disabled ink, so the reader still sees the reaction is theirs. */    &:has(.reaction-input:checked:disabled) {      box-shadow: inset 0 0 0 .5px var(--color-text-disabled);    }    /* As specific as the press above, so it is not overruled by it. */    @media (prefers-reduced-motion: reduce) {      &:active:not(:has(.reaction-input:disabled)) .reaction-emoji {        scale: none;      }    }    /*     * Reactions stand 6px apart, closer than the 8px a 44px target would reach to the side: on touch a pill's     * target grows above and below only, so it never takes a tap meant for its neighbor. The pill keeps its size.     */    @media (pointer: coarse) {      &::after {        @apply --touch-target-block;      }    }    @media (forced-colors: active) {      outline: 1px solid CanvasText;      outline-offset: -1px;      &:has(.reaction-input:checked):not(:has(.reaction-input:focus-visible)) {        outline: 2px solid Highlight;        outline-offset: -2px;      }      &:has(.reaction-input:focus-visible) {        outline: 2px solid Highlight;        outline-offset: 2px;      }      &:has(.reaction-input:disabled) {        outline-color: GrayText;        color: GrayText;      }    }  }  /* The checkbox covers the pill invisibly: the label is the target, the input keeps the state. */  .reaction-input {    position: absolute;    inset: 0;    width: 100%;    height: 100%;    margin: 0;    padding: 0;    border: 0;    border-radius: inherit;    corner-shape: inherit;    opacity: 0;    appearance: none;    cursor: inherit;  }  /* The emoji, a character or a picture, in a square as tall as its font; also an option of the picker. */  .reaction-emoji {    display: inline-grid;    flex: none;    place-items: center;    width: var(--reaction-emoji-size, 1rem);    height: var(--reaction-emoji-size, 1rem);    font-size: var(--reaction-emoji-size, 1rem);    line-height: 1;    transition: scale var(--duration-quick) var(--easing-glide);  }  /* The count, from the counter; text written inside it is shown instead. */  .reaction-count {    min-width: 1ch;    text-align: center;    /* Trimmed to its figures, so flex centres the figures and not the line around them. */    text-box: trim-both cap alphabetic;    &:empty::before {      content: counter(reaction);    }  }  /*   * Add a reaction: a round button of the same pill, with a face and a plus. It opens the page's emoji picker,   * a popover, which adds the chosen reaction.   */  .reaction-add {    --reaction-height: 1.75rem;    position: relative;    display: inline-grid;    flex: none;    place-items: center;    width: var(--reaction-height);    height: var(--reaction-height);    margin: 0;    padding: 0;    border: 0;    border-radius: 999px;    corner-shape: round;    background: var(--color-surface-chip);    color: var(--color-text-muted);    box-shadow: inset 0 0 0 .5px var(--color-line-contour);    appearance: none;    -webkit-tap-highlight-color: transparent;    cursor: pointer;    touch-action: manipulation;    transition-property: background-color, box-shadow, color;    transition-duration: var(--duration-quick);    transition-timing-function: var(--easing-glide);    &::before {      content: '';      width: 1rem;      height: 1rem;      background: currentColor;      mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M13.07 5.27A8 8 0 1 0 18.73 10.93M19.5 2v5M17 4.5h5M8 15.5q3 2.5 6 0'/%3E%3Ccircle cx='8.5' cy='11' r='1' fill='black' stroke='none'/%3E%3Ccircle cx='13.5' cy='11' r='1' fill='black' stroke='none'/%3E%3C/svg%3E") center / contain no-repeat;    }    @media (hover: hover) {      &:hover:not(:disabled) {        color: var(--color-text-strong);        box-shadow: inset 0 0 0 .5px var(--color-line-mark);      }    }    &:active:not(:disabled), &:has(+ .popover:popover-open) {      background: var(--color-surface-inset);      color: var(--color-text-strong);      box-shadow: var(--shadow-pressed);    }    &:active:not(:disabled) {      transition-duration: var(--duration-press);    }    &:focus-visible {      @apply --focus-ring;    }    /* Disabled: the flat well of a reaction that cannot be given. */    &:disabled {      background: var(--color-surface-inset);      color: var(--color-text-disabled);      box-shadow: var(--shadow-flat);      cursor: not-allowed;    }    /*     * It stands 6px after the last reaction, closer than the 8px a 44px target would reach to the side: on touch     * its target grows above and below only, and keeps its 28px width, so it never takes a tap meant for the pill.     */    @media (pointer: coarse) {      &::after {        @apply --touch-target-block;      }    }    @media (forced-colors: active) {      outline: 1px solid ButtonText;      outline-offset: -1px;      &::before {        background: ButtonText;      }      /* The well it sinks into while the picker is open is gone with its shadow: a firmer outline keeps it. */      &:has(+ .popover:popover-open):not(:focus-visible) {        outline: 2px solid Highlight;        outline-offset: -2px;      }      &:disabled {        outline-color: GrayText;        &::before {          background: GrayText;        }      }    }  }}