Frontend School

Resizable Horizontal Split View

Machine Coding
medium

Resizable Horizontal Split View

Medium
Resizable Panels
UI
React
Frontend
DOM Events

Overview

Many modern applications, from IDEs to data dashboards, require flexible layouts where users can adjust the size of content areas. This problem challenges you to build a foundational component for such a layout: a horizontal split view with resizable panels. This is a common UI pattern that demonstrates your ability to manage DOM interactions, state, and responsive styling.

What you need to do / Task

Your task is to implement a ResizablePanels React component that displays two child components side-by-side, separated by a draggable vertical divider.

  1. Create the ResizablePanels component: This component should accept two React elements as leftPanel and rightPanel props.
  2. Implement the layout: The component should render the leftPanel, a draggable divider, and the rightPanel horizontally. The panels should initially share the available width equally.
  3. Enable resizing: When the user clicks and drags the divider, the width of the leftPanel and rightPanel should adjust accordingly. The total width of the ResizablePanels container should remain constant.
  4. Enforce minimum width: Each panel should have a minimum width (e.g., 100px). The divider should stop moving if dragging it further would cause a panel to shrink below its minimum width.

UI/UX expectations

  • The ResizablePanels component should occupy 100% width and height of its parent container.
  • The divider should be visually distinct (e.g., a thin vertical line).
  • When the user hovers over the divider, the cursor should change to ew-resize to indicate it's draggable.
  • During a drag operation, the panels should resize smoothly without flickering or abrupt jumps.
  • The content within the panels should not overflow or cause layout shifts as panels resize, assuming the content itself is responsive.

Acceptance criteria

  • The ResizablePanels component renders with two distinct panels and a visible divider between them.
  • Dragging the divider horizontally successfully resizes both the left and right panels.
  • The total width of the two panels plus the divider remains constant during resizing.
  • Neither panel can be resized below a specified minimum width (e.g., 100px).
  • The mouse cursor correctly changes to ew-resize when hovering over the divider.
  • The UI remains stable and responsive during and after resize operations.

Constraints

Constraints & assumptions

  • You must use React functional components with TypeScript.
  • The solution should be implemented using native browser events (mousemove, mouseup, etc.) without relying on third-party resize libraries.
  • Assume the ResizablePanels component will be rendered within a container that provides a defined width and height.
  • Focus on the core resizing logic for two horizontal panels.
  • Minimum panel width can be a hardcoded constant (e.g., 100px or 10%) or passed as a prop.

Out of scope

  • Vertical resizing or multi-level nested resizable panels.
  • Saving panel sizes to local storage or a backend.
  • Complex accessibility features beyond cursor changes.
  • Extensive styling; basic functional styling is sufficient.

What interviewers evaluate

  • Core Logic Implementation: Correctness and robustness of the drag-to-resize mechanism.
  • React Principles: Effective use of state management, event handling, and functional components.
  • Code Structure: Clarity, modularity, and maintainability of the component.
  • User Experience: Smoothness of the resizing interaction and adherence to UI/UX expectations.

Loading editor...