Home
← All questions

Popup / modal plugin | Frontend Machine Coding

HardPremiumMachine Coding

Frontend Machine Coding interview practice: Design a configurable popup/modal plugin with CTAs, async content, and a priority queue.

Problem

Build a reusable popup/modal plugin driven by an options object.

const options = {
  contentHTML: "HTMLString | Promise",
  onContentClick: () => {},
  showClose: true,
  positiveCTA: { text: "OK", onClick: () => {} },
  negativeCTA: { text: "Cancel", onClick: () => {} },
  // Follow-ups
  animateOnOpen: true,
  backgroundOpacity: 0.5,
  priority: 1,
  closeOthers: false,
};

Requirements

  • Render content (string or a Promise that resolves to content — show a loader until resolved).
  • Optional close button and positive/negative CTAs with click handlers.
  • Backdrop with configurable opacity; clicking content fires onContentClick.

Follow-ups / Hints

  • Animate on open, configurable backdrop opacity.
  • Priority queue: if multiple popups are requested, show the highest priority first and queue the rest; closeOthers dismisses currently open popups.
  • Implementation: a singleton popup manager holding a queue; open(options) enqueues by priority, renders the top one, and on close pops the next. Use a portal to render at the document root and trap focus for accessibility.
Premium question

Unlock the in-browser editor, test cases, and model solution with Mentoxis Premium.

Unlock with Premium