Frontend School

Implement a Transaction Details Modal Component

Machine Coding
medium

Implement a Transaction Details Modal Component

Medium
React
TypeScript
Frontend
UI
Modal
Accessibility
State Management

Overview

In a financial dashboard, users often need to view detailed information about specific transactions without navigating away from their current context. A modal dialog is a common and effective UI pattern for presenting such details. This problem focuses on building a robust, reusable, and accessible TransactionDetailsModal component that can display comprehensive information about a given transaction.

What you need to do / Task

Your primary task is to implement the TransactionDetailsModal component based on the provided Transaction interface and mock data.

  1. Create the TransactionDetailsModal component: Implement the TransactionDetailsModal component that receives isOpen, onClose, and transaction as props.
  2. Display Transaction Details: Within the modal, present the details of the transaction object in a clear and readable format (e.g., ID, Amount, Status, Date, Customer Name, Payment Method).
  3. Modal Control: The modal should open when isOpen is true and close when isOpen is false.
  4. Close Mechanisms: Implement multiple ways to close the modal:
    • An explicit close button (e.g., an 'X' icon or a 'Close' text button).
    • Pressing the Escape key.
    • Clicking on the semi-transparent backdrop outside the modal content.
  5. Accessibility: Ensure the modal is accessible for all users, including those using keyboard navigation or screen readers.

UI/UX expectations

  • When open, the modal should overlay the main content, typically centered on the screen.
  • A semi-transparent overlay (backdrop) should cover the rest of the page content, indicating that the main content is inactive.
  • The modal content area should be scrollable if its height exceeds the viewport height.
  • The modal should have a clear header, body, and footer structure.
  • The close button should be visually distinct and easily discoverable.

Acceptance criteria

  • The TransactionDetailsModal component renders and displays the provided transaction data correctly.
  • The modal opens when the isOpen prop is true and is hidden when isOpen is false.
  • Clicking the dedicated close button within the modal successfully closes it by triggering the onClose callback.
  • Pressing the Escape key closes the modal by triggering the onClose callback.
  • Clicking on the modal's backdrop (outside the main content area) closes the modal by triggering the onClose callback.
  • When the modal is open, keyboard focus is trapped within the modal, preventing users from tabbing to elements outside the modal.
  • When the modal closes, keyboard focus is restored to the element that triggered the modal's opening.
  • Appropriate ARIA attributes (e.g., role="dialog", aria-modal="true", aria-labelledby) and semantic HTML elements are used to enhance accessibility.

Constraints

Constraints & assumptions

  • You must use React and TypeScript for this implementation.
  • No external modal libraries or UI component frameworks (e.g., Chakra UI, Ant Design) are allowed; build the modal from scratch using native browser APIs and React hooks.
  • The modal component will receive a Transaction object as a prop; you do not need to fetch this data.
  • Assume a basic parent component (already provided in App.tsx) will manage the modal's open/close state.
  • Styling should be functional and demonstrate the UI/UX expectations (e.g., basic centering, backdrop opacity, content layout). Extensive aesthetic styling is not the primary focus.

Out of scope

  • Complex animations for modal opening/closing.
  • Form submissions or data mutations within the modal (e.g., editing transaction details).
  • Internationalization or localization of currency/dates.

What interviewers evaluate

  • Component Design: How well the TransactionDetailsModal component is structured, its reusability, and adherence to React best practices.
  • Functional Correctness: Accurate implementation of modal behavior, including opening/closing logic and interaction handling (backdrop, keyboard).
  • Accessibility: Proper use of ARIA attributes, semantic HTML, and focus management for an inclusive user experience.
  • Code Quality: Readability, maintainability, effective use of TypeScript, and overall code organization.

Loading editor...