Is it possible to replicate Mac's standard Help menu Search item?

Old programmer but Apple programming noob. I wanted to make a menubar-only app that had a text entry field in its submenu, just like Help/Search.

It compiles with no errors and runs with no errors and no log output but the TextField between the "Buttons" dosn't appear.

//
//  Search_MenuApp.swift
//  Search Menu
//
//  Created by Andrew Dunbar on 30/8/2023.
//

import SwiftUI

@main
struct MenuTestApp: App {
    @State private var textfieldValue: String = "the text field value"

    var body: some Scene {
        WindowGroup {
            ContentView()
        }
        .commands {
            CommandMenu("My Menu") {
                Button("Submenu Item 1") { print("You pressed sub menu 1.") }
                    .keyboardShortcut("S")
                
                TextField("Sub Menu Item 2", text: $textfieldValue) { print("You committed the string.") }
                
                Button("Sub Menu Item 3") { print("You pressed sub menu 2.") }
            }
        }
    }
}
Screenshot_2023-08-30_at_4.15.49_pm.png
image.png
Was this page helpful?