Skip to content

Commit 76e2a71

Browse files
tltvrusselljtdyer
andauthored
docs: document MenuConfiguration (vaadin#3770)
* docs: document MenuConfiguration Renamed menu-registry to menu-configuration. Updated content to match with new simpler public API of MenuConfiguration. MenuRegistry was changed to internal API and only new public API is documented. RelatedTo: vaadin/flow#20063 * Updated by review comments * First pass at editing new document. * Second pass at editing. * A few more minor edits. --------- Co-authored-by: Russell J.T. Dyer <6652767+russelljtdyer@users.noreply.github.com>
1 parent e1b1d8e commit 76e2a71

File tree

3 files changed

+50
-103
lines changed

3 files changed

+50
-103
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
title: Menu Configuration
3+
description: Collecting menu annotated routes for menu generation.
4+
order: 115
5+
---
6+
7+
8+
= Menu Configuration
9+
10+
To generate a custom menu, the [classname]`MenuConfiguration` may be used for collecting defined server and client routes. Client routes are taken from the FileSystem routes definition. Server routes come from routes annotated with [annotationname]`@Menu`.
11+
12+
The collected menu items are filtered by access control from the [classname]`UI` (i.e., [classname]`NavigationAccessControl` and [classname]`ViewAccessChecker`). If the application has login and route defined `Roles`, the returned list is filtered on only available routes.
13+
14+
15+
== Creating Routes Menu
16+
17+
For a Flow application, any route annotated with [annotationname]`@Menu` is eligible for collection.
18+
19+
To get the available menu routes, call the static method `MenuConfiguration.getMenuEntries()`. This returns a [classname]`List<MenuEntry>`, first sorted in order found, then by path alphabetically and locale. It makes creating a simple menu by using [classname]`Anchor`, which can look like this:
20+
21+
[source,java]
22+
----
23+
List<MenuEntry> menuEntries = MenuConfiguration.getMenuEntries();
24+
menuEntries.forEach(entry -> layout.add(new Anchor(entry.path(), entry.title())));
25+
----
26+
27+
28+
== Data Returned for Menu Entries
29+
30+
The [classname]`MenuEntry` for a route contains information on the route. Using this data, it's possible to populate a menu, automatically.
31+
32+
The data contained is as follows:
33+
34+
`path`::
35+
Route path that should be used for navigation.
36+
37+
`title`::
38+
Title set in the [annotationname]`@Menu` annotation or the [annotationname]`@PageTitle`, if defined -- otherwise, the class simple name. For the client, title is populated from the FS router data.
39+
40+
`order`::
41+
Order number for the menu entry, if defined.
42+
43+
`icon`::
44+
Icon to use in the menu. This value can be entered inside a `<vaadin-icon>` element's `icon` attribute. It accepts icon group and a name like `vaadin:file`. Or the value can be given in `<vaadin-icon>` element's `src` attribute, which takes the path to the icon (e.g., `line-awesome/svg/lock-open-solid.svg`).
45+
46+
`menuClass`::
47+
Source class of the [annotationname]`@Menu` annotation. Always null for client routes.
48+
49+
[discussion-id]`647922A8-D542-4FA7-AAF6-44D40FC6A33B`

articles/flow/advanced/menu-registry.adoc

Lines changed: 0 additions & 102 deletions
This file was deleted.

articles/flow/integrations/hilla.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ public class MainView extends Div implements RouterLayout {
238238

239239
For more information on `RouterLayout`, see <<../routing/layout.adoc#,Router Layouts & Nested Router Targets>>.
240240

241-
Information on dynamic menu item generation, see <<../advanced/menu-registry#,Menu Registry>>.
241+
Information on dynamic menu item generation, see <<../advanced/menu-configuration#,Menu Configuration>>.
242242

243243
[NOTE]
244244
If the application is using access protection add [annotationname]`@AnonymousAllowed` on the `MainView` so that the request is not denied.

0 commit comments

Comments
 (0)