Custom menu components for navigation or a Toolbar control?

Toolbar or custom menu components? How do you develop your navigation controls in your app? During Power Apps projects I see many different ways clients have implemented navigation controls, in this post some of the options. I’m of course concluding with the easiest and most manageable way of getting your menus sorted out.

Navigation in a Single screen

Quite often I find people who start with Power Apps development add a gallery to a screen and then make this gallery use a data structure like this:

Table(
{
ID: 1,
Label: "Home"
},
{
ID: 2,
Label: "Details"
}
)

Then with a simple button within the gallery the navigation structure will work as we can record which button has been pressed resulting in a variable being set to the ID of each menu option. Then we only need to make sure that each control on the screen looks at this variable to decide if it needs to be visible or not.

Gallery with menu items
Gallery with menu items

Now this option is extremely simple to implement and for single screen apps this works quite well. However before you know it your apps has hundreds of controls on a single screen, making it very hard to manage your app.

And of course we could set the colour of the buttons in such a way that we can recognize the current screen. by comparing ThisRecord..ID with the varCurrentSection value.

Navigation in a Multiple screen

Quite rightly you might now decide to add more screens to you app. For each section (menu option) we can add a separate new screen.

Now we would need to update the data structurer that feeds our gallery with menu items to include a screen

Table(
{
ID: 1,
Label: "Home",
Screen: 'Screen Home'
},
{
ID: 2,
Label: "Details",
Screen: 'Screen Details'
}
)

And then we update the Navigation button’s OnSelct as shown below.

Navigate to a screen
Navigate to a screen

And again we can set the colours of to help the user identify which screen they are on but this time we can compare the active screen with the navigation item’s screen

Identify the current screen
Identify the current screen

There are a few more things that you might want to sort out as we now need to replicate our data structures and gallery across all screens.

To avoid having multiple copies of the navigation structures, I would create a named formula. however you could of course do the same with the App.Onstart and set a variable.

Navigate to screens
Navigate to screens

This approach will help us not having multiple copies of the data structure however we still have multiple copies of the same gallery across all screens and especially if you have many custom settings within the galleries you might want to use a component that can be copied to every screen.

Tree view interface displaying components with a search bar, new component button, and a hierarchical list showing 'comNavigation', 'Gallery1_2', and 'ButtonCanvas1_3'.
Custom menu components for navigation or a Toolbar control? 1

The easiest option – Toolbar control

As part of the modern controls there is the Toolbar control.

Toolbar control and its Items property
Toolbar control and its Items property

Using the following data structure you can very quickly create a navigation structure. That looks similar to tools bars that we find in other Microsoft products.

Table(
{
ItemKey: "new",
ItemDisplayName: "New",
ItemIconName: "Add",
ItemAppearance: "Primary",
ItemIconStyle: "Regular",
ItemTooltip: "Add new item"
},
{
ItemKey: "edit",
ItemDisplayName: "Edit",
ItemIconName: "Edit",
ItemAppearance: "Subtle",
....

And this doesn’t just give us buttons but also icons. And if you prefer your buttons underneath eachother, all you need to do is set the alignment to Vertical and the Tools bar will do the rest for you.

Toolbar in Vertical mode
Toolbar in Vertical mode

To make the navigation control work, we just have to update the OnSelect property for the control. As we have to update this across all screens it might be useful to create a component instead, so that we don’t end up with multiple copies. Or alternatively a User Defined Function could also work. You might however find that buttons could change depending on data and then just a collection will also work.

The OnSelect to property to configure what each button does
The OnSelect to property to configure what each button does

This control makes it very easy to make your app look good. But it might be worth having a bit more of a detailed look at that data structure.

There are six properties that we can control the buttons with.

  • ItemKey
  • ItemDisplayName
  • ItemIconName
  • ItemAppearance
  • ItemIconStyle
  • ItemTooltip

The ItemKey just needs to be a unique key. Then the ItemDisplayName will be the text that appears next to your menu icons. ItemAppearance will control how your buttons will appear. You can pick Primary or Subtle as we’ve seen in the example earlier, but you can also use Outline, Secondary and Transparent.

Appearance options that are available
Appearance options that are available

Below you can see how each of the buttons will appear.

How each appearance setting will make your buttons look
How each appearance setting will make your buttons look

IconStyle is the next property to look at. For icon Style we have two options. Either Outline or Filled. The Filled options gives you a slightly bolder icon.

Two blue plus signs on a white background.
Custom menu components for navigation or a Toolbar control? 2

IconToolTip, you can add if you like your buttons to have the tooltips appear.

Tooltip shown in the Toolbar
Tooltip shown in the Toolbar

This then could make your navigation look like this

Example navigation in an app
Example navigation in an app

Discover more from SharePains

Subscribe to get the latest posts sent to your email.

Related Posts

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.