Frontend School

Dynamic Content Popover with Nested Interactive Tooltips

Machine Coding
hard

Dynamic Content Popover with Nested Interactive Tooltips

Hard
React
TypeScript
UI Components
Tooltip
Popover
Accessibility
State Management
Event Handling

Overview

In modern web applications, rich and contextual information display is crucial for user experience. Imagine you're enhancing a dashboard where users need to quickly understand complex data points or interact with detailed user profiles without navigating away. This problem challenges you to build robust, reusable Popover and Tooltip components that can display dynamic content, handle various interactions, and ensure accessibility.

What you need to do / Task

Your goal is to implement two core UI components: Popover and Tooltip, and demonstrate their combined usage.

  1. Tooltip Component: Create a Tooltip component that displays a brief text message when the user hovers over or focuses on its child element. It should have a configurable delay before appearing and disappearing.
  2. Popover Component: Create a Popover component that displays arbitrary content. It should be triggered by clicking its child element and must close when the user clicks anywhere outside the popover or presses the Escape key.
  3. Integration & Dynamic Content: In the provided App.tsx skeleton, integrate these components. The main task involves a trigger element that opens a Popover containing detailed user information. Crucially, within this Popover's content, there should be another interactive element that itself triggers a Tooltip on hover/focus.

UI/UX expectations

  • Positioning: Both Tooltip and Popover should appear relative to their respective trigger elements. The Popover should ideally appear below its trigger, centered horizontally, and adjust if it goes off-screen (though a basic relative position is sufficient for this round). The Tooltip should appear above or below its target.
  • Interaction: Tooltip should activate on mouseenter and focus, and deactivate on mouseleave and blur, with a short delay (e.g., 300ms). Popover should toggle on click of its trigger, and close on click outside or Escape key press.
  • Styling: Provide minimal but clear styling to differentiate the tooltip and popover from the background content (e.g., background, border, shadow).
  • Accessibility: Ensure both components are accessible via keyboard navigation. Use appropriate ARIA attributes (aria-haspopup, aria-expanded, aria-describedby, role) where relevant.

Acceptance criteria

  • A Tooltip component correctly displays content on hover/focus and disappears on leave/blur, respecting a delay.
  • A Popover component correctly opens when its trigger is clicked.
  • The Popover closes when clicking outside its bounds.
  • The Popover closes when the Escape key is pressed.
  • The Popover and Tooltip are positioned visually close and relative to their respective trigger/child elements.
  • The Popover content dynamically renders the provided ReactNode (e.g., user details).
  • An interactive element inside the Popover correctly triggers its own Tooltip.
  • Both components are keyboard accessible and utilize appropriate ARIA attributes for screen readers.

Constraints

Constraints & assumptions

  • You must implement the Tooltip and Popover components from scratch. Do not use external UI component libraries (e.g., Material UI, Ant Design, Headless UI).
  • Focus on functional correctness and clean, reusable component design over pixel-perfect styling or complex animation.
  • Assume a modern browser environment for JavaScript and CSS features.
  • The data for the popover content (e.g., user details) can be mocked or hardcoded as provided in App.tsx.

Out of scope

  • Complex positioning algorithms that auto-flip the popover/tooltip if it goes off-screen (basic relative positioning is sufficient).
  • Advanced custom animations (simple CSS transitions are acceptable).
  • Full internationalization (i18n) support.

What interviewers evaluate

  • Component Design & Reusability: How well the Tooltip and Popover components are designed to be generic, reusable, and extensible.
  • Correctness & Interaction Logic: Accurate implementation of opening/closing logic, hover/focus states, and outside click/Escape key handling.
  • Accessibility (A11y): Proper keyboard navigation support and semantic use of ARIA attributes.
  • Code Quality: Clean, readable code, effective use of React hooks, and strong TypeScript type definitions.

Loading editor...