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

966 Views Asked by At

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())
    })
  }
}
1

There are 1 best solutions below

4
Gil Birman On BEST ANSWER

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()
    })
  }
}