Skip to content
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

DataTable: expose focus-related attributes #116644

Open
jpnurmi opened this issue Dec 7, 2022 · 2 comments
Open

DataTable: expose focus-related attributes #116644

jpnurmi opened this issue Dec 7, 2022 · 2 comments
Labels
a: desktop Running on desktop c: new feature Nothing broken; request for a new capability c: proposal A detailed proposal for a change to Flutter f: focus Focus traversal, gaining or losing focus f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. P3 Issues that are less important to the Flutter project team-framework Owned by Framework team

Comments

@jpnurmi
Copy link
Member

jpnurmi commented Dec 7, 2022

Use case

The use case is to control tab focus traversal on the desktop. For example, the following kind of table might want to have 3 tab-focus traversal steps per row:

  • the row as a whole
  • the edit button
  • the delete button

image

DataTable creates hidden ink wells/responses under the hood. For these, none of the focus-related attributes are exposed. As a result, the focus chain for the above table becomes "Foo 2" -> "Bar 2" -> "(Baz)" -> "Edit" -> "Delete" where it's hard for the user to understand where the focus is traversing because there are "hidden" steps under the hood.

sample code
import 'package:flutter/material.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  FocusManager.instance.addListener(() => print(primaryFocus));

  runApp(
    MaterialApp(
      home: Scaffold(
        body: DataTable(
          showCheckboxColumn: false,
          columns: const [
            DataColumn(label: Text('Foo')),
            DataColumn(label: Text('Bar')),
            DataColumn(label: Text('Baz')),
          ],
          rows: [
            for (var i = 1; i <= 5; ++i)
              DataRow.byIndex(
                index: i,
                cells: [
                  DataCell(Text('Foo $i')),
                  DataCell(Text('Bar $i')),
                  DataCell(Row(
                    mainAxisSize: MainAxisSize.min,
                    children: [
                      IconButton(
                        icon: const Icon(Icons.edit),
                        focusNode: FocusNode(debugLabel: 'edit'),
                        onPressed: () {},
                      ),
                      IconButton(
                        icon: const Icon(Icons.delete),
                        focusNode: FocusNode(debugLabel: 'delete'),
                        onPressed: () {},
                      ),
                    ],
                  ))
                ],
                onSelectChanged: (value) => print('Selected $i $value'),
              ),
          ],
        ),
      ),
    ),
  );
}

Proposal

Expose autofocus, focusNode, and perhaps canRequestFocus for both DataRow and DataCell.

@danagbemava-nc danagbemava-nc added in triage Presently being triaged by the triage team c: new feature Nothing broken; request for a new capability framework flutter/packages/flutter repository. See also f: labels. f: material design flutter/packages/flutter/material repository. c: proposal A detailed proposal for a change to Flutter a: desktop Running on desktop f: focus Focus traversal, gaining or losing focus and removed in triage Presently being triaged by the triage team labels Dec 7, 2022
@gspencergoog gspencergoog added the P3 Issues that are less important to the Flutter project label Dec 8, 2022
@GP4cK
Copy link

GP4cK commented Jun 9, 2023

I have a similar use case when a DataTable has TextFields and the rows can be selected via the checkbox: in that case, the user needs to press tab twice to go to the next field because between every field, the row gets the focus.

The issue was already raised here: #74022 and the fix works well only if the table doesn't have checkboxes.

@flutter-triage-bot
Copy link

The triaged-desktop label is irrelevant if there is no team-desktop label or fyi-desktop label.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a: desktop Running on desktop c: new feature Nothing broken; request for a new capability c: proposal A detailed proposal for a change to Flutter f: focus Focus traversal, gaining or losing focus f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. P3 Issues that are less important to the Flutter project team-framework Owned by Framework team
Projects
None yet
Development

No branches or pull requests

6 participants