I want to make a textEditor have default focus when a view appears in SwiftUI. My approach works for a textField but not a textEditor. I'm not sure why this is.
struct ContentView: View {
enum FocusedField {
case firstName, lastName
}
@State private var firstName = ""
@State private var lastName = ""
@FocusState private var focusedField: FocusedField?
var body: some View {
TextEditor(text: $firstName)
.focused($focusedField, equals: .firstName)
.onAppear {
focusedField = .firstName
}
}
}