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
Disable arrow key focus navigation for text fields #42533
Disable arrow key focus navigation for text fields #42533
Conversation
Actually, this exposed an issue in the focus subsystem. I have a fix here: #42554. Once that lands, this PR will pass tests. |
Thanks for fixing this. The change looks good. My only concern with this approach is that it disables arrow-key navigation in text fields with no way to re-enable it. Ideally, arrow-key navigation in text fields would be off by default. But if a developer decides that they want this behavior in their app, they should be able to do so. |
9fc7942
to
9313755
Compare
Yes, I share that concern about not being able to re-define them, but I'm not sure how to implement that, other than adding an explicit flag to the text field to not re-map them. We already have too many flags, and this one seems oddly specific. The other way I could block it would be to bind the Being able to re-bind the arrow keys to something is probably not as useful as it seems, however, since the |
@mdebbar, can I take that as an "LGTM", or do you want someone else to review it? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the detailed reply.
LGTM!
Another way this could be implemented is to check the current focus inside the action when the action is invoked, and have the action do nothing if it's a text field. Then if someone really wanted to remap the keys, they could just replace the default action with another one that doesn't do that check. The down side of that approach is that it would only work for text fields that wrapped Would that be a better implementation, do you think? |
Yeah I think I prefer that approach. It also removes the duplication of code in material and cupertino text fields. |
Oh, crap, I didn't see your comment until after I submitted. I'll correct it tomorrow. |
I was happy to see that focus traversal was implemented by using the arrow keys and very sad that it was removed again. I am developing a desktop app for macOS and Windows. |
It's actually only removed for text fields. Other controls will continue to have arrow key focus traversal. We removed it for text fields because it is non-standard for both mobile and desktop, and so was surprising to users. If you open most desktop apps, focus a text field, and try and move it to another field with the arrow keys, it moves the cursor, and not the input focus. Spreadsheets are an exception, but most other apps (web browsers, preference panels, file dialogs, etc) don't allow arrow key traversal between fields. On macOS, even having arrow key traversal on non-list/non-grid primitives is non standard, although not as surprising. If you still want focus traversal for text fields in your app, you will be able to add it back in again once I implement the change I alluded to in #42533 (comment) (which I'm going to attempt today). Once that exists, you will be able to bind the arrow keys to a directional focus action that doesn't check for text fields, it just won't be the default. |
…different way. (#42790) In #42533, I disabled the up/down arrows for focus navigation in text fields, but we thought of a better way to do it, so this is that better way. This change reverts the other change, and instead it tests the context of the node in the action to see if it's an EditableText node. If so, then it doesn't do the navigation action.
This disables the arrow key focus navigation for text fields. This was non-standard behavior for text fields, although it remains useful for other kinds of controls. Fixes flutter#42259
…different way. (flutter#42790) In flutter#42533, I disabled the up/down arrows for focus navigation in text fields, but we thought of a better way to do it, so this is that better way. This change reverts the other change, and instead it tests the context of the node in the action to see if it's an EditableText node. If so, then it doesn't do the navigation action.
Description
This disables the arrow key focus navigation for text fields. This was non-standard behavior for text fields, although it remains useful for other kinds of controls.
Related Issues
Fixes #42259
Tests
Breaking Change