Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
enum CurrentField{
case field1
case field2
struct TextFieldFocus: View {
@State var field1 = ""
@State var field2 = ""
@FocusState var activeState: CurrentField?
var body: some View {
TextField("Email", text: $field1)
.focused($activeState, equals: .field1)
SecureField("Password", text: $field2)
.focused($activeState, equals: .field2)
Button("Goto Email") {
activeState = .field1
Button("Goto Password") {
activeState = .field2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment