Radial action menu
A round action button that fans five shortcuts out along an arc, each popping in on a staggered spring with its own label.
"use client";
import {
useEffect,
useRef,
useState,
type CSSProperties,
type KeyboardEvent,
type ReactNode,
} from "react";
import "./radial-menu.css";
export type RadialAction = {
label: string;
icon: ReactNode;
onSelect?: () => void;
};
type RadialMenuProps = {
actions: RadialAction[];
/** Arc spread in degrees (180 = half circle). */
spread?: number;
/** Distance from the center button, in px. */
radius?: number;
label?: string;
theme?: "light" | "dark";
};
/**
* RadialMenu
* - The main button opens a fan of actions along an arc above it.
* - Each action is placed with CSS: rotate(angle) translate(radius) rotate(-angle).
* - Arrow keys move between actions, Escape closes and returns focus.
*/
export function RadialMenu({
actions,
spread = 160,
radius = 112,
label = "Quick actions",
theme = "light",
}: RadialMenuProps) {
const [open, setOpen] = useState(false);
const [picked, setPicked] = useState<string | null>(null);
const main = useRef<HTMLButtonElement>(null);
const items = useRef<(HTMLButtonElement | null)[]>([]);
useEffect(() => {
if (open) items.current[0]?.focus();
}, [open]);
const onKey = (e: KeyboardEvent<HTMLDivElement>) => {
if (e.key === "Escape") {
setOpen(false);
main.current?.focus();
return;
}
if (
!open ||
!["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown"].includes(e.key)
)
return;
e.preventDefault();
const i = items.current.findIndex((el) => el === document.activeElement);
const step = e.key === "ArrowRight" || e.key === "ArrowDown" ? 1 : -1;
items.current[(i + step + actions.length) % actions.length]?.focus();
};
const start = -90 - spread / 2; // centered above the button
return (
<div
className="gu-radial"
data-theme={theme}
data-open={open || undefined}
onKeyDown={onKey}
style={{ "--r": `${radius}px` } as CSSProperties}
>
<ul className="gu-radial__ring" aria-label={label}>
{actions.map((a, i) => {
const angle = start + (spread / (actions.length - 1)) * i;
return (
<li
key={a.label}
style={{ "--a": `${angle}deg`, "--i": i } as CSSProperties}
>
<button
ref={(el) => {
items.current[i] = el;
}}
type="button"
tabIndex={open ? 0 : -1}
aria-hidden={!open}
onClick={() => {
a.onSelect?.();
setPicked(a.label);
setOpen(false);
main.current?.focus();
}}
>
{a.icon}
<span className="gu-radial__label">{a.label}</span>
</button>
</li>
);
})}
</ul>
<button
ref={main}
type="button"
className="gu-radial__main"
aria-expanded={open}
aria-label={open ? `Close ${label.toLowerCase()}` : label}
onClick={() => setOpen((o) => !o)}
>
<span aria-hidden="true" />
</button>
<p className="gu-radial__status" role="status">
{picked ? `Chose: ${picked}` : ""}
</p>
</div>
);
}
Paste this into ChatGPT, Claude, Cursor, v0, Lovable or Bolt. It describes the layout, motion, colors and accessibility and includes the code, so the AI can rebuild it in any framework.
# Build this UI piece: Radial action menu
You are a senior front-end engineer. Recreate the piece below in my project. If I don't say which framework I use, ask once, then build it in that framework (React, Vue, Svelte, Angular, Astro, plain HTML/CSS/JS or anything else). Keep the behavior, motion, colors, spacing and accessibility exactly as described. Keep the code clean and commented for beginners.
## What it is
A floating action button that fans five shortcut buttons out along an arc above it, like a hand of cards. Each shortcut springs out with a small stagger and shows its label on hover.
## Layout and look
- Main button: 68px orange (#ff5a1f) circle with a dark plus made of two 24×3px rounded bars and an orange glow shadow. Open, the plus rotates 135° into an x.
- Actions: 52px dark circles (#0e0e10, inverted in dark mode) with 22px line icons, spread over a 160° arc centered straight above the main button at a 112px radius.
- Labels: small dark tags (12px, weight 700) above each action.
- A status line under the button announces the chosen action.
## Behavior and motion
1. Each action is positioned with transform: rotate(angle) translate(radius) rotate(-angle), and starts at the center at scale 0.3 and opacity 0.
2. Opening: transform transitions 600ms with an overshooting spring cubic-bezier(0.34, 1.56, 0.64, 1), delayed 45ms per item. Closing reverses quickly (350ms ease-in) in the opposite order.
3. Hover or focus scales an action to 1.12 and reveals its label (fade + 4px rise).
4. Selecting an action closes the menu, returns focus to the main button and updates the status line.
## Touch
Tap to open. Labels are shown permanently while open on touch screens (media hover: none).
## Accessibility
- The main button has aria-expanded and a clear label. Closed actions are removed from the tab order.
- Opening moves focus to the first action; arrow keys cycle through actions; Escape closes and returns focus.
- The status line uses role="status".
- prefers-reduced-motion: actions fade in at their final positions, no fly-out.
## Props
actions ({ label, icon, onSelect? }[]), spread (degrees, default 160), radius (px, default 112), label, theme.
## Reference implementation
The original is written in React with one plain CSS file. Dependencies: none (plain React and CSS). Translate it faithfully; do not add new libraries unless my framework needs them.
### RadialMenu.tsx
```tsx
"use client";
import {
useEffect,
useRef,
useState,
type CSSProperties,
type KeyboardEvent,
type ReactNode,
} from "react";
import "./radial-menu.css";
export type RadialAction = {
label: string;
icon: ReactNode;
onSelect?: () => void;
};
type RadialMenuProps = {
actions: RadialAction[];
/** Arc spread in degrees (180 = half circle). */
spread?: number;
/** Distance from the center button, in px. */
radius?: number;
label?: string;
theme?: "light" | "dark";
};
/**
* RadialMenu
* - The main button opens a fan of actions along an arc above it.
* - Each action is placed with CSS: rotate(angle) translate(radius) rotate(-angle).
* - Arrow keys move between actions, Escape closes and returns focus.
*/
export function RadialMenu({
actions,
spread = 160,
radius = 112,
label = "Quick actions",
theme = "light",
}: RadialMenuProps) {
const [open, setOpen] = useState(false);
const [picked, setPicked] = useState<string | null>(null);
const main = useRef<HTMLButtonElement>(null);
const items = useRef<(HTMLButtonElement | null)[]>([]);
useEffect(() => {
if (open) items.current[0]?.focus();
}, [open]);
const onKey = (e: KeyboardEvent<HTMLDivElement>) => {
if (e.key === "Escape") {
setOpen(false);
main.current?.focus();
return;
}
if (
!open ||
!["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown"].includes(e.key)
)
return;
e.preventDefault();
const i = items.current.findIndex((el) => el === document.activeElement);
const step = e.key === "ArrowRight" || e.key === "ArrowDown" ? 1 : -1;
items.current[(i + step + actions.length) % actions.length]?.focus();
};
const start = -90 - spread / 2; // centered above the button
return (
<div
className="gu-radial"
data-theme={theme}
data-open={open || undefined}
onKeyDown={onKey}
style={{ "--r": `${radius}px` } as CSSProperties}
>
<ul className="gu-radial__ring" aria-label={label}>
{actions.map((a, i) => {
const angle = start + (spread / (actions.length - 1)) * i;
return (
<li
key={a.label}
style={{ "--a": `${angle}deg`, "--i": i } as CSSProperties}
>
<button
ref={(el) => {
items.current[i] = el;
}}
type="button"
tabIndex={open ? 0 : -1}
aria-hidden={!open}
onClick={() => {
a.onSelect?.();
setPicked(a.label);
setOpen(false);
main.current?.focus();
}}
>
{a.icon}
<span className="gu-radial__label">{a.label}</span>
</button>
</li>
);
})}
</ul>
<button
ref={main}
type="button"
className="gu-radial__main"
aria-expanded={open}
aria-label={open ? `Close ${label.toLowerCase()}` : label}
onClick={() => setOpen((o) => !o)}
>
<span aria-hidden="true" />
</button>
<p className="gu-radial__status" role="status">
{picked ? `Chose: ${picked}` : ""}
</p>
</div>
);
}
```
### radial-menu.css
```css
/* RadialMenu: change these colors to match your brand. */
.gu-radial {
--main: #ff5a1f; /* round button */
--main-icon: #0e0e10;
--item: #0e0e10; /* action buttons */
--item-icon: #f3eee3;
--label-bg: #0e0e10;
--label-text: #f3eee3;
--text: #57534b;
--focus: #2b35ff;
--spring: cubic-bezier(0.34, 1.56, 0.64, 1);
position: relative;
display: grid;
place-items: center;
width: calc(var(--r) * 2 + 96px);
height: calc(var(--r) + 140px);
padding-top: calc(var(--r) + 20px);
font-family: system-ui, sans-serif;
}
.gu-radial[data-theme="dark"] {
--item: #f3eee3;
--item-icon: #0e0e10;
--label-bg: #f3eee3;
--label-text: #0e0e10;
--text: #aea89c;
--focus: #d7ff3a;
}
.gu-radial button:focus-visible {
outline: 2px solid var(--focus);
outline-offset: 3px;
}
/* Main button: a plus that turns into an x */
.gu-radial__main {
position: relative;
z-index: 2;
width: 68px;
height: 68px;
border: 0;
border-radius: 50%;
background: var(--main);
box-shadow: 0 14px 30px -12px rgb(255 90 31 / 0.7);
cursor: pointer;
transition: transform 0.5s var(--spring);
}
.gu-radial__main:active {
transform: scale(0.94);
}
.gu-radial__main span,
.gu-radial__main span::before {
position: absolute;
inset: 50% auto auto 50%;
width: 24px;
height: 3px;
margin: -1.5px 0 0 -12px;
border-radius: 2px;
background: var(--main-icon);
transition: transform 0.5s var(--spring);
}
.gu-radial__main span::before {
content: "";
inset: 0;
margin: 0;
transform: rotate(90deg);
}
.gu-radial[data-open] .gu-radial__main span {
transform: rotate(135deg);
}
/* The ring of actions: every item starts at the center and flies out */
.gu-radial__ring {
position: absolute;
left: 50%;
bottom: 70px;
width: 0;
height: 0;
margin: 0;
padding: 0;
list-style: none;
}
.gu-radial__ring li {
position: absolute;
left: -26px;
top: -26px;
transform: rotate(var(--a)) translate(0) rotate(calc(var(--a) * -1))
scale(0.3);
opacity: 0;
pointer-events: none;
transition:
transform 0.35s ease-in calc((4 - var(--i)) * 25ms),
opacity 0.25s calc((4 - var(--i)) * 25ms);
}
.gu-radial[data-open] .gu-radial__ring li {
transform: rotate(var(--a)) translate(var(--r)) rotate(calc(var(--a) * -1))
scale(1);
opacity: 1;
pointer-events: auto;
transition:
transform 0.6s var(--spring) calc(var(--i) * 45ms),
opacity 0.2s calc(var(--i) * 45ms);
}
.gu-radial__ring button {
position: relative;
display: grid;
place-items: center;
width: 52px;
height: 52px;
border: 0;
border-radius: 50%;
background: var(--item);
color: var(--item-icon);
cursor: pointer;
transition: transform 0.35s var(--spring);
}
.gu-radial__ring button:hover,
.gu-radial__ring button:focus-visible {
transform: scale(1.12);
}
.gu-radial__ring svg {
width: 22px;
height: 22px;
}
/* Labels appear on hover/focus (always on for touch screens) */
.gu-radial__label {
position: absolute;
bottom: calc(100% + 8px);
left: 50%;
padding: 5px 9px;
border-radius: 7px;
background: var(--label-bg);
color: var(--label-text);
font-size: 0.75rem;
font-weight: 700;
white-space: nowrap;
transform: translate(-50%, 4px);
opacity: 0;
pointer-events: none;
transition:
opacity 0.2s,
transform 0.3s var(--spring);
}
.gu-radial__ring button:hover .gu-radial__label,
.gu-radial__ring button:focus-visible .gu-radial__label {
opacity: 1;
transform: translate(-50%, 0);
}
@media (hover: none) {
.gu-radial[data-open] .gu-radial__label {
opacity: 1;
transform: translate(-50%, 0);
}
}
.gu-radial__status {
min-height: 1.2em;
margin: 16px 0 0;
color: var(--text);
font-size: 0.9rem;
font-weight: 600;
}
@media (prefers-reduced-motion: reduce) {
.gu-radial__ring li,
.gu-radial[data-open] .gu-radial__ring li {
transform: rotate(var(--a)) translate(var(--r)) rotate(calc(var(--a) * -1));
transition: opacity 0.15s;
}
.gu-radial__main,
.gu-radial__main span,
.gu-radial__ring button {
transition: none;
}
}
```
You might also want
Next piece: Reaction burst buttonSplit action button
Components, intermediate
Hold to confirm
Components, beginner
Smart tooltips
Components, intermediate