Define keyboard behavior before markup
This exercise uses nested lists and native buttons. A folder button exposes aria-expanded; a file button exposes its selected toggle state with aria-pressed. Tab, Enter, and Space work through browser behavior. Do not add role=tree unless you also implement its distinct focus and arrow-key contract.
Recurse over data
A FileNode renders a row, then maps folder children to more FileNode elements. The same component handles each supplied depth without hard-coded levels. This is appropriate for an interview-sized fixture; it is not a promise of unlimited stack depth or production-scale rendering.
Keep durable UI state above hidden branches
FileExplorer owns expandedIds as a Set and selectedId as a scalar. If each nested component owned its open flag, unmounting children on parent collapse would erase that flag. A shared Set retains expansion independently of whether descendants are mounted.
Update immutably
Copy the previous Set, add or remove one ID, and return the copy from a functional state update. Mutating the old Set and returning it can prevent React from noticing the change. Use node.id as each key, since README.md can exist in several folders.
Derive structure and selection
Indent through nested list padding. File nodes do not recurse, even if malformed data supplies children. Missing children on a folder are treated as empty. Selecting a file changes only selectedId; toggling folders changes only expandedIds. When the selected file is hidden, retain its selection so it reappears after reopening.
Try the difficult path
Open src, components, then forms. Select Input.jsx. Collapse and reopen src: forms is still expanded and Input.jsx is still selected. Open assets to see Empty folder. Select the two README.md files separately to confirm name collisions do not share identity.