Frontend School

Interactive Tweet Card: Tooltip & Popover

Machine Coding
medium

Interactive Tweet Card: Tooltip & Popover

Medium
React
UI
Component Design
Tooltip
Popover
Accessibility

Overview

Twitter's user experience thrives on rich, interactive elements that provide context without overwhelming the main content. For L4 engineers, building these foundational UI components efficiently and robustly is critical. This problem focuses on enhancing a basic Tweet Card by integrating a Tooltip for quick user information and a Popover for more detailed profile previews, demonstrating your ability to build composable, accessible, and well-structured React components.

What you need to do / Task

Your task is to implement and integrate two core UI components, Tooltip and Popover, into a TweetCard component.

  1. Implement a Tooltip component:
    • It should accept content (the text/JSX to display) and children (the trigger element).
    • When the children element is hovered, the content should appear. It should disappear on mouse leave.
  2. Implement a Popover component:
    • It should accept content (the text/JSX to display) and children (the trigger element).
    • When the children element is clicked, the content should appear. It should disappear when clicking outside of the popover or its trigger, or when the Escape key is pressed.
  3. Integrate into TweetCard:
    • Wrap the username (@{author.username}) with the Tooltip component to display the author.fullName on hover.
    • Wrap the profile picture with the Popover component to display a detailed user preview (provided in the sandpackFiles as user-popover-details) on click.

UI/UX expectations

  • Tooltip:
    • Appears on mouseenter of the username, disappears on mouseleave.
    • Should be positioned reasonably close to the username (e.g., above or below).
    • Minimal styling, typically a dark background with light text.
  • Popover:
    • Appears on click of the profile picture, disappears on click outside or Escape key press.
    • Should be positioned reasonably close to the profile picture (e.g., below or to the side).
    • More elaborate content display, as shown in the provided mock-up for user-popover-details.
  • Accessibility:
    • The Popover should be dismissible via the Escape key.
    • Consider basic aria attributes if time permits, e.g., aria-describedby for the tooltip (optional, but a plus).

Acceptance criteria

  • The Tooltip component correctly displays the author's full name when hovering over the username.
  • The Tooltip disappears when the mouse leaves the username area.
  • The Popover component correctly displays the user details when the profile picture is clicked.
  • The Popover disappears when clicking anywhere outside of the popover content or its trigger.
  • The Popover disappears when the Escape key is pressed.
  • Both the Tooltip and Popover are positioned logically relative to their trigger elements.
  • The overall TweetCard layout remains functional and readable.

Constraints

Constraints & assumptions

  • You will be working in a React environment.
  • Basic HTML and CSS are sufficient; no need for advanced animation libraries or complex styling frameworks.
  • Data for the tweet and user is provided directly as props to the TweetCard component.
  • Focus on functional components and React hooks.
  • Assume a single TweetCard instance is rendered for simplicity.
  • Basic positioning (e.g., position: absolute with top/left offsets) is expected. No need for full-fledged auto-positioning logic that handles viewport collisions.

Out of scope

  • Advanced positioning logic (e.g., dynamic edge-of-screen adjustments, auto-flipping).
  • Full keyboard navigation support for popovers (e.g., tab trapping within the popover).
  • Backend integration, data fetching, or state management beyond local component state.
  • Extensive styling or theming; focus on functionality and basic visual coherence.

What interviewers evaluate

  • Component Design: How well Tooltip and Popover are encapsulated, reusable, and follow React best practices.
  • State Management: Effective use of useState, useRef, and useEffect for managing visibility and event listeners.
  • Interaction Logic: Correct implementation of hover, click, click-outside, and keyboard event handling.
  • Positioning: Ability to dynamically position the overlay components relative to their triggers.
  • Accessibility: Basic consideration for user experience, specifically Escape key dismissal.

Loading editor...