Giter Club home page Giter Club logo

Comments (5)

clragon avatar clragon commented on August 15, 2024 2

The current way that focus is implemented in the TypeAhead package as of its latest version does indeed seem to cause a lot of trouble. I think we will swap over to the same technique that Autocomplete is using to rectify all this and in the process simplify a lot of the code. Hopefully I'll find time for that soon.

This change might also come with some more freedom so we can fix some other complaints as well.
We might make it easier to customize even more of the field.

from flutter_typeahead.

wmadden avatar wmadden commented on August 15, 2024 1

Hi @clragon,

Sorry, I think I've used the wrong terminology - I'm not actually talking about selection, rather highlighting the option which will become selected when the user presses enter.

The list of options displayed in the popover has a currently-highlighted option which is implemented using keyboard focus. flutter_typeahead moves the highlight up or down the list when the user presses the arrow keys by calling node.focusInDirection().

My feature request, and my preferred outcome, is: retain keyboard focus in the textarea at all times and maintain the currently-highlighted item using internal state, e.g. an index.

from flutter_typeahead.

wmadden avatar wmadden commented on August 15, 2024 1

I could also imagine looking closer into how autocomplete achieves their way of up and down arrow key selection while not intercepting tab and trying to recreate this here.

It's implemented using Shortcuts. See the relevant code here: https://github.com/flutter/flutter/blob/3.19.5/packages/flutter/lib/src/widgets/autocomplete.dart#L577-L580

from flutter_typeahead.

clragon avatar clragon commented on August 15, 2024 1

Thank you for this information. I was not aware that Autocomplete manually implements this, very interesting.
I can imagine that we could follow suit on this and remove the complex focus code I have written - since it is unsightly.
I will look into this.

from flutter_typeahead.

clragon avatar clragon commented on August 15, 2024

Hi,

Thank you for your issue. The current approach is unfortunately rather janky, as we need to two-way sync state and focus and it becomes very tedious to enforce this without ending up in endless loops.

Looking at Autocomplete, it doesnt seem like it keeps track of a selected entry in any way, rather, it calls onSelected exactly when the user interacts with one of the the items. This is equivalent to TypeAheadField.onSelected.

"Selection" is therefore not related to the item which is currently focused. Focus is only meant to allow users to navigate selecting items via keyboard. I believe it is better if the package stays agnostic to how the onSelected callback is used and the user keeps track of what item was last selected themselves, if necessary. There are many use-cases where this would not be required.

The Autocomplete widget also allows users to navigate the list of suggestions via up and down keyboard keys.
It does however not intercept Tab, allowing users to move to the next field.

I could imagine adding an option to disable _SuggestionsBoxTraversalConnectorState's behaviour, therefore making selection via up and down keys no longer possible.
I could also imagine looking closer into how autocomplete achieves their way of up and down arrow key selection while not intercepting tab and trying to recreate this here.

What would be your preferred outcome?

from flutter_typeahead.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.