Declaration
compose().menuOrder(order: SwiftUI.MenuOrder)nonisolated func menuOrder(_ order: MenuOrder) -> some ViewParameters
order*SwiftUI.MenuOrderThe menu item ordering strategy to apply.
Return value
A view that uses the specified menu ordering strategy.
Discussion
Use this modifier to override the default menu order. On supported
platforms, MenuOrder.priority order keeps the first items closer
to the user’s point of interaction, whereas MenuOrder.fixed order
always orders items from top to bottom.
On iOS, the MenuOrder.automatic order resolves to
MenuOrder.fixed for menus presented within scrollable content.
Pickers that use the PickerStyle.menu style also default to
MenuOrder.fixed order. In all other cases, menus default to
MenuOrder.priority order.
On macOS, tvOS and watchOS, the MenuOrder.automatic order always
resolves to MenuOrder.fixed order.
The following example creates a menu that presents its content in a fixed order from top to bottom:
Menu {
Button("Select", action: selectFolders)
Button("New Folder", action: createFolder)
Picker("Appearance", selection: $appearance) {
Label("Icons", systemImage: "square.grid.2x2").tag(Appearance.icons)
Label("List", systemImage: "list.bullet").tag(Appearance.list)
}
} label: {
Label("Settings", systemImage: "ellipsis.circle")
}
.menuOrder(.fixed)You can use this modifier on controls that present a menu.
For example, the code below creates a Picker using the
PickerStyle.menu style with a priority-based order:
Picker("Flavor", selection: $selectedFlavor) {
Text("Chocolate").tag(Flavor.chocolate)
Text("Vanilla").tag(Flavor.vanilla)
Text("Strawberry").tag(Flavor.strawberry)
}
.pickerStyle(.menu)
.menuOrder(.priority)You can also use this modifier on context menus. The example below creates a context menu that presents its content in a fixed order:
Text("Favorite Card Suit")
.padding()
.contextMenu {
Button("♥️ - Hearts", action: selectHearts)
Button("♣️ - Clubs", action: selectClubs)
Button("♠️ - Spades", action: selectSpades)
Button("♦️ - Diamonds", action: selectDiamonds)
}
.menuOrder(.fixed)The modifier has no effect when applied to a subsection or submenu of a menu.
See also
More in Presentation.
- alertPresents an alert when a given condition is true, using a localized string resource for the title.
- confirmationDialogPresents a confirmation dialog when a given condition is true, using a localized string resource for the title.
- contextMenuAdds an item-based context menu to a view.
- dialogIconConfigures the icon used by dialogs within this view.
- dialogSuppressionToggleEnables user suppression of dialogs and alerts presented within self, with a custom suppression message on macOS. Unused on other platforms.
- dismissalConfirmationDialogPresents a confirmation dialog upon an attempt to dismiss the window for this view.
- documentBrowserContextMenuAdds to a DocumentLaunchView actions that accept a list of selected files as their parameter.
- fileDialogBrowserOptionsOn macOS, configures the fileExporter, fileImporter, or fileMover to provide a refined URL search experience: include or exclude hidden files, allow searching by tag, etc.
- fileDialogConfirmationLabelOn macOS, configures the fileExporter, fileImporter, or fileMover with a custom confirmation button label.
- fileDialogCustomizationIDOn macOS, configures the fileExporter, fileImporter, or fileMover to persist and restore the file dialog configuration.
- fileDialogDefaultDirectoryConfigures the fileExporter, fileImporter, or fileMover to open with the specified default directory.
- fileDialogImportsUnresolvedAliasesOn macOS, configures the fileExporter, fileImporter, or fileMover behavior when a user chooses an alias.