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 {
else
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),
child: new Padding(
padding: padding,
......@@ -210,6 +212,7 @@ class IconButton extends StatelessWidget {
),
),
),
),
);
if (tooltip != null) {
......
......@@ -573,11 +573,13 @@ void _tests() {
],
),
new TestSemantics(
flags: <SemanticsFlags>[SemanticsFlags.isButton],
actions: <SemanticsAction>[SemanticsAction.tap],
label: r'Previous month December 2015',
textDirection: TextDirection.ltr,
),
new TestSemantics(
flags: <SemanticsFlags>[SemanticsFlags.isButton],
actions: <SemanticsAction>[SemanticsAction.tap],
label: r'Next month February 2016',
textDirection: TextDirection.ltr,
......
......@@ -2,10 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
import '../rendering/mock_canvas.dart';
import '../widgets/semantics_tester.dart';
class MockOnPressedFunction implements Function {
int called = 0;
......@@ -270,6 +274,32 @@ void main() {
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 }) {
......
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