Frontend School

Dynamic Resizable Layout with Nested Split Panes

Machine Coding
hard

Dynamic Resizable Layout with Nested Split Panes

Hard
React
UI
Split Pane
Drag and Drop
Accessibility

Overview

Modern productivity applications, especially those in the Zoho suite, heavily rely on flexible and customizable user interfaces. A common requirement is the ability for users to dynamically adjust the layout of different content areas. This problem challenges you to build a robust and reusable SplitPane component that allows users to resize adjacent content areas by dragging a divider. The component should support both horizontal and vertical splitting and, critically, allow for nesting to create complex, multi-dimensional layouts.

What you need to do / Task

Your primary task is to implement a SplitPane React component that offers dynamic resizing capabilities.

  1. Core SplitPane Component: Create a SplitPane component that accepts children (representing the content of each pane), a direction prop ('horizontal' or 'vertical'), and an optional initialSizes prop (an array of numbers representing initial percentage values for each pane). Each SplitPane instance must also take a unique id prop for persistence.
  2. Resizable Dividers: Implement a draggable divider between the panes. When a user drags this divider, the sizes of the adjacent panes should adjust dynamically.
  3. Nested Split Panes: Ensure your SplitPane component can be nested. For example, a main vertical split where one of the panes itself contains a horizontal split. This requires careful consideration of how sizing and drag events propagate.
  4. Minimum Pane Size: Each pane should respect a minimum size (e.g., 50px or 10% of the container, configurable via a minSize prop, defaulting to 50px). Panes should not be able to shrink below this threshold.
  5. State Persistence: The sizes of the panes should be persisted (e.g., in localStorage) and restored upon component mount, providing a consistent user experience across sessions. The unique id prop should be used to store and retrieve sizes for each specific SplitPane instance.

UI/UX expectations

  • Visual Dividers: A clear, visually distinct divider should separate the panes.
  • Cursor Feedback: The cursor should change to ew-resize for horizontal splits and ns-resize for vertical splits when hovering over the divider.
  • Smooth Resizing: Resizing should feel fluid and responsive, without jank or flickering.
  • Accessibility: The divider should be focusable via keyboard (tab). Users should be able to resize panes using arrow keys (e.g., left/right for horizontal, up/down for vertical splits) when the divider is focused. Appropriate ARIA attributes (e.g., role="separator", aria-orientation, aria-valuenow, aria-valuemin, aria-valuemax) should be used.
  • Default Layout: The provided App.tsx will demonstrate a nested layout. Your component should render this structure correctly.

Acceptance criteria

  • The SplitPane component correctly renders its children arranged according to the specified direction (horizontal or vertical).
  • Dragging the divider accurately resizes the two adjacent panes, respecting the minSize constraint.
  • Nested SplitPane components function independently and correctly within their parent panes.
  • Pane sizes are persisted to and loaded from localStorage based on a unique id for each SplitPane instance.
  • The divider's cursor changes on hover.
  • The divider is keyboard-focusable and resizable via arrow keys, with appropriate ARIA attributes.
  • The overall layout and interaction feel smooth and responsive.

Constraints

Constraints & assumptions

  • You are building this component in a React environment.
  • You should implement the split-pane logic from scratch; do not use external UI libraries specifically for split-pane functionality (e.g., react-split-pane, re-resizable). Basic utility libraries like lodash are acceptable if needed, but the core logic should be custom.
  • The component should be robust enough to handle varying numbers of children (at least 2, up to 5-6).
  • Focus on functional correctness and clean, modular component design.
  • Assume the parent container of the top-level SplitPane has a defined size.
  • initialSizes will be an array of percentages summing to 100, or will be absent, in which case panes should distribute evenly.

Out of scope

  • Advanced animations beyond smooth resizing.
  • Server-side persistence of layout preferences.
  • Complex context menus or toolbar interactions within panes.
  • Extensive error handling for invalid initialSizes array length (assume it matches children count if provided).

What interviewers evaluate

  • Component Design & Reusability: How well the SplitPane component is designed for reusability, extensibility, and clarity.
  • Core Logic Implementation: Correctness and efficiency of the drag-and-drop resizing mechanism, and the handling of mixed percentage/pixel-based sizing (for initialSizes and minSize).
  • Nesting & Edge Cases: Ability to correctly implement and manage nested split panes, including handling minimum sizes and size distribution.
  • UI/UX & Accessibility: Attention to detail in visual feedback (cursors, smooth resizing) and basic accessibility features (keyboard navigation, ARIA attributes).
  • State Management & Persistence: Effective use of React state/refs and proper implementation of local storage persistence.

Loading editor...