TextField inside a List does not respect certain styling when in edit mode

TextField inside a List doesn't respect certain styling as for instance a background colour when it gets focused (edited). The right colour is only visible and working as long as the textfield has no focus. I have noticed height of the textfield also changes on focus, so it must be using some other style forced by the List.

Setting the textfield's style to plain has no effect. Testing the same TextField inside a ScrollView or any other View, it's been working correctly, so I am assuming this is a SwiftUI bug? Is there no workaround for this?

Tested on MacOS 14, Xcode 15.4.

I've been also getting the following error coming from textfields although this has been already reported elsewhere. No idea if it's related somehow:

CLIENT ERROR: TUINSRemoteViewController does not override -viewServiceDidTerminateWithError: and thus cannot react to catastrophic errors beyond logging them

Give us the minimum amount of code that reproduces your issue, and we'll have a look. It's very difficult to diagnose things like this without seeing your code.

I hit the same problem as the OP (and I'm considering posting my code as open source in a bit). While editing text fields embedded in a List, the background turns white behind the text field (unexpected and unfortunate, when the background of my list and the text fields are a color other than white).

But to get OP to jump over the problem, add this:

extension NSTextView {
    open override var frame: CGRect {
        didSet {
            backgroundColor = .clear
            drawsBackground = true
        }
    }
}

The problem with adding this to your SwiftUI code is that it will set the backgroundColor to clear for ALL other AppKit NSTextViews. You can't set a private access modifier on this extension which has an open var. So this problem is still an open issue for me.

edit: I'm wondering if the OP has the same application setup as me -- where I am embedding a SwiftUI view via a NSHostingView inside a regular NSWindow alongside other (non-SwiftUI) NSViews. When it's a pure SwiftUI app, I do not see this problem when editing text fields.

TextField inside a List does not respect certain styling when in edit mode
 
 
Q