Question presented to candidate: "Our mobile web app has a round floating action button in the bottom-right corner. Tapping it should fan out a short column of secondary actions (Share, Print, Copy link, Download) with a little staggered animation, and collapse again when you pick one, tap elsewhere or press Escape. Build it."
Requirements:
- A floating action button (FAB) fixed to the bottom-right that toggles a vertical column of action buttons above it; the "+" icon rotates into a "ร".
- Staggered animation: on open the action nearest the FAB appears first; on close the farthest disappears first.
- Choosing an action reports it and closes; Escape closes; a press outside closes; focus returns to the FAB.
- Keyboard: from the open FAB, ArrowUp moves into the actions and up the column, ArrowDown moves back down to the FAB; Tab reaches the actions only while open.
- Each action has a visible text label as well as an icon; respects
prefers-reduced-motion.
What a strong answer should cover:
- Keeping the actions mounted so the close animation can play, and making them
inertwhile closed so they are unreachable. - Computing per-item
transition-delayfrom the index and the direction (open vs close). - Outside-press detection with
contains()and listener cleanup, and focus return to the FAB. - ARIA for the FAB (
aria-expanded,aria-controls, an accessible name) and why icon-only actions need labels. - Reduced motion and touch target sizes (at least 44 px).
Clarifying questions expected:
- "Vertical or radial layout? Which direction does it open?"
- "Should it also open on hover on desktop?"
- "Is it a primary action plus extras, or only a launcher?"
Code / implementation expected: Yes. One component plus a demo; CSS transitions, no animation library.