I have a 3 TextFields in SwiftUI. one on top and two side by side underneath that.
VStack{
//TF1
TextField("Duty", text: $dutyNumber)
.textFieldStyle(RoundedBorderTextFieldStyle())
.padding([.leading], 50)
.multilineTextAlignment(.center)
.keyboardType(.numberPad)
HStack{
//TF2
TextField("Start time", text: $dutyStartTime)
.textFieldStyle(RoundedBorderTextFieldStyle())
.padding([.leading], 50)
.multilineTextAlignment(.center)
.keyboardType(.numberPad)
//TF3
TextField("Finish time", text: $dutyFinishTime)
.textFieldStyle(RoundedBorderTextFieldStyle())
.padding([.leading], 50)
.multilineTextAlignment(.center)
.keyboardType(.numberPad)
}
}.cornerRadius(4)
However only the last textfield TF3 is interactive. Cannot select the first two TF1 & TF2. Can Tab into them with keyboard but cannot select them with a finger tap. If I change the order from TF1, TF2, TF3 to TF1, TF3, TF2 for example. Then TF2 is now interactive but TF1 & TF3 are not. Is this a bug with adding multiple TextFields in SwiftUI or am I missing something obvious?
Adding answer to benefit others.
having played around with it the solution was to remove .cornerRadius and the all the TextFields work.
VStack{
//TF1
TextField("Duty", text: $dutyNumber)
.textFieldStyle(RoundedBorderTextFieldStyle())
.padding([.leading], 50)
.multilineTextAlignment(.center)
.keyboardType(.numberPad)
HStack{
//TF2
TextField("Start time", text: $dutyStartTime)
.textFieldStyle(RoundedBorderTextFieldStyle())
.padding([.leading], 50)
.multilineTextAlignment(.center)
.keyboardType(.numberPad)
//TF3
TextField("Finish time", text: $dutyFinishTime)
.textFieldStyle(RoundedBorderTextFieldStyle())
.padding([.leading], 50)
.multilineTextAlignment(.center)
.keyboardType(.numberPad)
}
}//.cornerRadius(4)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With