Skip to content

Conversation

gspencergoog
Copy link
Contributor

Description

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 is configurable in the intent, so that if you want to have arrow keys enabled in your text field (e.g. in a spreadsheet), then you can do something similar to the following in the build function for the section of the app where you want it enabled:

final Map<LogicalKeySet, Intent> _enabledNavigationKeys = <LogicalKeySet, Intent>{
  LogicalKeySet(LogicalKeyboardKey.arrowLeft): DirectionalFocusIntent(TraversalDirection.left, ignoreTextFields: false),
  LogicalKeySet(LogicalKeyboardKey.arrowRight): DirectionalFocusIntent(TraversalDirection.right, ignoreTextFields: false),
  LogicalKeySet(LogicalKeyboardKey.arrowDown): DirectionalFocusIntent(TraversalDirection.down, ignoreTextFields: false),
  LogicalKeySet(LogicalKeyboardKey.arrowUp): DirectionalFocusIntent(TraversalDirection.up, ignoreTextFields: false),
};

Widget build(BuildContext context) {
  return Shortcuts(
    shortcuts: _enabledNavigationKeys,
    child: ...
  );
}

Related Issues

Tests

  • Kept existing tests to make sure that keys are ignored by default for text fields (no modifications needed)
  • Added a test to verify that you can override the behavior.

Breaking Change

  • No, this is not a breaking change.

@fluttergithubbot fluttergithubbot added f: cupertino flutter/packages/flutter/cupertino repository f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. labels Oct 15, 2019
@gspencergoog gspencergoog requested a review from mdebbar October 15, 2019 20:31
Copy link
Contributor

@mdebbar mdebbar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for improving this! LGTM.

@gspencergoog gspencergoog merged commit 3afdd08 into flutter:master Oct 17, 2019
@gspencergoog gspencergoog deleted the disable_text_up_down branch November 13, 2019 23:13
Inconnu08 pushed a commit to Inconnu08/flutter that referenced this pull request Nov 26, 2019
…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.
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
f: cupertino flutter/packages/flutter/cupertino repository f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants