Frontend School

Build a Resizable Split Pane Component

Machine Coding
medium

Build a Resizable Split Pane Component

Medium
React
UI
Split Pane
Drag and Drop
Layout
Machine Coding

Overview

Modern applications, from IDEs to dashboards, often require flexible layouts that allow users to customize their workspace. A common UI pattern for this is the "Split Pane," which enables users to dynamically resize adjacent content areas. This problem challenges you to build a robust and interactive SplitPane component, a fundamental building block for highly configurable user interfaces. Mastering this pattern demonstrates strong understanding of DOM manipulation, event handling, and responsive UI design in React.

What you need to do / Task

Your primary task is to create a SplitPane React component that allows a user to resize two horizontal content areas by dragging a divider between them.

  1. Component Definition: Implement a functional React component named SplitPane.
  2. Pane Rendering: The SplitPane component should accept two React.ReactNode children, leftPane and rightPane, and render them side-by-side.
  3. Resizable Divider: Render a visible, interactive divider between the leftPane and rightPane.
  4. Drag-to-Resize: Users must be able to click and drag this divider horizontally to adjust the width of both panes simultaneously.
  5. Initial Configuration: The component should accept an initialRatio prop (a number between 0 and 1) to set the initial width distribution of the panes. If not provided, default to 0.5 (50/50 split).
  6. Minimum Pane Width: The component should accept a minPaneWidth prop (a number in pixels) to prevent either pane from shrinking below a specified minimum width. If not provided, default to 100 pixels.

UI/UX expectations

  • Visual Divider: The divider should be clearly visible and distinguishable from the content panes.
  • Cursor Feedback: When hovering over the divider, the cursor should change to ew-resize (east-west resize) to indicate it's draggable.
  • Smooth Resizing: Panes should resize smoothly as the divider is dragged, without significant lag or flickering.
  • Containment: The SplitPane component should occupy 100% width and height of its parent container.

Acceptance criteria

  • The SplitPane component renders two distinct content areas (left and right) and a divider between them.
  • Dragging the divider horizontally successfully resizes both the left and right panes proportionally.
  • The initialRatio prop correctly sets the initial width distribution of the panes.
  • Neither pane can be resized below the minPaneWidth value.
  • The cursor changes to ew-resize when hovering over the divider.
  • The component behaves correctly even when the parent container is resized (e.g., window resize).

Constraints

Constraints & assumptions

  • You must implement the SplitPane component as a React functional component.
  • You are not allowed to use any third-party libraries specifically for split pane functionality (e.g., react-split-pane, re-resizable). Build the core logic from scratch.
  • The component should handle horizontal splitting only (left/right panes). You do not need to implement vertical splitting.
  • The parent container of SplitPane is assumed to have a defined width and height.
  • minPaneWidth will be a positive integer.

Out of scope

  • Vertical (top/bottom) split panes.
  • Nested split panes (split pane within a split pane).
  • Saving/loading pane sizes to persistent storage.
  • Advanced accessibility features beyond standard cursor changes (e.g., keyboard navigation for resizing).
  • Context menus or additional controls on the divider.

What interviewers evaluate

  • Correctness and Robustness: Does the drag-to-resize functionality work as expected, handling edge cases like minimum pane widths?
  • Component Design: Is the SplitPane component well-structured, reusable, and does it follow React best practices (e.g., prop types, state management, event handling)?
  • Performance: Does the resizing feel smooth and responsive, avoiding excessive re-renders or layout thrashing?
  • UI/UX Details: Is the user experience intuitive, with appropriate visual feedback like cursor changes?
  • Code Quality: Is the code clean, readable, and maintainable, with clear variable names and logical flow?

Loading editor...