Frontend School

Resizable Vertical Split Pane Component

Machine Coding
medium

Resizable Vertical Split Pane Component

Medium
UI
React
Split Pane
Resizing
Machine Coding

Overview

Modern applications, especially those in data visualization, IDEs, or dashboards, often require flexible layouts where users can dynamically adjust the size of different content areas. A common pattern for this is a 'Split Pane' component. This problem focuses on building a robust and interactive vertical split pane, allowing users to intuitively resize two content areas (top and bottom) by dragging a divider.

What you need to do / Task

Your task is to implement a React functional component named SplitPane that renders two distinct content areas, topContent and bottomContent, separated by a draggable horizontal divider. The user should be able to drag this divider vertically to resize the top and bottom panes.

Deliverables:

  1. SplitPane Component: Create a SplitPane React component that accepts topContent and bottomContent as React.ReactNode props.
  2. Draggable Divider: Implement a horizontal divider between the two content areas that can be dragged vertically using the mouse.
  3. Dynamic Resizing: As the divider is dragged, the height of the topContent pane should adjust, and the bottomContent pane should automatically fill the remaining available height within the SplitPane container.

UI/UX expectations

  • Initial State: The SplitPane should initially divide the available vertical space equally (50/50 split) between the top and bottom panes.
  • Divider Appearance: The divider should be visually distinct (e.g., a thin bar) and have its cursor change to ns-resize when hovered over.
  • Minimum Pane Size: Both the top and bottom panes must maintain a minimum height of 50px to prevent them from collapsing completely.
  • Content Overflow: If the content within a pane exceeds its allocated height, the pane should display vertical scrollbars to allow viewing of all content.

Acceptance criteria

  • The SplitPane component renders topContent and bottomContent props correctly.
  • A visually distinct horizontal divider separates the two content areas.
  • Hovering over the divider changes the cursor to ns-resize.
  • Clicking and dragging the divider vertically resizes the top and bottom panes dynamically.
  • The top and bottom panes respect a minimum height of 50px during resizing.
  • Content within each pane correctly scrolls if it overflows its current height.
  • The component behaves predictably across common browser interactions (e.g., fast dragging, releasing mouse outside of divider).

Constraints

Constraints & assumptions

  • You must use React functional components and hooks.
  • No external libraries specifically for split pane functionality are allowed. Implement the resizing logic yourself using native browser APIs (e.g., MouseEvent, window.addEventListener).
  • The SplitPane component should occupy 100% width and a predefined height of its parent container. Assume the parent container provides adequate height for the split pane to function.
  • Focus on a vertical split (horizontal divider, top/bottom panes) only.

Out of scope

  • Nested split panes (e.g., splitting one of the existing panes).
  • Saving or restoring pane sizes (e.g., to local storage).
  • Keyboard accessibility for resizing the panes.
  • Horizontal split panes (vertical divider, left/right panes).

What interviewers evaluate

  • Correctness and Functionality: Does the split pane resize accurately and handle edge cases like minimum pane sizes?
  • React Proficiency: Effective use of React state, refs, and event handling for a dynamic UI component.
  • Code Quality: Clean, readable, modular, and maintainable code structure.
  • Browser API Usage: Appropriate use of DOM APIs for mouse events and element measurements.

Loading editor...