Reaction Picker
A like button that opens a tray of emoji reactions, each growing under the pointer.
AI prompt
Create a "Like" button (38px tall, pill) with a reaction tray above it containing five emoji buttons (Like 👍, Love ❤️, Laugh 😂, Wow 😮, Sad 😢), each 40px with an aria-label. The tray opens on hover over the button or tray, on focus-within and when the main button is clicked; it closes after 250ms when the pointer leaves, on Escape and after choosing. When opening, the tray fades and scales from 0.9 in 160ms and the emoji pop in with a 30ms stagger. Hovering an emoji scales it to 1.35 in 120ms. Choosing a reaction closes the tray and changes the main button to show that emoji and its name ("Love"), set aria-pressed true; clicking the main button while a reaction is set removes it. Keyboard: Arrow keys move between reactions. Under prefers-reduced-motion use a plain 120ms fade without scale or stagger.About this pattern
Definition
A button that reveals a row of reactions on hover, focus or click. Hovering a reaction enlarges it, and choosing one replaces the button's label.
Purpose & UX principles
- Offers a range of responses behind one familiar control.
- The tray opens on hover for pointer users, and on click or focus for touch and keyboard users.
- Every reaction is a labelled button; the chosen reaction is shown in text as well as emoji.
Interaction states
- No reaction, tray open, hovered reaction (enlarged), chosen, focus-visible.
Motion specification
- Tray: fade and scale from 0.9, 160ms. Reactions pop in with a 30ms stagger.
- Hovered reaction scales to 1.35 in 120ms.
- Reduced motion: the tray fades only, with no scaling or stagger.
Responsive behaviour
- Reactions are 40px targets; the tray is horizontal and stays inside the container.
- On touch, tapping the main button toggles the tray.
Code
<div class="rp" id="rp">
<div class="tray" id="tray" role="group" aria-label="Reactions" hidden>
<button data-n="Like" aria-label="Like" style="--i:0">👍</button><button data-n="Love" aria-label="Love" style="--i:1">❤️</button><button data-n="Laugh" aria-label="Laugh" style="--i:2">😂</button><button data-n="Wow" aria-label="Wow" style="--i:3">😮</button><button data-n="Sad" aria-label="Sad" style="--i:4">😢</button>
</div>
<button class="main" id="main" aria-pressed="false" aria-haspopup="true"><span id="mi">👍</span> <span id="ml">Like</span></button>
</div>:root{--bg:#F1F1EF;--surface:#fff;--surface-2:#F7F7F5;--line:#E0E0DC;--text:#171717;--muted:#6f6f6f;--accent:#171717;--accent-ink:#fff;--danger:#d92d20}
*{box-sizing:border-box;margin:0}
.rp{position:relative;display:grid;justify-items:center;padding-top:56px}
.tray{position:absolute;top:0;display:flex;gap:2px;padding:4px;background:var(--surface);border:1px solid var(--line);border-radius:99px;box-shadow:0 10px 24px rgba(0,0,0,.12);transform-origin:bottom center;animation:tin .16s ease-out}
.tray[hidden]{display:none}
.tray button{width:40px;height:40px;border:0;border-radius:50%;background:none;font-size:22px;line-height:1;cursor:pointer;transition:transform .12s;animation:pin .2s ease-out backwards;animation-delay:calc(var(--i) * 30ms)}
.tray button:hover,.tray button:focus-visible{transform:scale(1.35);outline:none}
.tray button:focus-visible{background:var(--bg)}
@keyframes tin{from{opacity:0;transform:scale(.9)}}
@keyframes pin{from{opacity:0;transform:translateY(8px) scale(.7)}}
.main{height:38px;padding:0 16px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font:inherit;font-size:13.5px;font-weight:500;cursor:pointer;transition:border-color .15s}
.main:hover{border-color:var(--accent)}
.main:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
.main[aria-pressed=true]{background:var(--accent);color:var(--accent-ink);border-color:var(--accent)}
@media (prefers-reduced-motion:reduce){.tray{animation:fd .12s}.tray button{animation:none;transition:none}.tray button:hover{transform:none}@keyframes fd{from{opacity:0}}}const rp=document.getElementById('rp'),tray=document.getElementById('tray'),main=document.getElementById('main'),mi=document.getElementById('mi'),ml=document.getElementById('ml');
let t=0,set=false;
const open=()=>{clearTimeout(t);tray.hidden=false;};const close=()=>{t=setTimeout(()=>{tray.hidden=true;},250);};
rp.addEventListener('pointerenter',e=>{if(e.pointerType==='mouse')open();});rp.addEventListener('pointerleave',e=>{if(e.pointerType==='mouse')close();});
rp.addEventListener('focusin',open);rp.addEventListener('focusout',e=>{if(!rp.contains(e.relatedTarget))close();});
rp.addEventListener('keydown',e=>{const b=[...tray.querySelectorAll('button')],i=b.indexOf(document.activeElement);
if(e.key==='Escape'){tray.hidden=true;main.focus();}else if(i>=0&&e.key==='ArrowRight'){e.preventDefault();b[(i+1)%b.length].focus();}else if(i>=0&&e.key==='ArrowLeft'){e.preventDefault();b[(i-1+b.length)%b.length].focus();}});
tray.addEventListener('click',e=>{const b=e.target.closest('button');if(!b)return;mi.textContent=b.textContent;ml.textContent=b.dataset.n;set=true;main.setAttribute('aria-pressed','true');tray.hidden=true;main.focus();});
main.addEventListener('click',()=>{if(set){set=false;mi.textContent='👍';ml.textContent='Like';main.setAttribute('aria-pressed','false');tray.hidden=true;}else{tray.hidden?open():tray.hidden=true;}});One complete HTML file. Save it and open it in a browser.
<!doctype html>
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Reaction Picker — demo</title>
<style>
:root{--bg:#F1F1EF;--surface:#fff;--surface-2:#F7F7F5;--line:#E0E0DC;--text:#171717;--muted:#6f6f6f;--accent:#171717;--accent-ink:#fff;--danger:#d92d20}
*{box-sizing:border-box;margin:0}
html,body{height:100%}body{background:var(--bg);color:var(--text);font:15px/1.5 -apple-system,BlinkMacSystemFont,'Segoe UI',Inter,Roboto,sans-serif;-webkit-font-smoothing:antialiased}.stage{min-height:100%;display:grid;place-items:center;padding:24px}button,input,select,textarea{font-family:inherit}@media (prefers-reduced-motion:reduce){html{scroll-behavior:auto}}
.rp{position:relative;display:grid;justify-items:center;padding-top:56px}
.tray{position:absolute;top:0;display:flex;gap:2px;padding:4px;background:var(--surface);border:1px solid var(--line);border-radius:99px;box-shadow:0 10px 24px rgba(0,0,0,.12);transform-origin:bottom center;animation:tin .16s ease-out}
.tray[hidden]{display:none}
.tray button{width:40px;height:40px;border:0;border-radius:50%;background:none;font-size:22px;line-height:1;cursor:pointer;transition:transform .12s;animation:pin .2s ease-out backwards;animation-delay:calc(var(--i) * 30ms)}
.tray button:hover,.tray button:focus-visible{transform:scale(1.35);outline:none}
.tray button:focus-visible{background:var(--bg)}
@keyframes tin{from{opacity:0;transform:scale(.9)}}
@keyframes pin{from{opacity:0;transform:translateY(8px) scale(.7)}}
.main{height:38px;padding:0 16px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font:inherit;font-size:13.5px;font-weight:500;cursor:pointer;transition:border-color .15s}
.main:hover{border-color:var(--accent)}
.main:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
.main[aria-pressed=true]{background:var(--accent);color:var(--accent-ink);border-color:var(--accent)}
@media (prefers-reduced-motion:reduce){.tray{animation:fd .12s}.tray button{animation:none;transition:none}.tray button:hover{transform:none}@keyframes fd{from{opacity:0}}}
</style></head>
<body><div class="stage">
<div class="rp" id="rp">
<div class="tray" id="tray" role="group" aria-label="Reactions" hidden>
<button data-n="Like" aria-label="Like" style="--i:0">👍</button><button data-n="Love" aria-label="Love" style="--i:1">❤️</button><button data-n="Laugh" aria-label="Laugh" style="--i:2">😂</button><button data-n="Wow" aria-label="Wow" style="--i:3">😮</button><button data-n="Sad" aria-label="Sad" style="--i:4">😢</button>
</div>
<button class="main" id="main" aria-pressed="false" aria-haspopup="true"><span id="mi">👍</span> <span id="ml">Like</span></button>
</div>
</div>
<script>
const rp=document.getElementById('rp'),tray=document.getElementById('tray'),main=document.getElementById('main'),mi=document.getElementById('mi'),ml=document.getElementById('ml');
let t=0,set=false;
const open=()=>{clearTimeout(t);tray.hidden=false;};const close=()=>{t=setTimeout(()=>{tray.hidden=true;},250);};
rp.addEventListener('pointerenter',e=>{if(e.pointerType==='mouse')open();});rp.addEventListener('pointerleave',e=>{if(e.pointerType==='mouse')close();});
rp.addEventListener('focusin',open);rp.addEventListener('focusout',e=>{if(!rp.contains(e.relatedTarget))close();});
rp.addEventListener('keydown',e=>{const b=[...tray.querySelectorAll('button')],i=b.indexOf(document.activeElement);
if(e.key==='Escape'){tray.hidden=true;main.focus();}else if(i>=0&&e.key==='ArrowRight'){e.preventDefault();b[(i+1)%b.length].focus();}else if(i>=0&&e.key==='ArrowLeft'){e.preventDefault();b[(i-1+b.length)%b.length].focus();}});
tray.addEventListener('click',e=>{const b=e.target.closest('button');if(!b)return;mi.textContent=b.textContent;ml.textContent=b.dataset.n;set=true;main.setAttribute('aria-pressed','true');tray.hidden=true;main.focus();});
main.addEventListener('click',()=>{if(set){set=false;mi.textContent='👍';ml.textContent='Like';main.setAttribute('aria-pressed','false');tray.hidden=true;}else{tray.hidden?open():tray.hidden=true;}});
</script>
</body></html>