Skip to content

Support for keyboard navigation of Autocomplete options.#83696

Merged
darrenaustin merged 3 commits intoflutter:masterfrom
darrenaustin:autocomplete_keyboard
Jun 2, 2021
Merged

Support for keyboard navigation of Autocomplete options.#83696
darrenaustin merged 3 commits intoflutter:masterfrom
darrenaustin:autocomplete_keyboard

Conversation

@darrenaustin
Copy link
Contributor

@darrenaustin darrenaustin commented Jun 1, 2021

This PR adds support for keyboard navigation to the Autocomplete widget:

Autocomplete-keyboard

Specifically it adds new intents AutocompletePreviousOptionIntent and AutocompleteNextOptionIntent bound to the up arrow and down arrow keys respectively. These are handled by actions that move a highlight up and down the options list. If the field is submitted (usually with the enter key) it will replace the text with the highlighted option.

If the app provides a custom optionsViewBuilder to the Autocomplete widget, it will need to manage the display of the highlighted option manually. To do this they can get the index of the highlighted option with the inherited widget AutocompleteHighlightedOption. This can be accessed in the builder with:

final highlightedIndex = AutocompleteHighlightedOption.of(context);

Fixes: #82783

I have added several tests to verify the keyboard navigation is working correctly.

Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement].
  • I signed the [CLA].
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt.
  • All existing and new tests are passing.

@flutter-dashboard flutter-dashboard bot added f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. labels Jun 1, 2021
@google-cla google-cla bot added the cla: yes label Jun 1, 2021
Copy link
Contributor

@HansMuller HansMuller left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

Choose a reason for hiding this comment

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

That's attention to detail :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's an IDE that points out typos and an OCD engineer... 😄

Copy link
Contributor

@gspencergoog gspencergoog left a comment

Choose a reason for hiding this comment

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

32384589-a60f0e74-c078-11e7-9bc1-e5b5287aea9d

Just some really minor wording nits, and a question about needing to make things public.

@darrenaustin darrenaustin merged commit 3bb4a34 into flutter:master Jun 2, 2021
@darrenaustin darrenaustin deleted the autocomplete_keyboard branch June 2, 2021 20:59
@justinmc
Copy link
Contributor

@darrenaustin Thanks for doing this while I was out, looks great! This is exactly how I was hoping we could do this with Actions and Shortcuts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

[Proposal] Autocomplete Desktop Keyboard Support

4 participants