Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why am I not getting the keyboard SwiftUI TextField

Tags:

swiftui

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?

like image 916
RyanTCB Avatar asked Jan 20 '26 06:01

RyanTCB


1 Answers

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)
like image 105
RyanTCB Avatar answered Jan 23 '26 10:01

RyanTCB



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!