NavigationMobileMenu
Searchastronomic.dev# MobileMenu
On small screens, for the main links in a panel that slides in. Navbar uses it for you.
Interactive: inline script.
## Usage
```astro
import MobileMenu from "@astronomic-dev/ui/components/MobileMenu.astro";
```
## Examples
### Links and an action
A plain bar with the menu at its end. Open it to see the panel. Navbar shows this menu on narrow screens.
```astro
---
import MobileMenu from "@astronomic-dev/ui/components/MobileMenu.astro";
const links = [
{ label: "Work", href: "#work", current: true },
{ label: "Services", href: "#services" },
{ label: "About", href: "#about" },
];
const actions = [{ label: "Start a project", href: "#start" }];
---
<div class="flex items-center justify-between gap-4 rounded-card border-ui border-solid border-border px-6 py-4">
<span class="font-medium">Astronomic</span>
<MobileMenu links={links} actions={actions} label="Astronomic" />
</div>
```
### On a band
tone="band" on a surface-band row with focus-on-band, as in the Navbar's bar: the open button takes the band's ghost colors and the band's focus ring. The panel stays the page surface, and closeLabel names its close button "Close navigation".
```astro
---
import MobileMenu from "@astronomic-dev/ui/components/MobileMenu.astro";
const links = [
{ label: "Work", href: "#work", current: true },
{ label: "Services", href: "#services" },
{ label: "About", href: "#about" },
];
const actions = [{ label: "Start a project", href: "#start" }];
---
<div class="surface-band focus-on-band flex items-center justify-between gap-4 rounded-card border-ui border-solid px-6 py-4">
<span class="font-medium">Astronomic</span>
<MobileMenu tone="band" links={links} actions={actions} label="Astronomic" closeLabel="Close navigation" />
</div>
```
### With words
openText="Menu": the open button is a bordered pill with the word in place of the icon, the secondary look on its tone. The word names the button.
```astro
---
import MobileMenu from "@astronomic-dev/ui/components/MobileMenu.astro";
const links = [
{ label: "Work", href: "#work", current: true },
{ label: "Services", href: "#services" },
{ label: "About", href: "#about" },
];
const actions = [{ label: "Start a project", href: "#start" }];
---
<div class="flex items-center justify-between gap-4 rounded-card border-ui border-solid border-border px-6 py-4">
<span class="font-medium">Astronomic</span>
<MobileMenu links={links} actions={actions} label="Astronomic" openText="Menu" />
</div>
```
### As a card
panel="card": the panel is a floating card that drops in just under the bar, on its side edges, with the card corners, in place of the tall drawer. data-menu-anchor on the row names the bar it lines up with; in a Navbar (menuPanel="card") the bar is the anchor.
```astro
---
import MobileMenu from "@astronomic-dev/ui/components/MobileMenu.astro";
const links = [
{ label: "Work", href: "#work", current: true },
{ label: "Services", href: "#services" },
{ label: "About", href: "#about" },
];
const actions = [{ label: "Start a project", href: "#start" }];
---
<div data-menu-anchor class="flex items-center justify-between gap-4 rounded-card border-ui border-solid border-border bg-surface px-6 py-4 shadow-card">
<span class="font-medium">Astronomic</span>
<MobileMenu links={links} actions={actions} label="Astronomic" panel="card" />
</div>
```
## Props
### MobileMenu
| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `links` | `{ label, href, current?, target?, index?, badge? }[]` | None | The menu links. current marks the page you are on. |
| `actions` | `{ label, href, variant? }[]` | `[]` | Buttons below the links. The last one is primary. |
| `label` | `string` | `"Menu"` | Accessible name of the menu's navigation. Also the title when `title` is not set. |
| `title` | `string` | None | Visible title of the panel. Default: `label`. |
| `openLabel` | `string` | `"Open menu"` | Accessible name of the icon-only open button. Not used with `openText`. |
| `openText` | `string` | None | Visible words on the open button, such as "Menu": a bordered pill (the secondary look on the same tone) with no icon, at least 44px tall on a touch screen. The words are its accessible name, so it takes no aria-label. Off by default. |
| `closeLabel` | `string` | `"Close menu"` | Accessible name of the panel's close button, e.g. for a translation. |
| `tone` | `"page" \| "band"` | `"page"` | The surface the open button sits on. `page`: the page's ghost button. `band`: an optional band (the Navbar's bar, a surface-band area), with the band's ghost colors; put focus-on-band on the band for its focus ring. The panel is always the page surface. |
| `panel` | `"drawer" \| "card"` | `"drawer"` | The panel's shape. `drawer`: a tall floating panel with the panel corners, set in from the screen edges, that slides in from the end of the screen. `card`: a floating card just under the bar and as wide as it, with the card corners, that drops in; it lines up with the closest data-menu-anchor around the open button, else its closest <nav> (the Navbar's bar), else it opens under the button 1rem in from the sides. A long menu scrolls inside the card. Navbar passes its menuPanel. |
| `class` | `string` | None | Classes for the open button. |
| `phone` | `{ number, label?, icon, callText? }` | None | A number to call: a "Call {number}" row with your icon at the end of the panel, a link at least 44px tall named by its words. callText sets the words ({number} is filled in by the number as written; keep it, as the words are the name). A number with fewer than 3 digits leaves no row. The Navbar passes its own. |
| `roll` | `boolean` | `false` | Each link label rolls up on hover and keyboard focus and the same words roll in from below (the text-roll utility). Read once. Still under reduced motion and the theme's calm setting. The Navbar passes its own roll. |
| Slot | Description |
| --- | --- |
| `default` | More content below the actions. |
The panel is a native <dialog>, opened by a small script with no framework. As it opens, it moves into the closest element with data-ui-portal, or into <body>, so it takes that part's tokens. Without JavaScript the open button is hidden: show the links another way, as Navbar does.
## Accessibility
| Key | Action |
| --- | --- |
| Enter or Space | Opens the menu from its button |
| Tab and Shift+Tab | Move through the panel; focus stays inside it |
| Escape | Closes the menu and returns focus to its button |
- The open button is named by openLabel (default "Open menu"), or by its visible openText, and has aria-expanded. The close button is named by closeLabel (default "Close menu").
- The panel is a modal dialog titled by title; while it is open, the page behind cannot be reached and does not scroll.
- Its links sit in a <nav> named by label, and the current link has aria-current="page".
- Picking a link or action closes the menu (opening one in a new tab leaves it open), and so does a click on the shade beside the panel, or a window widened until the open button hides.
- Under reduced motion the panel opens and closes with no slide.
MobileMenu
FreeOn small screens, for the main links in a panel that slides in. Navbar uses it for you.
- File
- MobileMenu.astro
- Group
- Navigation
- Kind
- Interactive: inline script
- Examples
- 4
Examples
Drag the orange handle to set the width. Frames get real breakpoints.
- Static
- Interactive
- Framed
Links and an action
A plain bar with the menu at its end. Open it to see the panel. Navbar shows this menu on narrow screens.
On a band
tone="band" on a surface-band row with focus-on-band, as in the Navbar's bar: the open button takes the band's ghost colors and the band's focus ring. The panel stays the page surface, and closeLabel names its close button "Close navigation".
With words
openText="Menu": the open button is a bordered pill with the word in place of the icon, the secondary look on its tone. The word names the button.
As a card
panel="card": the panel is a floating card that drops in just under the bar, on its side edges, with the card corners, in place of the tall drawer. data-menu-anchor on the row names the bar it lines up with; in a Navbar (menuPanel="card") the bar is the anchor.