# Navigation drawer

Source: https://material.spynejs.com/components/drawer
Part of: Material shell gallery, Google's Material Design 3 for SpyneJS. Index: https://material.spynejs.com/llms.txt

Material's navigation drawer, as a modal: the app's destinations in a panel that opens over the page from a menu button, in a window narrower than 840px. From 840px the app bar shows the links itself and there is no drawer. A model does not ask for it; its links are the app's routes.

## In an app model

Nothing. The drawer’s links are the app’s routes, declared in `src/index.js`, and a link’s words are the route’s key. Add a route and the drawer has its link.

## How it behaves

The drawer has a channel of its own, `CHANNEL_MENU_DRAWER`, which holds whether it is open. It closes when a destination is followed, when the scrim is pressed, on Escape, and when the window passes one of Material’s breakpoints. The Material channel reports the reasons that are not the drawer’s own:

| Action of `CHANNEL_MATERIAL` | Direction | Payload | Means |
| --- | --- | --- | --- |
| `CHANNEL_MATERIAL_DISMISS_EVENT` | out | `{ reason }` | something asked for whatever is open to close. `reason` is `escape` or `route`. |
| `CHANNEL_MATERIAL_BREAKPOINT_EVENT` | out | `{ breakpoint }` | the window entered another of Material’s sizes |

- Opening it moves focus to its first link.
- Anything of your own that opens over the page can close for the same reasons by listening to `CHANNEL_MATERIAL_DISMISS_EVENT`.
- The template has no drawer that stands open beside the page. The gallery’s sidebar is the gallery’s own layout.

## Where it is in the template

| File | What it holds | By name |
| --- | --- | --- |
| `src/app/channels/channel-menu-drawer.js` | the drawer’s channel: whether it is open |  |
| `src/app/traits/channel/channel-menu-drawer-traits.js` | what opens and closes it | `channelMenuDrawer$OnCloseRequest`, `channelMenuDrawer$OnUiClick` |
| `src/app/components/ui-elements/ui-menu-drawer-view.js` | the drawer’s view |  |
| `src/scss/03-components/ui/menu-drawer.scss` | the styles |  |
| `src/index.js` | the routes its links come from |  |

The template is public: https://github.com/spynejs/application-shell-material. An app made from it has these same files.

What it rests on in `@spynejs/grammar`: `record:modal-open-close`, `op:state-machine-in-channel`, `op:choose-replay-semantics`, `record:responsive-behavior-on-media-query`.

## As the page shows it

The page’s own words, in its own order, read from the page as it is drawn in the light colour scheme. They were written for someone looking at the page: “above”, “below” and “marked” mean the drawn page. A thing the page draws is named here in its place (`Button:`, `Field:`, `Switch:`), and a box that reports what the reader does is as it starts, empty. What depends on the reader’s own window is left out.

The app’s destinations, in a panel at the side.

### In the template

The drawer is for a window narrower than 840px. There the app bar shows a menu button, and the button opens the drawer over the page, behind a scrim. Opening it moves focus to its first link. From 840px the app bar shows the links itself, and there is no drawer.

It closes when a destination is followed, when the scrim is pressed, on Escape, and when the window passes one of Material’s breakpoints.

### In the gallery

From 840px the gallery keeps the drawer open beside the page, as its sidebar, and hides the app bar’s links. That is the gallery’s own layout. To see the drawer as the template has it, narrow the window below 840px and press the menu button.

### In the app model

Nothing. The drawer’s links are the app’s routes, declared in index.js, and a link’s words are the route’s key.

Nothing new is proposed here.
