Skip to content

Commit eea9041

Browse files
simonhampclaude
andcommitted
Document menu sections, rows, submenus, subtitles and checkmarks
Covers NavAction::section(), NavAction::row(), ->subtitle(), ->checked() and submenus from nested items(), with a Notes-style example, how each looks on iOS and Android, and the matching Blade props on <native:top-bar-action>. Pressable and list-item menus still draw a flat list, which the menus page now says. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent e543e7b commit eea9041

3 files changed

Lines changed: 192 additions & 14 deletions

File tree

‎resources/views/docs/mobile/4/edge-components/menus.md‎

Lines changed: 158 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ standalone element — you build a list of actions and attach it with an attribu
1313
- `items()` on a nav-bar action — see [Menus in the nav bar](#menus-in-the-nav-bar) below.
1414

1515
All of them share one item model: an array of `NavAction`, the same builder used
16-
[throughout layouts](../the-basics/layouts#builder-reference).
16+
[throughout layouts](../the-basics/layouts#builder-reference). Nav-bar menus can also be grouped into
17+
[sections, rows and submenus](#sections-rows-and-submenus).
1718

1819
## Building the items
1920

@@ -109,21 +110,166 @@ with dividers and destructive tinting, exactly like the inline menus above. This
109110
layouts — you can also attach it directly in a layout definition via `NavBar::make()->action(...)` in your
110111
layout's `navBar()`.
111112

112-
> **Note** Menus are only supported on nav-bar actions. Bottom-nav / tab-bar items and the inline
113-
> `<native:top-bar>` element render their actions as plain buttons — `items()` is ignored there.
113+
> **Note** Menus are only supported on nav-bar actions. Bottom-nav / tab-bar items and a
114+
> [`custom`](top-bar#custom-bars) `<native:top-bar>` render their actions as plain buttons, so `items()` is ignored
115+
> there. An inline `<native:top-bar>` without `custom` takes a menu as nested `<native:top-bar-action>` elements; see
116+
> [Menus in Blade](#menus-in-blade).
117+
118+
## Sections, rows and submenus
119+
120+
<x-docs.version-badge since="4.8" />
121+
122+
A nav-bar menu doesn't have to be a flat list. You can group items into titled sections, put a compact row of
123+
buttons across the top, nest a submenu, and give any item a subtitle or a checkmark. This menu is laid out like the
124+
one behind the ⋯ button in Apple's Notes app:
125+
126+
```php
127+
use Native\Mobile\Edge\Layouts\Builders\NavAction;
128+
use Native\Mobile\Edge\Layouts\Builders\NavBarOptions;
129+
130+
public function navigationOptions(): ?NavBarOptions
131+
{
132+
return NavBarOptions::make()->action(
133+
NavAction::make('more')
134+
->icon('ellipsis')
135+
->a11yLabel('More')
136+
->items([
137+
NavAction::row([
138+
NavAction::make('scan')
139+
->label('Scan')
140+
->icon(ios: 'doc.viewfinder', android: 'document_scanner')
141+
->press('scan'),
142+
NavAction::make('pin')
143+
->label($this->pinned ? 'Unpin' : 'Pin')
144+
->icon('pin')
145+
->press('togglePin'),
146+
NavAction::make('lock')->label('Lock')->icon('lock')->press('lock'),
147+
]),
148+
NavAction::section(items: [
149+
NavAction::make('find')->label('Find in Note')->icon('search')->press('find'),
150+
NavAction::make('move')
151+
->label('Move Note')
152+
->subtitle($this->folder)
153+
->icon('folder')
154+
->press('move'),
155+
]),
156+
NavAction::section('View', [
157+
NavAction::make('paper')
158+
->label('Lines & Grids')
159+
->icon(ios: 'squareshape.split.3x3', android: 'grid_on')
160+
->items([
161+
NavAction::make('paper_none')
162+
->label('None')
163+
->checked($this->paper === 'none')
164+
->press("setPaper('none')"),
165+
NavAction::make('paper_lines')
166+
->label('Lines')
167+
->checked($this->paper === 'lines')
168+
->press("setPaper('lines')"),
169+
NavAction::make('paper_grid')
170+
->label('Grid')
171+
->checked($this->paper === 'grid')
172+
->press("setPaper('grid')"),
173+
]),
174+
NavAction::make('attachments')
175+
->label('Show Attachments')
176+
->icon(ios: 'paperclip', android: 'attach_file')
177+
->checked($this->showAttachments)
178+
->press('toggleAttachments'),
179+
]),
180+
NavAction::section(items: [
181+
NavAction::make('delete')->label('Delete')->icon('trash')->press('delete')->destructive(),
182+
]),
183+
])
184+
);
185+
}
186+
```
187+
188+
Here's what each piece does:
189+
190+
- `NavAction::row([...])` puts its items side by side across the top of the menu, each with its icon above a short
191+
label. A row fits a few items, so keep the labels short.
192+
- `NavAction::section('View', [...])` groups its items under a heading. Use `NavAction::section(items: [...])` for a
193+
group with no heading. It still gets separated from the items around it.
194+
- An item with its own `items()` is a submenu. `Lines & Grids` above opens a submenu of paper styles.
195+
- `subtitle()` adds a second, smaller line under an item's label. Here it shows the folder the note is in.
196+
- `checked()` puts a checkmark on an item. Pass it a boolean from your screen's state, like the paper styles do, and
197+
the checkmark moves when the state changes.
198+
199+
Rows and sections are containers, not tappable items. Their ids are fixed placeholders (`row` and `section`, like
200+
`divider` for a divider), and they ignore `icon()`, `press()` and the other item methods. Give each item inside them
201+
its own unique id.
202+
203+
### How they look on each platform
204+
205+
On iOS, the menu is a native `UIMenu`. Sections are drawn inline, with the title as a small heading above the group
206+
and a separator line between groups. The row uses UIKit's medium element size: each item is a small button with its
207+
icon above its label, the same as the Scan, Pin and Lock buttons in Notes. A submenu shows a chevron and opens in
208+
place over the menu it came from. Checked items get the system checkmark, and destructive items are red.
209+
210+
On Android, the menu is a Material dropdown. A divider separates each section from the items around it, and the
211+
section's title shows as a small heading. The row is a line of buttons, each with an icon and a label. Tapping a
212+
submenu replaces the dropdown's items with the submenu's, with a back row at the top to return to the previous
213+
level. Checked items show a check mark at the end of the item, and a subtitle sits under the label in a smaller,
214+
quieter style.
215+
216+
### Menus in Blade
217+
218+
An inline [`<native:top-bar>`](top-bar) builds the same menu from nested `<native:top-bar-action>` elements. Add
219+
`section` (with an optional `label` for its heading) or `row` to an action to make it a container, and nest actions
220+
inside an item to make a submenu. `subtitle` and `checked` are attributes like any other:
221+
222+
@verbatim
223+
```blade
224+
<native:top-bar title="Note">
225+
<native:top-bar-action id="more" icon="ellipsis" a11y-label="More">
226+
<native:top-bar-action row>
227+
<native:top-bar-action id="scan" label="Scan" icon="document_scanner" ios-icon="doc.viewfinder" @tap="scan" />
228+
<native:top-bar-action id="pin" :label="$pinned ? 'Unpin' : 'Pin'" icon="pin" @tap="togglePin" />
229+
<native:top-bar-action id="lock" label="Lock" icon="lock" @tap="lock" />
230+
</native:top-bar-action>
231+
232+
<native:top-bar-action section label="View">
233+
<native:top-bar-action id="paper" label="Lines & Grids" icon="grid_on" ios-icon="squareshape.split.3x3">
234+
<native:top-bar-action id="paper_none" label="None" :checked="$paper === 'none'" @tap="setPaper('none')" />
235+
<native:top-bar-action id="paper_lines" label="Lines" :checked="$paper === 'lines'" @tap="setPaper('lines')" />
236+
<native:top-bar-action id="paper_grid" label="Grid" :checked="$paper === 'grid'" @tap="setPaper('grid')" />
237+
</native:top-bar-action>
238+
</native:top-bar-action>
239+
240+
<native:top-bar-action section>
241+
<native:top-bar-action id="delete" label="Delete" icon="trash" destructive @tap="delete" />
242+
</native:top-bar-action>
243+
</native:top-bar-action>
244+
</native:top-bar>
245+
```
246+
@endverbatim
247+
248+
<aside>
249+
250+
Sections, rows, submenus, subtitles and checkmarks are drawn in nav-bar menus. Menus attached with `:menu` or
251+
`:trailing-menu` still draw a flat list, so keep those to plain items and `NavAction::divider()`.
252+
253+
</aside>
114254

115255
## Item reference
116256

117257
The menu-relevant `NavAction` methods:
118258

119-
- `make(string $id)` — create an item with a unique id
120-
- `icon(?string $name = null, ios:, android:)` — a leading [icon](icon)
121-
- `label(string)` — the row text
122-
- `press(string $method)` — the component method to call when chosen
123-
- `url(string)` — navigate to a URL instead of calling a method
124-
- `items(array $items)` — sub-items that turn a nav-bar action into a pull-down menu (nav-bar actions only)
125-
- `a11yLabel(string)` — screen-reader label for icon-only actions
126-
- `destructive(bool = true)` — tint the item as destructive
127-
- `NavAction::divider()` — a separator row
259+
- `make(string $id)` - create an item with a unique id
260+
- `icon(?string $name = null, ios:, android:)` - a leading [icon](icon)
261+
- `label(string)` - the item's text
262+
- `subtitle(string)` - a second, smaller line under the label (nav-bar menus)
263+
- `press(string $method)` - the component method to call when chosen
264+
- `url(string)` - navigate to a URL instead of calling a method
265+
- `items(array $items)` - sub-items that turn a nav-bar action into a pull-down menu, or an item inside one into a
266+
submenu (nav-bar actions only)
267+
- `a11yLabel(string)` - screen-reader label for icon-only actions
268+
- `destructive(bool = true)` - tint the item as destructive
269+
- `checked(bool = true)` - show a checkmark on the item (nav-bar menus)
270+
- `NavAction::divider()` - a separator row
271+
- `NavAction::section(?string $title = null, array $items = [])` - an inline group of items under an optional heading
272+
(nav-bar menus)
273+
- `NavAction::row(array $items)` - a compact row of icon-over-label buttons (nav-bar menus)
128274

129275
See the [`NavAction` builder](../the-basics/layouts#builder-reference) for the full list.

‎resources/views/docs/mobile/4/edge-components/top-bar.md‎

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,17 @@ On iOS, if more than 5 actions are provided, they collapse into an overflow menu
9696

9797
### `<native:top-bar-action>` Props
9898

99-
- `id` - Unique identifier (required)
99+
- `id` - Unique identifier (required, except on a `section` or `row`)
100100
- `icon` - A named [icon](icon#icon-name-reference) — the cross-platform fallback (optional if a platform icon is given)
101101
- `ios-icon` / `android-icon` - Per-platform icon overrides: an enum case (`App\Icons\Ios`, `App\Icons\Android`, `App\Icons\AndroidOutlined`) or a raw symbol string. `ios` / `android` are accepted as shorthand (optional). See [Platform icons](#platform-icons)
102102
- `material-variant` - Material style hint for Android, e.g. `outlined` (optional). Set automatically when you use an `AndroidOutlined` enum case
103103
- `label` - Text label. Used for accessibility and displayed in overflow menus (optional but recommended)
104104
- `url` - A URL to navigate to when tapped (optional)
105105
- `destructive` - Render in the destructive (red) tint (optional, boolean)
106+
- `subtitle` - A second, smaller line under the label, for an action inside a menu (optional, string)
107+
- `checked` - Show a checkmark, for an action inside a menu (optional, boolean)
108+
- `section` - Group the actions nested inside this one, with `label` as the heading (optional, boolean). See [Menus](#menus)
109+
- `row` - Show the actions nested inside this one as a compact row of icon-over-label buttons (optional, boolean). See [Menus](#menus)
106110

107111
<aside>
108112

@@ -111,6 +115,31 @@ method on your screen instead of navigating, use `@tap="methodName"`.
111115

112116
</aside>
113117

118+
### Menus
119+
120+
Nest `<native:top-bar-action>` elements inside an action and it opens a pull-down menu of them instead of firing a
121+
press. Inside a menu, an action with its own nested actions is a submenu, and the `section` and `row` attributes
122+
group items the way [`NavAction::section()` and `NavAction::row()`](menus#sections-rows-and-submenus) do:
123+
124+
@verbatim
125+
```blade static
126+
<native:top-bar title="Inbox">
127+
<native:top-bar-action id="more" icon="ellipsis" a11y-label="More">
128+
<native:top-bar-action section label="Sort by">
129+
<native:top-bar-action id="sort_date" label="Date" :checked="$sort === 'date'" @tap="sortBy('date')" />
130+
<native:top-bar-action id="sort_sender" label="Sender" :checked="$sort === 'sender'" @tap="sortBy('sender')" />
131+
</native:top-bar-action>
132+
<native:top-bar-action section>
133+
<native:top-bar-action id="archive_all" label="Archive All" icon="archive" @tap="archiveAll" />
134+
</native:top-bar-action>
135+
</native:top-bar-action>
136+
</native:top-bar>
137+
```
138+
@endverbatim
139+
140+
See [Menus](menus#menus-in-blade) for a full example and how menus look on each platform. A `custom` bar draws its
141+
actions as plain buttons and ignores nested actions.
142+
114143
### Platform icons
115144

116145
`<native:top-bar-action>` resolves icons through the same contract as [`<native:icon>`](icon#typed-icon-enums): a

‎resources/views/docs/mobile/4/the-basics/layouts.md‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,10 @@ in a screen's Blade.
143143
- `press(string $method)` — screen method to call when tapped
144144
- `url(string)` — navigate to a URL when tapped; `event(string)` — dispatch a native event (advanced)
145145
- `destructive(bool = true)` — render in the destructive tint
146-
- `items(array $actions)` — nest `NavAction`s to render a pull-down menu; `NavAction::divider()` adds a separator
146+
- `items(array $actions)` — nest `NavAction`s to render a pull-down menu; `NavAction::divider()` adds a separator,
147+
`NavAction::section($title, $items)` groups items under a heading, `NavAction::row($items)` adds a compact row of
148+
buttons, and an item with its own `items()` opens a submenu. See [Sections, rows and submenus](../edge-components/menus#sections-rows-and-submenus)
149+
- `subtitle(string)` and `checked(bool = true)` add a second line and a checkmark to an item inside a menu
147150

148151
#### Custom title view / logo
149152

0 commit comments

Comments
 (0)