Why is TextField height wrong when changing font size?

I have a simple SwiftUI view with a TextField in a macOS app. I change the font size of the TextField.


The TextField keeps its original height (prior to changing the font) until it has text, when it suddeny jumps to the correct size.


One work around is to have placeholder text (even an empty string with just a space in it), but then the cursor looks funny as the cursor keeps the original height.


The following code shows the problem:


struct ContentView: View {
  @State var input: String = ""
  var body: some View {
    TextField("Type Here", text: $input)
      .font(Font.custom("Arial", size: 35))
  }
}


I've tried changing the height (using frame modifier) of my view, but this shows the smaller TextField in the larger view, until the TextField receives input.


Is this a bug in TextField, or am I doing something wrong and either way, does anybody have a workaround/fix for it?

Hi Oreman,

Did you figure out the issue?
Hello,

I'm having the same issue with my macOS application I'm developing with SwiftUI as well. Did you find a workaround?

No, I have not.

I found a workaround by wrapping a NSTextField in a NSViewRepresentable but this broke again in Big Sur. So, I am again trying to resolve this.

ps. Sorry for only replying now. For some reason I missed the notification.
Why is TextField height wrong when changing font size?
 
 
Q