@@ -10,6 +10,7 @@ struct LoginForm<S: Session>: View {
1010 @State private var loginError : LoginError ?
1111 @State private var currentPage : LoginPage = . serverURL
1212 @State private var loading : Bool = false
13+ @FocusState private var focusedField : LoginField ?
1314
1415 let inspection = Inspection < Self > ( )
1516
@@ -19,9 +20,19 @@ struct LoginForm<S: Session>: View {
1920 case . serverURL:
2021 serverURLPage
2122 . transition ( . move( edge: . leading) )
23+ . onAppear {
24+ DispatchQueue . main. async {
25+ focusedField = . baseAccessURL
26+ }
27+ }
2228 case . sessionToken:
2329 sessionTokenPage
2430 . transition ( . move( edge: . trailing) )
31+ . onAppear {
32+ DispatchQueue . main. async {
33+ focusedField = . sessionToken
34+ }
35+ }
2536 }
2637 }
2738 . animation ( . easeInOut, value: currentPage)
@@ -79,6 +90,7 @@ struct LoginForm<S: Session>: View {
7990 text: $baseAccessURL,
8091 prompt: Text ( " https://coder.example.com " )
8192 ) . autocorrectionDisabled ( )
93+ . focused ( $focusedField, equals: . baseAccessURL)
8294 }
8395 } . formStyle ( . grouped) . scrollDisabled ( true ) . padding ( . horizontal)
8496 Divider ( )
@@ -110,6 +122,7 @@ struct LoginForm<S: Session>: View {
110122 SecureField ( " Session Token " , text: $sessionToken, prompt: Text ( " ●●●●●●●● " ) )
111123 . autocorrectionDisabled ( )
112124 . privacySensitive ( )
125+ . focused ( $focusedField, equals: . sessionToken)
113126 HStack ( spacing: 0 ) {
114127 Text ( " Generate a session token at " )
115128 . font ( . subheadline)
@@ -144,12 +157,14 @@ struct LoginForm<S: Session>: View {
144157 }
145158 withAnimation {
146159 currentPage = . sessionToken
160+ focusedField = . sessionToken
147161 }
148162 }
149163
150164 private func back( ) {
151165 withAnimation {
152166 currentPage = . serverURL
167+ focusedField = . baseAccessURL
153168 }
154169 }
155170}
0 commit comments