I found a similar case here How can I remove Textfield focus when I press return or click outside Textfield? (SwiftUI, MacOS) - https://stackoverflow.com/questions/58987542/how-can-i-remove-textfield-focus-when-i-press-return-or-click-outside-textfield,with the following code
swift
func onCommit() - Void {
DispatchQueue.main.async {
NSApp.keyWindow?.makeFirstResponder(nil)
}
}
It's almost what I want, except that, after I press return key, I can see the selection flash and quickly disappear.
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: