Flat tree view of bucket keys using aria-level for folders
A cloud storage console lists the objects in a bucket. Storage has no real folders: every object is just a key such as reports/2025/q3-summary.pdf, and the console builds folders from the / separators. Build that browser as a tree view, but render it the way large tree views often are for performance: as one flat list of rows, where depth is expressed with aria-level (and indentation) instead of nested elements.
The starter code includes the bucket’s keys, in no particular order:
const OBJECT_KEYS = [
'reports/2025/q4-summary.pdf',
'index.html',
'images/logo.svg',
'reports/2025/q3-summary.pdf',
'images/',
'images/icons/close.svg',
'reports/readme.txt',
'images/2025/banner.png',
'images/icons/Arrow.svg',
'favicon.ico',
'reports/2024/annual.pdf',
'archive/',
];
/. Every segment except the last is a folder; the last segment is a file./ (like archive/) is a folder placeholder: it creates the folder and no file. archive is an empty folder. images/ must not create a second images folder.images, not images/.name.toLowerCase()). Don’t mutate OBJECT_KEYS.role="tree" and the accessible name Bucket contents (an aria-label, or aria-labelledby pointing at a visible heading).role="treeitem" that is a direct child of the tree element. Don’t nest treeitems and don’t use role="group". A folder’s visible children come right after it in the list, depth first.aria-level: 1 for top-level items, 2 for their children, and so on.aria-setsize: how many items share its parent folder, and aria-posinset: its 1-based position among them, in the sorted order.aria-hidden="true".aria-expanded="false" when collapsed and "true" when expanded. Files have no aria-expanded.images and icons, collapse images, expand images again, and icons is still expanded.images/2025 and reports/2025). Expanding one must not expand the other.aria-selected="true"; no other treeitem has aria-selected="true".Selected: {key} with the file’s full key, for example Selected: images/icons/Arrow.svg. Before anything is selected, show No file selected.Load archive, images, reports, favicon.ico, index.html (level 1, setsize 5)
Click "images" archive, images, 2025, icons, logo.svg, reports, ... (2025, icons, logo.svg at level 2)
Click "icons" ... icons, Arrow.svg, close.svg, logo.svg ... (level 3)
Click "Arrow.svg" "Selected: images/icons/Arrow.svg"
Expand all 17 rows
Collapse all the 5 top-level rows again
Arrow.svg sorts before close.svg because the comparison ignores case.2025 appears under both images and reports: key expansion state by full path.archive folder still flips its aria-expanded; it just adds no rows.Keyboard navigation inside the tree is out of scope for this problem.
The tests read the page through ARIA, the way a screen reader does. You don’t need test ids or class names. They:
role="tree" element and check its aria-label or aria-labelledby name,role="treeitem" elements in DOM order, using each one’s text as its name, and check that each is a direct child of the tree,aria-level, aria-setsize, aria-posinset, aria-expanded and aria-selected,Selected: {key} and No file selected text.Capitalization and extra spacing don’t matter.