Frontend School

Interactive Spreadsheet Cell Grid

Machine Coding
medium

Interactive Spreadsheet Cell Grid

Medium
React
UI
State Management
Keyboard Navigation
Forms

Overview

Meesho sellers frequently manage extensive product catalogs, which involve editing various attributes for numerous products. A highly interactive and intuitive spreadsheet-like interface is crucial for efficient data entry and modification. This problem challenges you to build the core interaction for a grid of cells, mimicking a simplified spreadsheet, to significantly enhance the data entry experience for our sellers.

What you need to do / Task

Your task is to implement an interactive grid of cells with selection, editing, and navigation capabilities.

  1. Render a Grid: Display a fixed 5x5 grid of cells. Each cell should initially display a placeholder value (e.g., "R1C1").
  2. Cell Selection: Clicking on any cell should select it, visually highlighting it. Only one cell can be selected at a time. If a cell is in edit mode, clicking another cell should save changes to the currently edited cell before selecting the new one.
  3. Cell Editing:
    • Double-clicking a selected cell should transition it into an editable input field, pre-filled with its current value.
    • Saving Changes: Pressing Enter while in edit mode, or clicking outside the active input field (blur event), should save the new value to the cell and revert it to display mode.
    • Discarding Changes: Pressing Escape while in edit mode should discard any changes made in the input field and revert the cell to display mode, retaining its original value.
  4. Keyboard Navigation: When the grid is focused (e.g., after selecting a cell), the arrow keys (Up, Down, Left, Right) should allow moving the selection to adjacent cells. If an arrow key attempts to move the selection out of the grid boundaries, the selection should remain on the boundary cell.

UI/UX expectations

  • Grid Layout: Cells should be clearly delineated with borders. The grid should maintain a consistent, organized layout.
  • Selected State: A selected cell must be visually distinct (e.g., different background color, border).
  • Edit State: When a cell is in edit mode, an input element should replace the displayed text, allowing modification. This input should automatically focus when edit mode begins.
  • Responsiveness: The UI should be responsive to user interactions without noticeable delays.
  • Accessibility: Keyboard navigation via arrow keys is a core requirement for interaction.

Acceptance criteria

  • A 5x5 grid of cells is rendered, each displaying a value.
  • Clicking a cell selects it and visually highlights it; only one cell is selected at a time.
  • Double-clicking a selected cell transforms it into an editable input field with its current value.
  • Pressing Enter or blurring the input saves the new value and exits edit mode.
  • Pressing Escape discards changes and exits edit mode.
  • Arrow keys (Up, Down, Left, Right) correctly navigate the selected cell within the grid boundaries.

Constraints

Constraints & assumptions

  • Grid Size: The grid will be fixed at 5 rows and 5 columns for this problem.
  • Cell Values: Cell values will be simple strings.
  • Data Management: All grid data and UI state should be managed client-side using React's state management capabilities. No backend integration is required.
  • Technology Stack: Use React for building the UI.
  • Time Budget: This problem is designed to be completable within approximately 45 minutes.

Out of scope

  • Complex formula evaluation (e.g., A1+B1).
  • Copy, cut, or paste functionality.
  • Dynamic addition or deletion of rows/columns.
  • Performance optimizations for extremely large grids.
  • Persistence of data across page loads.

What interviewers evaluate

  • Code Structure & Modularity: Clarity, organization, and reusability of React components.
  • State Management: Effective and appropriate use of React state for managing cell values, selection, and edit mode.
  • Event Handling: Correct implementation of DOM events (click, double-click, keyboard, focus/blur) and their interactions.
  • UI/UX Implementation: Adherence to the specified visual and interaction requirements, ensuring a smooth user experience.

Loading editor...