Unverified Commit e6f20eb9 authored by Michael Goderbauer's avatar Michael Goderbauer Committed by GitHub

IconButton is a button, semantically (#13674)

* IconButton is a button, semantically

* fix datepicker test
parent 12f40557
...@@ -191,7 +191,9 @@ class IconButton extends StatelessWidget { ...@@ -191,7 +191,9 @@ class IconButton extends StatelessWidget {
else else
currentColor = disabledColor ?? Theme.of(context).disabledColor; currentColor = disabledColor ?? Theme.of(context).disabledColor;
Widget result = new ConstrainedBox( Widget result = new Semantics(
button: true,
child: new ConstrainedBox(
constraints: const BoxConstraints(minWidth: _kMinButtonSize, minHeight: _kMinButtonSize), constraints: const BoxConstraints(minWidth: _kMinButtonSize, minHeight: _kMinButtonSize),
child: new Padding( child: new Padding(
padding: padding, padding: padding,
...@@ -210,6 +212,7 @@ class IconButton extends StatelessWidget { ...@@ -210,6 +212,7 @@ class IconButton extends StatelessWidget {
), ),
), ),
), ),
),
); );
if (tooltip != null) { if (tooltip != null) {
......
...@@ -573,11 +573,13 @@ void _tests() { ...@@ -573,11 +573,13 @@ void _tests() {
], ],
), ),
new TestSemantics( new TestSemantics(
flags: <SemanticsFlags>[SemanticsFlags.isButton],
actions: <SemanticsAction>[SemanticsAction.tap], actions: <SemanticsAction>[SemanticsAction.tap],
label: r'Previous month December 2015', label: r'Previous month December 2015',
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
), ),
new TestSemantics( new TestSemantics(
flags: <SemanticsFlags>[SemanticsFlags.isButton],
actions: <SemanticsAction>[SemanticsAction.tap], actions: <SemanticsAction>[SemanticsAction.tap],
label: r'Next month February 2016', label: r'Next month February 2016',
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
......
...@@ -2,10 +2,14 @@ ...@@ -2,10 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'dart:ui';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import '../rendering/mock_canvas.dart'; import '../rendering/mock_canvas.dart';
import '../widgets/semantics_tester.dart';
class MockOnPressedFunction implements Function { class MockOnPressedFunction implements Function {
int called = 0; int called = 0;
...@@ -270,6 +274,32 @@ void main() { ...@@ -270,6 +274,32 @@ void main() {
await gesture.up(); await gesture.up();
}); });
testWidgets('IconButton Semantics', (WidgetTester tester) async {
final SemanticsTester semantics = new SemanticsTester(tester);
await tester.pumpWidget(
wrap(
child: new IconButton(
onPressed: mockOnPressedFunction,
icon: const Icon(Icons.link, semanticLabel: 'link'),
),
),
);
expect(semantics, hasSemantics(new TestSemantics.root(
children: <TestSemantics>[
new TestSemantics.rootChild(
rect: new Rect.fromLTRB(0.0, 0.0, 48.0, 48.0),
actions: <SemanticsAction>[SemanticsAction.tap],
flags: <SemanticsFlags>[SemanticsFlags.isButton],
label: 'link',
)
]
), ignoreId: true, ignoreTransform: true));
semantics.dispose();
});
} }
Widget wrap({ Widget child }) { Widget wrap({ Widget child }) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment