Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Focus behavior of AutoSuggestBox #671

Closed
klondikedragon opened this issue Jan 10, 2023 · 2 comments
Closed

Focus behavior of AutoSuggestBox #671

klondikedragon opened this issue Jan 10, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@klondikedragon
Copy link
Contributor

Is your feature request related to a problem? Please describe.
I'm using the AutoSuggestBox with autofocus=true and trying to set the focus to the next control (or even a different control than the next control, e.g., like the final submit button in the form). The AutoSuggestBox is calling focusNode.unfocus(); at the end after both the widget.onSelected and widget.onChanged callbacks are called during the onSelected callback of the overlay built in the _insertOverlay() method call. This means that I can't control the focus from either of those callbacks since even if I set the focus in the onSelected or onChanged callback the later call to unfocus clears that out.

Describe the solution you'd like
I'd like to be able to control the focus myself from either of these callbacks, to set a custom focus behavior when a selection of an item has been made.

Additional context
I'm using the AutoSuggestBox as the main content in a modal ContentDialog (shown using showDialog) and I want to set focus to the Apply button when the user made a selection from the AutoSuggestBox overlay:
image

@klondikedragon
Copy link
Contributor Author

As an unrelated aside, it also would be nice to be able to specify the "default action" to perform if the enter key is pressed when a modal ContentDialog is shown. Maybe that would be an optional callback for the ContentDialog widget? Right now I'm wrapping the ContentDialog in a RawKeyboardListener, but that isn't quite right as it receives keyboard events anytime a key is pressed no matter what control has the focus (e.g., it receives all key presses for keys typed into a text box on a modal dialog), it should really only be capturing events like the enter key if another control doesn't have the focus right now. In any case, this is a common pattern for a desktop app to have some behavior when an enter key is pressed to attempt to perform a default action when a modal dialog is being shown. (Note that the ESC key already seems to work to close the dialog by asking the Navigator to pop)

@bdlukaa bdlukaa added the bug Something isn't working label Jan 13, 2023
@klondikedragon
Copy link
Contributor Author

@bdlukaa - Works perfectly, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants