Expand Folders in a File Tree
Write the code, see it run, pass the checks.
The problem
- medium
- Code
The FileTree component gets a tree prop: a list of nodes, each { name } for a file or { name, children } for a folder, where children is a list of nodes in the same shape, so folders nest to any depth (a folder may be empty). Render it recursively, as nested lists. Every folder and every file is a button whose text is just its name (an icon is fine if it has aria-hidden="true"). Folders start closed; clicking a folder opens or closes it, and its button has aria-expanded, "true" while open and "false" while closed. A folder's contents show only while it's open (leave them out, or hide them with the hidden attribute). Files have no aria-expanded. Clicking a file shows a line with its full path, the names from the top joined with slashes, like "Selected: src/components/Button.jsx".
Your code must pass
- Shows the top-level folders and files, with every folder closed
- Clicking a folder opens it and shows its contents
- Clicking an open folder closes it
- Folders open at any depth
- Clicking a file shows its full path, like "Selected: src/components/Button.jsx"