Question presented to candidate: "Our file manager shows where you are as a trail: Home / Projects / Codepad / src / components. Build a Breadcrumbs component. Each level except the last is a link back to that level; the last one is the current page. Deep paths do not fit on a phone, so when there are too many levels, collapse the middle into an ellipsis that the user can expand."
Requirements:
- Data-driven: takes an array of
{ label, href }items and anonNavigate(index)callback (or event). - Renders a
navlandmark labelled "Breadcrumb" containing an ordered list; separators are decorative and hidden from screen readers. - Every item but the last is a link; the last is plain text marked
aria-current="page". - When there are more items than
maxItems(default 4), show the first item, an ellipsis button and the last two items. The button has an accessible name such as "Show 2 hidden levels"; activating it reveals every level and moves focus to the first revealed link. - Navigating to a new trail collapses it again. The trail wraps rather than overflowing on a 360 px screen.
What a strong answer should cover:
- Deriving the visible entries (with one ellipsis marker) from the items,
maxItemsand expanded state, rather than storing a second list. - Correct semantics:
navwitharia-label,ol(order matters),aria-current="page", separators witharia-hidden. - Why the ellipsis is a
button(it changes the view) while crumbs are links (they navigate), and why focus must move after expanding. - Resetting the expanded state when the trail changes (a
key, or an input setter). - Intercepting link clicks for client-side navigation while keeping real
hrefs for open-in-new-tab.
Clarifying questions expected:
- "How many items before and after the ellipsis, and is it configurable?"
- "Should the ellipsis expand in place or open a menu of the hidden levels?"
- "Do the crumbs come from the router, or are they passed in?"
Code / implementation expected: Yes. A component plus a small demo in which you can open subfolders and click crumbs to go back up.