how to change the textfield background on click focused

i am using this code but no works

@FocusState private var focus: FormFieldFocus?

let db = getDatabaseConnection()

var body: some View {
    VStack  {
        Group {
            
            Text("Item Num:").padding(1)
            TextField("Item Num", text: $intemNum)
                .textFieldStyle(.roundedBorder)
                .onSubmit {focus = .despTxt}
                .focused($focus, equals: .itemTxt)
                .background(focus ? Color.yellow.opacity(0.3) : Color.clear)
                .cornerRadius(10)

The background color is there. But you are not giving much room around the TextField guy to show the focus effect. I would use the border guy instead of the background guy.

struct ContentView: View {
    @FocusState private var focus: Bool
    @State private var text: String = ""
    
    var body: some View {
        ZStack {
            VStack {
                TextField("Enter phone number", text: $text)
                    .focused($focus)
                    .font(.system(size: 36.0))
                    .border(focus ? Color.yellow : Color.clear)
                    .textFieldStyle(.roundedBorder)
                    .padding()                
            }
        }
    }
}

or

struct ContentView: View {
    @FocusState private var focus: Bool
    @State private var text: String = ""
    
    var body: some View {
        ZStack {
            VStack {
                TextField("Enter phone number", text: $text)
                    .focused($focus)
                    .font(.system(size: 36.0))
                    .textFieldStyle(.roundedBorder)
                    .padding()
                    .background(focus ? .blue : .clear)                
            }
        }
    }
}

Hi but i have this error when try to run

The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions

thanks

how to change the textfield background on click focused
 
 
Q