ナビゲーション

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には、そのリアクションを付けた人のうち、読者本人を除いた人数を設定します。ピルのカウンターはその値から始まり、チェックが入ると 1 を足すため、読者が付けたリアクションは--countより 1 多く表示されます。reaction-countを空にすると、カウンターの数値が表示されます。1 人単位で表示するには数が大きすぎる場合は、1.2kなどのテキストを入れると、そのテキストが表示されます。

#状態

通常時は、1 本の輪郭線で囲まれた平らなピル型で、カウントは控えめな色で表示します。ポインターを重ねると輪郭がはっきりし、押している間はピルがくぼみ、絵文字も一緒に沈み込みます。リアクションを付けると、ライブラリ共通の選択状態になり、インク色の極細線と淡いインク色の背景が付き、カウントは強いインク色になります。終了したスレッドなどでチェックボックスが無効な場合は、平らなまま絵文字が薄く表示されます。

状態

<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でカウントの数字の上下をキャップハイトに合わせて切り詰めます。これにより、行ボックスではなく数字そのものがピル内で中央に配置され、絵文字の中央とそろいます。この指定がなくても、数字の中央と絵文字の中央のずれは 0.5px 以内です。text-boxは Chromium と Safari で利用できます。

#クラス

クラス説明
reaction-grouprole="group"と名前を持つ要素に置くリアクションの行。必要に応じて折り返し、メッセージの下では吹き出しに、スレッド内では本文に位置を合わせます。
reaction1つのリアクションを表示する28pxのピルです。reaction-input、絵文字、件数を囲みます。--count には、読者本人を除く他の人のリアクション件数を設定します。
reaction-input読者自身のリアクションを保持するチェックボックス。見えない状態でピル全体を覆います。「いいね、ほか 3 人」のように、絵文字と他の人の人数が伝わる名前を付けます。
reaction-emoji絵文字。span 内の文字、またはクラスを img に付けた画像です。入力欄にアクセシブルな名前がある場合は、絵文字を支援技術から隠します。ピッカーのボタン内の絵文字にも使います。
reaction-count要素が空の場合、カウンターが --count の値を表示します。読者自身がリアクションしている間は、その値に1を加えて表示します。要素内に 1.2k などのテキストがあれば、そちらを表示します。
reaction-add行末にある顔とプラス記号付きの丸いボタン。ページの絵文字ピッカーを開き、直後のポップオーバーが開いている間は沈んだ表示を維持

#カスタムプロパティ

プロパティ既定値説明
--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;        }      }    }  }}