Hi,
Is is possible to determine when a TextField
has the focus or is the first responder using SwiftUI on macOS?
I've tried using the .onCommand()
view modifiers, but i've had no success. The following do not work:
TextField(...).onCommand(#selector(NSResponder.becomeFirstResponder), perform: {...})
// and
TextField(...).onCommand(#selector(NSResponder.resignFirstResponder), perform: {...})
I am aware I could use NSViewRepresentable, but I'm trying to avoid this.
Using the onEditingChanged parameter does not allow you to determine when the TextField is focused, it's only invoked on first edit.
The .focusable() view modifier does not work either.
Has anyone been able to achieve this?
Thanks, Adam.