Skip to content

Web/Desktop Focus should follow the DOM Tree or Widget Tree as a default  #55033

@phackwer

Description

@phackwer

Use case

As a Web Developer, we are used to have the Focus of the tab key to follow one of those two things:

1 - DOM tree: deafault behaviour, when you hit TAB the focus moves to next input in the page in the order they were added to the DOM tree, so if I have a div with 3 fields acting as a column, and another div with 4 fields in another column, the tab order would be to go to the first 3 items in the same column and then go to the next 4 in the second column. In a table, it would go to the first cell and then the second cell in the same row and so on. This is a default standard on web inputs behaviour.

2 - Tab Index: this overwrites the standard behaviour on a page and make the tab to follow the order.

At the moment we don't have such approach on Flutter. We have a left to right top to down approach which causes the following problem: on a page that has 2 widgets with inputs as children and a drawer on the right with input itens, the focus goes to the first item of the first column/widget, then the first item of the second column/widget, and then to the first item on the drawer. If we consider that those widgets are groups of information (Personal Data - First Name, Last Name, Email - Organisation Data - Org Name, Org Address - and Page Settings - theme, wallpaper), this means that the navigation ends to be:

First Name -> Org Name -> Page Theme -> Last Name, -> Org Address -> Wallpaper -> Email -> Submit button

This is quite broken from a user perspective. Since those information were grouped as widgets the navigation should be

First Name -> Last Name -> Email -> Org Name -> Org Address -> Submit button (and if you keep hitting tab, Theme and Wallpaper).

Proposal

Tab key should go to the next sibling input into the children list of a widget, and if none is found, go to next widget till it reaches the end of the inputs, and goes back to the first in the page. The Widget structure is already a tree so the Tab Navigation should follow the context of the parent Widget of the Inputs till it reaches the end and needs to go to next widget or cycle back to the start of the tree.

So, full navigation logic for the presented case would be like:
Anybody request focus first? Go to that input (that way a search input on top that is not requesting the focus would not get it as the first input, only when it cycles back to the top of the tree)
PersonalInfoWidget
FirsNameInput gets focus
Tab key pressed in the context of PersonalInfoWidget. Is there a sibling? Goes to it.
LastNameInput gets focus
Tab key pressed in the context of PersonalInfoWidget. Is there a sibling? Goes to it.
EmailInput gets focus
Tab key pressed in the context of PersonalInfoWidget. Is there a sibling? No? Goes to next Widgett o
OrgInfoWidget
OrgNameInput gets focus

And so on until last there is no more siblings, so we go back to the top of the tree.

Metadata

Metadata

Assignees

No one assigned

    Labels

    a: desktopRunning on desktopc: new featureNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to Flutterf: focusFocus traversal, gaining or losing focusframeworkflutter/packages/flutter repository. See also f: labels.platform-webWeb applications specifically

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions