Frontend School

Reorderable Task List

Machine Coding
easy

Reorderable Task List

Easy
Drag and Drop
Frontend
UI

Overview

At Browserstack, managing test cases, test runs, or even simple project tasks often involves lists of items that need flexible organization. The ability to reorder items intuitively via drag-and-drop is a fundamental UI pattern that significantly enhances user experience and productivity. This problem challenges you to implement a basic drag-and-drop reordering feature for a list of tasks, simulating a common interaction found in many of our products.

What you need to do / Task

Your goal is to build a simple React component that displays a list of tasks. Users should be able to reorder these tasks by dragging an item and dropping it into a new position within the list.

  1. Render a list of tasks: Display a predefined set of tasks as a vertical list.
  2. Enable Dragging: Make each task item draggable.
  3. Enable Dropping and Reordering: Allow users to drop a dragged task item into a new position in the list, effectively reordering the tasks. The list should visually update to reflect the new order.

UI/UX expectations

  • Clear Items: Each task item should be clearly distinguishable (e.g., with a border or background).
  • Drag Feedback: When an item is being dragged, it should provide visual feedback (e.g., a semi-transparent ghost image or a temporary border/shadow around the dragged item).
  • Drop Target Feedback: As a dragged item hovers over potential drop locations, there should be visual cues indicating where the item will be placed (e.g., a gap appearing, or a border highlighting the insertion point).
  • Smooth Reorder: The list should update smoothly to reflect the new order without jarring jumps.

Acceptance criteria

  • The initial list of tasks renders correctly.
  • Any task item can be picked up and dragged.
  • A dragged task item can be dropped at any valid position (start, middle, or end) within the list.
  • Upon a successful drop, the list items are reordered according to the drop position.
  • The UI updates immediately to show the new order of tasks.
  • No console errors occur during drag-and-drop operations.

Constraints

Constraints & assumptions

  • You must use React (with TypeScript) for building the UI.
  • The task data will be a simple in-memory array of objects. No backend integration or data persistence is required.
  • Focus on the core drag-and-drop functionality using native HTML5 Drag and Drop APIs.
  • The application should be a single-page component.

Out of scope

  • Advanced accessibility features beyond standard semantic HTML elements.
  • Complex animations for item reordering (simple visual updates are sufficient).
  • Support for multiple lists or dragging items between different containers.
  • External drag-and-drop libraries (e.g., react-beautiful-dnd). Focus on native APIs.

What interviewers evaluate

  • Correctness: Does the drag-and-drop reordering work as expected?
  • Code Quality: Is the code clean, readable, well-structured, and idiomatic React/TypeScript?
  • State Management: Is React's state managed effectively and immutably for list reordering?
  • UI/UX Details: Are basic visual feedbacks for drag and drop implemented?

Loading editor...