Overview
Spreadsheets are fundamental tools for data organization and analysis. Building a simplified interactive grid component is a common task in frontend development, touching upon state management, event handling, and dynamic rendering. This problem challenges you to create a core part of a spreadsheet application: an editable cell grid that can dynamically calculate the sum of its numeric contents.
What you need to do / Task
Your goal is to implement a React component that displays a grid of cells with the following functionalities:
- Render a Grid: Display a 5x5 grid of cells. Each cell should initially display a value. Some cells may contain numbers, others strings.
- Editable Cells: When a user clicks on a cell, it should transition into an editable state, displaying an
<input type="text" /> element.
- Save Cell Value: After editing, pressing the
Enter key or clicking outside the input field (blur event) should save the new value and revert the cell back to its display state.
- Live Summation: Below the grid, display the sum of all numeric values currently present in the grid's cells. This sum should update automatically whenever any cell's value is changed to a new numeric value. Non-numeric cell values should be ignored in the sum calculation.
UI/UX expectations
- The grid should be clearly structured, resembling a table or a set of uniform boxes.
- When a cell is in edit mode, it should be visually distinct (e.g., a border around the input field, a different background).
- The sum display should be clearly visible below the grid.
- Basic styling to make the grid and cells presentable is expected.
Acceptance criteria
- The application renders a 5x5 grid of cells.
- Each cell correctly displays its initial value.
- Clicking a cell enables an input field within it for editing.
- Editing a cell's value and pressing
Enter or blurring the input updates the cell's displayed value.
- The sum displayed below the grid accurately reflects the total of all numeric cell values.
- The sum updates automatically and correctly whenever a cell's value is modified to a numeric value.
- Non-numeric cell values (e.g., "hello") are correctly excluded from the sum calculation.