title: SWIFTUI 2, SWIFTUI 3 - MACOS: Why TextField's onCommit closure is always trigger every time I switch to another tab
body: <ul>
  <li><strong>My code</strong>: I use <code>onCommit</code> closure to be able to perform an action by pressing the <em>Enter key</em> when the <code>TextField</code> is being focused.</li>
  </ul>
  <pre class="lang-swift prettyprint-override"><code>import SwiftUI
  
  struct ContentView: View {
    @State private var text = &quot;&quot;
  
    var body: some View {
      TabView {
        TextField(
          &quot;&quot;,
          text: $text,
          onCommit: { print(&quot;onCommit&quot;) } // I have a problem here
        )
          .tabItem {
            Text(&quot;Tab 1&quot;)
          }
  
        Text(&quot;Tab 2&quot;)
          .tabItem {
            Text(&quot;Tab 2&quot;)
          }
  
        Text(&quot;Tab 3&quot;)
          .tabItem {
            Text(&quot;Tab 3&quot;)
          }
      }
    }
  }
  </code></pre>
  <ul>
  <li><strong>My problem:</strong> The <code>onCommit</code> closure is also always triggered when I switch to another tab, making my App perform an unexpected action.</li>
  <li><strong>My questions:</strong>
  <ol>
  <li>This is the <em>bug</em> or the <em>feature</em>?</li>
  <li>Is there a way to avoid the <code>onCommit</code> trigger every time I switch to another tab?</li>
  </ol>
  </li>
  </ul>