SwiftUI: How to make TextEditor field tabbable on MacOS

Viewed 17

I have a two text fields on my View. I want to be able to tab between them. It is currently writing the tab into the text content.

struct MyView: View
{
    @State var field1: String
    @State var field2: String

    var body: some View
    {
         TextEditor(text: $field1)
            .disableAutocorrection(false)
            .fixedSize(horizontal: false, vertical: true)
            .font(Font.system(size: 22, weight: .medium, design: .default))
            .multilineTextAlignment(.leading)
            .lineLimit(3)
            .overlay(RoundedRectangle(cornerRadius: 0).stroke(Color.gray, lineWidth: 1)

        TextEditor(text: $field2)
            .disableAutocorrection(false)
            .fixedSize(horizontal: false, vertical: true)
            .font(Font.system(size: 22, weight: .medium, design: .default))
            .multilineTextAlignment(.leading)
            .lineLimit(3)
            .overlay(RoundedRectangle(cornerRadius: 0).stroke(Color.gray, lineWidth: 1)
    }
}

How do I make the tab jump to the next field? Do I manually need to manage the focus or is there a simpler way?

0 Answers
Related