Hi @SuperGood1975,
I came across your thread today while searching for something else. The answer to your question is to use .contentShape()
to make the empty space tappable. Append the following to your TextField and it should work as expected:
.focused($focusedField, equals: .yourTextField)
.contentShape(RoundedRectangle(cornerRadius: 5))
.onTapGesture { focusedField = .yourTextField }
This solution also assumes you add the following to your code:
@FocusedState private var focusedField: Field?
private enum Field: Int, Hashable {
case yourTextField, yourOtherTextField
}
However, while the .contentShape
/ .onTapGesture
combo is perhaps easiest to code, you can instead wrap the field in a button and achieve the same result with better accessibility.
Button {
focusedField = .yourTextField
} label: {
TextField("", text: .constant(""))
...
.focused($focusedField, equals: .yourTextField)
}
Hope this helps.