Repository navigation
A11y: Dropdowns have accessibility focus issues #40101
Description
Internal: b/140831334
If you have a dropdown (DropdownButton and DropdownMenuItems) below a Navigator in a MaterialApp, it breaks the screenreader focus behavior.
The problem is that when you activate the dropdown button, focus gets lost instead of going to the selected item in the popup. Sometimes it works properly the first time you open the popup, but not subsequent times. One strange thing I noticed (TalkBack only) was that if you navigate backwards three times in this state, it will successfully focus on the last element, but navigating forwards from this state never focuses on anything. Also, when you select an item and the popup closes, focus gets lost instead of returning to the button.
If the dropdown does not have a Navigator in its ancestry, it doesn't have this problem.
Our app does have a page where the dropdown focus works correctly even though it has a Navigator in the tree above the dropdown. This gives me hope that there may be some kind of workaround for the issue. However, I haven't been able to isolate what makes this different from the repro case below because the app's tree has many layers.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Navigator(
onGenerateRoute: (_) {
return MaterialPageRoute(
builder: (context) {
return Scaffold(
body: SafeArea(
child: DropdownButton(
value: "foo",
items: [
DropdownMenuItem(value: "foo", child: Text("Foo"),),
DropdownMenuItem(value: "bar", child: Text("Bar"),),
],
onChanged: (_) {},
),
),
);
},
);
},
),
);
}
}
Tested on both Android and iOS. Issue is present on both.
Activity
HansMuller commentedon Sep 10, 2019
CC @gspencergoog @jonahwilliams
gspencergoog commentedon Sep 10, 2019
I assume that when you're referring to focus navigation here, you are referring accessibility focus within TalkBack/VoiceOver, correct, and not to regular input focus?
andywolff commentedon Sep 10, 2019
Yes, accessibility focus
jkurtw commentedon Sep 10, 2019
Internal: b/140831334
[-]A11y: Dropdowns with a nested Navigator have focus issues[/-][+]A11y: Dropdowns with a nested Navigator have accessibility focus issues[/+]gspencergoog commentedon Sep 11, 2019
In investigating this, it appears to be a larger problem: the dropdown button doesn't actually support any kind of focus properly yet (it doesn't yet manage a focus node), so once the selection is made, the input focus returns to another control.
I'll work on getting that to work properly, and I think that will also fix the a11y issue.
Also, the work I have in #40166 should also help, since dropdowns use their own kind of Route.
7 remaining items
Norbert515 commentedon Sep 21, 2019
This issue also affects shortcuts on desktop. The new
Shortcutswidget relies on focus. When pressing aDropDownButtona new route is pushed and the focus to theShortcutsis lost, thus shortcuts do not work anymore.Looking forward to the PR
gspencergoog commentedon Sep 23, 2019
Yes, that's also a known issue, but that's not related to this one, since that is input focus, not accessibility focus. In that case, it's just because we're not done enabling all widgets with focus handling.
gspencergoog commentedon Sep 24, 2019
OK, I think I've got a fix for this problem. It will land in two parts: one an engine fix: flutter-team-archive/engine#12410, and another that changes the behavior for dropdown widgets and popups (and other widgets) to set the input focus bit in the semantics of components that have the "primary focus", and also add regular (non-a11y) focus support to dropdowns and popups.
Hixie commentedon Oct 8, 2019
update: being worked on; there was a performance regression that we're tracking down before we can commit this. Thank you for your patience.
Enables setting of semantics focused and focusable attributes within …
Re-land keyboard traversal PRs (#42278)
Enables setting of semantics focused and focusable attributes within …
Re-land keyboard traversal PRs (flutter#42278)
keobrien commentedon Nov 18, 2020
I'm still seeing these issues on iOS TalkBack & Android TalkBack for the DropdownButtonFormField widget.
Issues:
Code Example:
GabrieleSuzart commentedon Jul 26, 2021
Hi, I'm having the same problem! I put a DropdownButton on the screen and then tested it with VoiceOver screen reader, after selecting a new option the reader focus is directed to the top of the screen, reading everything again, which makes the experience really bad for blind people.
github-actions commentedon Aug 9, 2021
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.