How to remove SwiftUI TextField focus border?

How does one remove the focus border for a TextField in SwiftUI?


In Cocoa, setting the border to "None" in interface builder would remove the border.


I've tried using .border with a width of zero, but that does not work. The .border adds another border on top of the focus border.


Setting the style also does not do the trick.

Accepted Reply

Code Block swift
extension NSTextField {
open override var focusRingType: NSFocusRingType {
get { .none }
set { }
}
}


with PlainButtonStyle() you can start a blank slate customization

Replies

Code Block swift
extension NSTextField {
open override var focusRingType: NSFocusRingType {
get { .none }
set { }
}
}


with PlainButtonStyle() you can start a blank slate customization

If you are developing for macOS and don't want a button to show a square focus on it you can use the focusable modifier.

Button("a button") { 
// the action the button will do 
}
 .focusable(false)