title: Multiline TextField/TextEditor in SwiftUI for MacOS in forms
body: <p>I need a SwiftUI multiline text input control for MacOS satisfying the following requirements:</p>
  <ul>
  <li>allow cursor control like in a editor (i.e. pressing RETURN causes a new line)</li>
  <li>working label in a form</li>
  </ul>
  <p>I tried using TextField with lineLimit() modifier which looks exactly how I need it, i.e. the label is showing correctly (incl. alignment), but it only has a height of 1 line if it's empty and the RETURN key doesn't do what I want (i.e. new line):</p>
  <pre><code>struct ContentView: View {
      @State var field1 = &quot;&quot;
      @State var field2 = &quot;&quot;
      @State var notes = &quot;&quot;
  
      var body: some View {
          Form {
              TextField(&quot;Label&quot;, text: $field1)
              TextField(&quot;Long Label&quot;, text: $field2)
              TextField(&quot;Notes&quot;, text: $notes)
                  .lineLimit(10)
          }
          .padding()
          .frame(height: 150)
      }
  }
  </code></pre>
  <p><a href="https://i.stack.imgur.com/ekh13.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ekh13.png" alt="enter image description here" /></a></p>
  <p>Then I tried a TextEditor, but this lacks the ability to define a label. The placement of the label is what makes the Form element extremly usefull for MacOS as it allows the right alignment of the labels without any hacks. The missing border style is only a small issue that can probably solved using border styles:</p>
  <pre><code>struct ContentView: View {
      @State var field1 = &quot;&quot;
      @State var field2 = &quot;&quot;
      @State var notes = &quot;&quot;
  
      var body: some View {
          Form {
              TextField(&quot;Label&quot;, text: $field1)
              TextField(&quot;Long Label&quot;, text: $field2)
              TextEditor(text: $notes)
          }
          .padding()
          .frame(height: 150)
      }
  }
  </code></pre>
  <p><a href="https://i.stack.imgur.com/cqwzZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cqwzZ.png" alt="enter image description here" /></a></p>
  <p>I'm only interested in a clean solution that is future-proof. If there's none, a hack must be at least very flexible, i.e. all the labels must be correctly aligned. The solution from workingdog doesn't fit for me, because as soon as the label text changes, everything falls apart.</p>