ForkFree

Prompts / Coding

Write a UI micro-interaction spec

You get a detailed, ready-to-use prompt for a coding assistant that describes one micro interaction in full, including timings, keyboard behaviour and edge cases. It works because the AI is forced to decide every state and fallback up front, so the coding assistant has little left to guess.

Struggled in our testThe content is thorough and covers every step, heading and edge case. But it runs to roughly 550 words against a hard limit of 350. Behaviour is bullets rather than the one short paragraph asked for. It also includes inline code-style tokens despite "no code".

The prompt

Act as a senior front-end engineer who specialises in accessible interface motion.

Task: write an implementation prompt that I can give to an AI coding assistant to build one micro interaction for {component_name} in {tech_stack}. The interaction should achieve this goal: {interaction_goal}.

Steps:
1. State the trigger, the start state and the end state of the interaction in one short paragraph.
2. List every intermediate state (for example hover, focus, loading, success, error) and say exactly what changes visually in each, including durations in milliseconds and easing.
3. Describe the keyboard and screen reader behaviour, plus a reduced-motion fallback.
4. Add edge cases to handle: {edge_cases}.
5. Finish with acceptance checks that someone could test by hand.

Output: a single ready-to-paste prompt under the headings Behaviour, States, Accessibility, Edge cases and Acceptance checks. Use bullet points, no code, and keep it under 350 words.

Change the parts in curly braces. Use it when you want a polished button, input or modal behaviour and your first attempts at asking an AI for it came back generic or inaccessible.

What happened when we ran it

We sent

Act as a senior front-end engineer who specialises in accessible interface motion.

Task: write an implementation prompt that I can give to an AI coding assistant to build one micro interaction for a 'Delete project' button in a project settings page of a project-management app in React 18, TypeScript and Tailwind CSS, with Framer Motion for animation. The interaction should achieve this goal: Stop accidental deletions by requiring the user to press and hold the button for 1.5 seconds, with a fill animation showing progress, before the project is deleted.

Steps:
1. State the trigger, the start state and the end state of the interaction in one short paragraph.
2. List every intermediate state (for example hover, focus, loading, success, error) and say exactly what changes visually in each, including durations in milliseconds and easing.
3. Describe the keyboard and screen reader behaviour, plus a reduced-motion fallback.
4. Add edge cases to handle: the user releases early, the user taps on a touch screen, the user holds the Space key, the network request fails after the hold completes, and the button is pressed twice quickly.
5. Finish with acceptance checks that someone could test by hand.

Output: a single ready-to-paste prompt under the headings Behaviour, States, Accessibility, Edge cases and Acceptance checks. Use bullet points, no code, and keep it under 350 words.

The model replied

**Prompt to paste:** Build a "Delete project" press-and-hold button for a project settings page using React 18, TypeScript, Tailwind CSS and Framer Motion. No extra libraries. **Behaviour** - Trigger: user presses and holds the button (pointer or Space/Enter) for 1500 ms. - Start: a red outlined button reading "Hold to delete project". - End: the fill completes, the project is deleted via an async `onDelete` prop, and the button shows "Project deleted". **States** - Idle: red outline, transparent fill. - Hover: background tints red-50, 150 ms ease-out. - Focus-visible: 2px red ring with 2px offset, instant. - Holding: a red fill sweeps left to right over exactly 1500 ms, linear easing. Label becomes "Keep holding…". Button scales to 0.98 over 100 ms ease-out. - Release early: fill reverses to 0 over 250 ms ease-out, label resets. - Deleting: fill is full, spinner replaces the label text, button disabled, `aria-busy` true. - Success: fill turns green over 200 ms ease-in-out, with a check icon and "Project deleted". - Error: fill drains over 300 ms ease-out, the button shakes ±4px for 300 ms, and an inline message appears: "Couldn't delete. Try again." **Accessibility** - Use a native `<button>`. Support Space and Enter keydown to start the hold and keyup to cancel. Ignore key auto-repeat events. - Add `aria-describedby` text: "Press and hold for 1.5 seconds to delete." - Use one polite `aria-live` region announcing "Hold started", "Deletion cancelled", "Project deleted" or the error. Do not announce progress percentages. - Reduced motion (`prefers-reduced-motion`): no scale, shake or sweeping animation. Show a stepped progress text ("Holding 1 of 3…") or a static bar updated in steps, and use 0 ms colour changes. **Edge cases** - Early release, pointer leave, pointer cancel, blur or Escape: cancel the timer and reverse the fill. - Touch: use pointer events with pointer capture, suppress the context menu and text selection (`touch-action: none`). A quick tap shows the hint "Press and hold" and does not delete. - Held Space: start only on the first keydown, never repeat, and prevent page scroll. - Network failure after the hold: enter the Error state, re-enable the button and allow retry. - Double press: lock with a ref once the hold completes, so `onDelete` is called at most once. Ignore input while deleting or after success. - Clear all timers on unmount. **Acceptance checks** - Releasing at 1.4 s never deletes; holding to 1.5 s deletes once. - Keyboard-only users can complete the hold with Space and Enter. - A screen reader announces start, cancel, success and error. - With reduced motion on, nothing slides or shakes. - A mocked failing request shows the error and permits retry. - Rapid double presses trigger exactly one request. - A short tap on mobile does nothing destructive.

Run on Claude Sonnet 5.5, 09 Nov 2026. Automatic check: 2 out of 5.

Mentioned for

Claude, ChatGPT, Gemini, Cursor

Where it came from

Found on Hacker News, shared by elwingo1: Show HN: UI micro interactions prompts for AI.

This is our own version of the idea, written and tested by us. The original may differ.

More coding prompts

Coding Worked in our test
Generate Strict JSON Spec From Description

You get a clean, machine-readable JSON object that matches your rules on the first try. It works because the model reads the rules first, then checks its own answer against each one before replying.

Found on GitHub, shared by DominikScholz
Coding Partly worked
Match Ownership Wording to Change Size

You get a tightly scoped code change, plus a separate list of things the AI spotted but left alone. It works because you state how far the AI may go, so a sense of "ownership" does not trigger unrequested refactoring.

Found on Web, shared by explainx.ai
Coding Worked in our test
Turn Vague Bug Reports Into Concrete Objectives

You get a bug fix broken into a reproduction, a minimal change and a regression test, each checked against clear objectives. Concrete objectives stop the model drifting into large rewrites or guessing at what "fixed" means.

Found on Web, shared by David Ch (@chhddavid)