Gil Birman
Gil Birman

Reputation: 35920

How do you fix reversed tab order in SwiftUI for MacOS? (key view loop)

I have a window with some text fields and when tabbing between fields, focus moves from the bottom to top instead of top-down. How do you make it tab top-to-bottom?

var body: some View {
  VStack {
    TextField("First name", text: $firstName)
      .modifier(InputModifier())
    TextField("Last namee", text: $lastName)
      .modifier(InputModifier())
    })
  }
}

Upvotes: 5

Views: 1044

Answers (1)

Gil Birman
Gil Birman

Reputation: 35920

Add .focusable() to the views and they will tab top-to-bottom.

var body: some View {
  VStack {
    TextField("First name", text: $firstName)
      .modifier(InputModifier())
      .focusable()
    TextField("Last name", text: $lastName)
      .modifier(InputModifier())
      .focusable()
    })
  }
}

Upvotes: 5

Related Questions