Frontend School

Sortable Task List with Drag and Drop

Machine Coding
medium

Sortable Task List with Drag and Drop

Medium
Drag and Drop
React
UI
Frontend

Overview

At CRED, efficiency and organization are key. We're building a new feature for our internal task management system that allows users to easily prioritize their daily tasks. This problem focuses on implementing an intuitive drag-and-drop interface for reordering a list of tasks.

What you need to do / Task

Your goal is to build a React component that displays a list of tasks and allows users to reorder them using drag-and-drop interactions.

  1. Render a List of Tasks: Display an initial list of tasks, each with a title and a priority number.
  2. Implement Drag-and-Drop Reordering: Enable users to click, drag, and drop any task item to a new position within the list.
  3. Update Task Order: When a task is dropped, the underlying data array should be updated to reflect the new order, and the UI should immediately reflect this change.
  4. Visual Feedback: Provide clear visual cues during the drag-and-drop process, such as highlighting the dragged item and indicating the potential drop zone.

UI/UX expectations

  • Layout: The tasks should be displayed as a vertical list. Each task item should be clearly distinguishable (e.g., with a border or background color).
  • Interaction: A user should be able to drag any task item from its current position and drop it between any two other tasks, or at the beginning/end of the list.
  • Drag Feedback: The item being dragged should have a distinct visual style (e.g., reduced opacity, different background).
  • Drop Zone Feedback: As a dragged item hovers over another item's potential drop position, there should be a visual indicator (e.g., a border around the target area, or a gap opening up) to show where the item will be placed.
  • Accessibility: Use semantic HTML elements where appropriate for list structures.

Acceptance criteria

  • Users can successfully drag a task and drop it into a new position in the list.
  • The visual order of tasks updates immediately and correctly after a drop.
  • The internal state (array of tasks) accurately reflects the new order after a successful drag-and-drop operation.
  • Dragging an item provides visual feedback (e.g., opacity change).
  • Dropping an item between two existing items correctly inserts it without breaking the order of other items.
  • No unexpected layout shifts or scroll jumps occur during the drag operation.

Constraints

Constraints & assumptions

  • You are working within a modern React environment.
  • The list will contain a small number of items (e.g., 5-10 tasks).
  • All data is client-side; no backend integration is required.
  • Focus on core browser Drag and Drop API (draggable, ondragstart, ondragover, ondrop, etc.) or a simple custom implementation. Avoid heavy third-party D&D libraries unless absolutely necessary and time permits.
  • The application should be functional in modern web browsers (Chrome, Firefox, Safari).

Out of scope

  • Complex animations beyond basic visual feedback (e.g., smooth transitions for item reordering).
  • Full accessibility support for screen readers beyond basic semantic HTML.
  • Persistence of task order across page reloads or different sessions.
  • Nested drag-and-drop lists or dragging items between multiple lists.
  • Keyboard-based reordering.

What interviewers evaluate

  • Core Drag-and-Drop Functionality: Correct implementation of the drag-and-drop logic using browser APIs or a custom approach.
  • State Management: Effective use of React state to manage and update the task list order.
  • UI Responsiveness and Feedback: Clear visual cues and smooth user experience during drag-and-drop.
  • Code Structure and Readability: Clean, modular, and understandable code with appropriate component breakdown.

Loading editor...