Frontend School

Interactive Dashboard: Drag-and-Drop Grid Reordering

Machine Coding
medium

Interactive Dashboard: Drag-and-Drop Grid Reordering

Medium
React
Drag and Drop
Grid
Reordering
Machine Coding
UI

Overview

Modern dashboards often feature customizable layouts, allowing users to arrange information widgets according to their preferences. This problem focuses on building the core interaction for such a feature: enabling users to reorder widgets within a grid using drag-and-drop. This functionality is critical for user personalization and an intuitive user experience.

What you need to do / Task

Your task is to implement a React component that displays a set of predefined widgets in a grid layout. The primary requirement is to enable users to reorder these widgets by dragging and dropping them into new positions within the grid.

  1. Render Widgets: Display the initial WIDGET_DATA in a grid layout.
  2. Implement Drag-and-Drop: Allow users to click, drag, and drop any widget to a new position within the grid.
  3. Visual Feedback: Provide clear visual cues during the drag operation, indicating the item being dragged and potential drop targets.
  4. Reorder Data: Upon a successful drop, update the internal state to reflect the new order of widgets.
  5. Maintain Grid Layout: Ensure the grid layout adapts correctly as items are reordered.

UI/UX expectations

  • Grid Layout: Widgets should be arranged in a responsive grid, ideally using CSS Grid.
  • Draggable Indicators: Each widget should visually indicate that it is draggable (e.g., cursor: grab).
  • Drag Feedback: When a widget is being dragged, it should have a distinct visual appearance (e.g., reduced opacity, a shadow, or a 'ghost' image). A placeholder or visual shift should indicate where the dragged item will be dropped.
  • Smooth Transitions (Optional but appreciated): If time permits, subtle animations for item reordering can enhance the user experience.

Acceptance criteria

  • The initial set of widgets is rendered correctly in a grid structure.
  • Users can initiate a drag operation on any widget.
  • While dragging, the UI provides visual feedback for the item being moved.
  • When a dragged widget is hovered over another widget's potential drop zone, the UI indicates a possible reordering (e.g., a visual shift in the grid).
  • Upon dropping a widget, the grid visually reorders itself to reflect the new position of the dropped item.
  • The underlying widgets state array is updated to match the new visual order.
  • There are no broken UI states (e.g., flickering, incorrect positioning) during or after the drag-and-drop operation.

Constraints

Constraints & assumptions

  • You should use React for this implementation.
  • Focus on native HTML5 Drag and Drop APIs or a minimal custom implementation; external drag-and-drop libraries are not required but can be used if they significantly speed up development without obscuring understanding.
  • The number of widgets is small and fixed (as provided in WIDGET_DATA).
  • Widgets have unique IDs and simple content.
  • No backend integration is required; state management should be entirely client-side.
  • The primary focus is on the core drag-and-drop logic and state management, not pixel-perfect styling or advanced responsiveness.

Out of scope

  • Saving/loading widget layouts (e.g., to local storage or an API).
  • Adding/removing widgets.
  • Complex resizing or configuration of individual widgets.
  • Full keyboard accessibility for drag-and-drop (basic mouse interaction is sufficient).

What interviewers evaluate

  • Correct and robust implementation of drag-and-drop logic using React state.
  • Effective use of React hooks and component lifecycle for managing UI interactions.
  • Clear and maintainable code structure, demonstrating good software engineering practices.
  • Attention to UI/UX details, providing good visual feedback during interaction.

Loading editor...