Make no-op buttons more accessible by showing a SnackBar when they're pressed (#16284)

* Remove explicit child nodes

* Remove semantics on no-op menu buttons

* Add a dummy action to the overflow bar
This commit is contained in:
David Shuckerow
2018-04-06 10:00:38 -07:00
committed by GitHub
parent cb3df70da6
commit c02ad6fd41

View File

@@ -181,7 +181,6 @@ class _BottomAppBarDemoState extends State<BottomAppBarDemo> {
new Semantics(
label: 'Set Bottom App Bar color to ${colorToName[color]}',
container: true,
explicitChildNodes: false,
child: new Row(children: <Widget> [
new Radio<Color>(
value: color,
@@ -311,34 +310,21 @@ class _DemoBottomAppBar extends StatelessWidget {
);
}
rowContents.addAll(<Widget> [
// Generally, an icon button does not need to be wrapped in a Semantics object.
// When the button has a null onPressed callback, it will be disabled by default.
//
// However, for the purposes of this demo, we don't want the button to appear disabled.
// To achieve this we use a no-op callback instead of a null callback. This allows
// the buttons to appear active, but perform no actions.
//
// To tell the accessibility service that the callback is a no-op, the Semantics widget
// wraps these buttons with `enabled: false`.
new Semantics(
label: 'Search',
container: true,
explicitChildNodes: false,
enabled: false,
child: new IconButton(
icon: const Icon(Icons.search),
onPressed: () {},
),
new IconButton(
icon: const Icon(Icons.search),
onPressed: () {
Scaffold.of(context).showSnackBar(
const SnackBar(content: const Text('This is a dummy search action.')),
);
},
),
new Semantics(
label: 'Show more',
container: true,
explicitChildNodes: false,
enabled: false,
child: new IconButton(
icon: const Icon(Icons.more_vert),
onPressed: () {},
),
new IconButton(
icon: const Icon(Icons.more_vert),
onPressed: () {
Scaffold.of(context).showSnackBar(
const SnackBar(content: const Text('This is a dummy menu action.')),
);
},
),
]);
return new Row(