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

[Bug] Focus is not properly handled #607

Closed
tddang-linagora opened this issue Oct 21, 2024 · 5 comments
Closed

[Bug] Focus is not properly handled #607

tddang-linagora opened this issue Oct 21, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@tddang-linagora
Copy link

Steps to reproduce

  1. Run the code on Web
  2. Press "Tab" several times

Expected results

Either

  • Move the focus to each suggestions, and when the focus reaches the last suggestion, move to the next TextField or
  • Move the focus to the next TextField right away

Actual results

The Focus gets stuck somewhere in between and returns to the first TextField.

Package Version

5.2.0

Platform

Web

Code sample

Code sample
import 'package:flutter/material.dart';
import 'package:flutter_typeahead/flutter_typeahead.dart';

void main() => runApp(const MaterialApp(home: TabDemo()));

class TabDemo extends StatefulWidget {
  const TabDemo({super.key});

  @override
  State<TabDemo> createState() => _TabDemoState();
}

class _TabDemoState extends State<TabDemo> {
  final focusNode1 = FocusNode();
  final focusNode2 = FocusNode();
  final controller1 = TextEditingController();
  final controller2 = TextEditingController();

  @override
  void dispose() {
    focusNode1.dispose();
    focusNode2.dispose();
    controller1.dispose();
    controller2.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Tab Demo')),
      body: Padding(
        padding: const EdgeInsets.all(16.0),
        child: Column(
          children: [
            TypeAheadField<String>(
              itemBuilder: (context, value) => Text(value),
              onSelected: (value) => controller1.text = value,
              suggestionsCallback: (s) => ['abc', 'bc', 'c'],
              emptyBuilder: (context) => const SizedBox(),
              controller: controller1,
              focusNode: focusNode1,
              builder: (context, controller, focusNode) => TextField(
                controller: controller,
                focusNode: focusNode,
                autofocus: true,
              ),
            ),
            TypeAheadField<String>(
              itemBuilder: (context, value) => Text(value),
              onSelected: (value) => controller2.text = value,
              suggestionsCallback: (s) => ['abc', 'bc', 'c'],
              controller: controller2,
              focusNode: focusNode2,
              builder: (context, controller, focusNode) => TextField(
                controller: controller,
                focusNode: focusNode,
              ),
            ),
          ],
        ),
      ),
    );
  }
}

Logs

No response

Screenshots or Video

Screenshots / Video demonstration
Screen.Recording.2024-10-21.at.15.27.49.mov
@tddang-linagora tddang-linagora added the bug Something isn't working label Oct 21, 2024
@tddang-linagora
Copy link
Author

Also reproducible on master branch

@tobiasbentin
Copy link

tobiasbentin commented Oct 30, 2024

For me it is working when wrapping the TypeAheadFields with a Row instead of a Column...really weird. Any updates to that?

Edit:
After digging a bit I found following setup working for me:

FocusTraversalGroup(
     policy: WidgetOrderTraversalPolicy(),
     child: Column(
         children: [
             TypeAheadField....
             TypeAheadField....
         ],
       ...

Hope it works for you too @tddang-linagora

@tddang-linagora
Copy link
Author

@tobiasbentin Thank you, it works now.

Before closing this issue, it'll be best if either:

  • This additional FocusTraversalGroup is documented or
  • The problem is fixed so that focus traversal works without additional FocusTraversalGroup.

@dorklein
Copy link

The problem with WidgetOrderTraversalPolicy() is it breaks reading order.

FocusTraversalGroup(
     policy: WidgetOrderTraversalPolicy(),
     child: ...
)

When wrapping the TypeAhead widget in a LayoutBuilder, the traversal order gets very weird.
Because WidgetOrderTraversalPolicy() is A FocusTraversalPolicy that traverses the focus order in widget hierarchy order.

@clragon
Copy link
Collaborator

clragon commented Dec 12, 2024

Duplicate of #579

@clragon clragon marked this as a duplicate of #579 Dec 12, 2024
@clragon clragon closed this as not planned Won't fix, can't repro, duplicate, stale Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants