A menu that drills in, one level at a time
Drill menu is the menu a phone needs. Each level fills the space it is given, a row with children opens the next level in its place, and a back row names where it returns to. Rows are a thumb tall and every label starts on one line, so a deep site reads as a few short lists rather than one long one. The site header puts it in its drawer, which fills the screen on a phone.
A site menu
The top sections take the default rows, the size the site header’s and the app sidebar’s drawers use; variant="prominent" sets a section in the heading face on a taller row where a menu wants its top level louder. Shop drills into its categories and Kitchen into its pages, each level opening with an overview row to the page its row links. The rows on the way to the current page carry the current fill. defaultPath={[]} opens this one on its first level.
Opening where the reader is
Given no defaultPath, the stack opens on the deepest level that holds the current page, with that page marked: a reader on Pans reopens the menu on Kitchen, and the back rows lead out from there. A host that shows something only on the first level, as the site header’s drawer does with its footer, reads the same path to know where the stack will open.
Descriptions and links off-site
A description sets a second line under the label. An external link opens in a new tab and carries an outward arrow.
Settings that drill into choices
A row with onClick is an action, not a link. In a list of choices each one sets selected, the chosen one carries the chosen mark, and the row above shows it as its value.
Alternatives
- Use Side nav instead when the list sits in a sidebar beside the page and branches should open in place.
Props
Read from the same JSDoc that ships in the package's types. A required prop is marked with an asterisk.
| Prop | Type | Default | Description |
|---|---|---|---|
items* | DrillMenuEntry[] | The first level's rows and sections. A row with `items` drills into the next level. | |
currentHref | string | href of the current page: the exactly matching row gets `aria-current="page"` and the current treatment, and every row on the way to it the current treatment. | |
path | string[] | The ids of the rows drilled into, first level first: `[]` is the first level. Pair with `onPathChange`. | |
defaultPath | string[] | The path the menu opens on, when it owns its state. Left out, it opens
on the deepest level that holds the current page (`currentHref`, or a
row marked `current`), so a reader deep in a section reopens the menu
where they are; `[]` opens on the first level always. | |
onPathChange | ((path: string[]) => void) | Fires with the new path whenever a row drills in or the back row steps out, in both controlled and uncontrolled modes. | |
onNavigate | ((item: DrillMenuItem, event: MouseEvent<HTMLElement, MouseEvent>) => void) | Fires when a link row is followed, alongside native navigation, such as to close the drawer the menu sits in. | |
header | ReactNode | Content above the first level's rows, such as a search field. | |
rootLabel | string | 'Menu' | The back row's text on the second level, naming the first. |
backLabel | ((title: string) => string) | (title) => `Back to ${title}` | The back row's accessible name, given the title of the level it returns to. Defaults to "Back to <title>". |
overviewLabel | ((label: string) => string) | (label) => `${label} overview` | The overview row's text on a level whose row has an `href`, given that row's label. Defaults to "<label> overview". |
navLabel | string | 'Menu' | The accessible name of the `<nav>` landmark. |
linkComponent | LinkComponent | The component its links render with, such as Next.js's `Link`, so they
navigate through the app's router. Wins over a LinkProvider's; a plain
`<a>` when neither is set. | |
className | string | '' | Additional CSS classes. |
Keys
Its rows are links and buttons, and the browser owns Tab, Enter and Space. A step moves focus to the new level’s title, and back to the row it came from on the way out. Those keys belong to the platform, so no test of this library presses them.
// From the npm package
import { DrillMenu } from 'rift-ds/components/DrillMenu/DrillMenu';
// Or as source you own, via the shadcn CLI
npx shadcn@latest add https://rift-ds.com/r/drill-menu.json6.8 kB gzipped, with everything it imports. Peer dependencies are not counted.
For agents: the props, their allowed values and defaults, and the tested keys, as markdown or as a JSON schema.