SwiftUI Text - paste into empty field?

I'm new to SwiftUI and iOS and trying to investigate an issue in an existing codebase.

There is a Text view that has a contextMenu attached for copying and pasting from the clip board. The issue I'm having is if the text field is empty the context menu doesn't appear.

This would make sense for copying but obviously if a user has copied something they want to paste into the empty input field

Is this by design or am I missing something?

        Text("")
            .contextMenu {
            Button("do something") {

            }

        }

In the above example the contextMenu won't appear - is there a way to trigger the context menu, or would you implement paste differently here?

Many thanks

Yes, it is normal. If text is "", then area is empty, hence nowhere to tap into.

Just set a frame, like this:

      Text("")
           .frame(minWidth: 100, minHeight: 20)
            .background(Color.red)    // Just to better see it
            .contextMenu {
            Button("do something") {
            }
        }
SwiftUI Text - paste into empty field?
 
 
Q