I am using FocusState to edit a TextField and then dismiss the keyboard with a 'done' submit label on the keyboard.
However, the .focused() modifier doesn't seem to work with a TextEditor on the same screen and therefore there is no 'done' button to dismiss the keyboard after typing into the TextEditor.
How can I create a single done button that dismisses the keyboard for both the focused text field and the text editor?
That is, I am looking for something like this:
struct ContentView: View {
@FocusState var focusedInput: Input?
@State private var fieldText: String = "Text field"
@State private var editorText: String = "Text editor"
var body: some View {
VStack {
TextField("", text: $fieldText)
.focused($focusedInput, equals: .field)
.submitLabel(.done)
TextEditor(text: $editorText)
.focused($focusedInput, equals: .editor)
.submitLabel(.done)
}
}
}
enum Input {
case field
case editor
}