swiftDialog
swiftDialog copied to clipboard
Feature Request: Grab the cursor focus for Text Fields and allow "Return" key to proceed
I would like for my SwiftDialog text field to have the cursor active as soon as the window draws. In other words, the blinky line for me to type would already be in the first --textfield when dialog is run.
I would also like to be able to type the "Return" key after entering text to activate the primary/OK button. Currently I'll need to tab to the button elements and then press return.
This has been a feedback from a couple folks here as well. It's not as intuitive currently.
So taking a look at this one and there are a couple of ways to attack it. The primary way I would like to do this us use the focusstate properties https://developer.apple.com/documentation/swiftui/focusstate
This is only available in macOS 12+ so introducing this will be a breaking change for using swiftDialog on macOS 11. I'm open to making this change eventually but as macOS 11 is in N-1 it's still supported in many environments.
Avoiding the breaking change involves one of two things:
- adding
if #available(macOS 12.0, *) {conditions. This makes for messy code as it would need to be repeated for each field type - extending textfield to support a focusable setting or creating a custom textfield. This would be some work. Examples I can find are all iOS based.
Unfortunately, setting which field has focus is something that was not implemented in SwiftUI 1 or 2. (2 being the version released with macOS 11 and the version I use)
Will park this for now and re-visit but it remains something I want to implement,
In the meantime, would setting focus on appear work as lifted from here https://developer.apple.com/forums/thread/681962 ?
It should probably be a separate issue, but what about the "return" key to submit from a field?
@dnikles The return key actually is already mapped to button 1. There's a bug in the markdown renderer that makes it steal focus on the first keystroke. With message text visible, hitting enter twice will quit the dialog.
so, this is an old issue - should be resolved in 2.3+ as the markdown renderer has been completely upgraded.
Can re-open if it's still an issue but as there's been no action on this one for over a year I'm going to close it as done.