FrontendInterviews.dev

Loading problem…

19. File Explorer Tree II

Medium•
Acceptance: 53.00%
•
🔓3/3 Pro unlocks today

This problem builds on file-explorer. Complete that first, then load your solution to continue.

Build an enhanced File Explorer component that extends the basic file explorer with search functionality.

New Features

1. Search/Filter Functionality

  • Add a search input field at the top
  • Filter files and folders by name as user types
  • Highlight matching text in file/folder names
  • Show only matching items and their parent folders (to maintain hierarchy)
  • Clear search button to reset filter

4. Enhanced Data Structure

interface FileNode {
  id: number;
  name: string;
  type: 'file' | 'folder';
  children?: FileNode[];
  size?: number; // File size in bytes (optional)
  modified?: string; // Last modified date (optional)
}

interface FileExplorerProps {
  data: FileNode[];
}

5. Example Data

const exampleData: FileNode[] = [
  {
    id: 1,
    name: 'src',
    type: 'folder',
    children: [
      {
        id: 2,
        name: 'components',
        type: 'folder',
        children: [
          { id: 3, name: 'Button.tsx', type: 'file', size: 1024 },
          { id: 4, name: 'Card.tsx', type: 'file', size: 2048 },
        ],
      },
      { id: 5, name: 'App.tsx', type: 'file', size: 512 },
    ],
  },
  {
    id: 6,
    name: 'package.json',
    type: 'file',
    size: 256,
  },
];

Requirements Summary

  1. Search: Real-time filtering with highlighted matches
  2. Maintain Previous Features: Expand/collapse, selection from File Explorer Tree I
  3. Accessibility: Proper ARIA attributes and semantic HTML

Constraints

  • Maintain all features from File Explorer Tree I
  • Search should filter in real-time as user types
  • Keyboard navigation should work even when items are filtered
  • Use semantic HTML and proper ARIA attributes
  • Handle edge cases: empty search, no matches, keyboard navigation at boundaries
  • Focus management: maintain focus when filtering/searching