From e6f20eb95c27475b9673411b532aad783b06d6e2 Mon Sep 17 00:00:00 2001 From: Michael Goderbauer Date: Tue, 19 Dec 2017 11:33:23 -0800 Subject: [PATCH] IconButton is a button, semantically (#13674) * IconButton is a button, semantically * fix datepicker test --- .../flutter/lib/src/material/icon_button.dart | 31 ++++++++++--------- .../test/material/date_picker_test.dart | 2 ++ .../test/material/icon_button_test.dart | 30 ++++++++++++++++++ 3 files changed, 49 insertions(+), 14 deletions(-) diff --git a/packages/flutter/lib/src/material/icon_button.dart b/packages/flutter/lib/src/material/icon_button.dart index 65a08b6a9c9..ed7a69ffd4f 100644 --- a/packages/flutter/lib/src/material/icon_button.dart +++ b/packages/flutter/lib/src/material/icon_button.dart @@ -191,21 +191,24 @@ class IconButton extends StatelessWidget { else currentColor = disabledColor ?? Theme.of(context).disabledColor; - Widget result = new ConstrainedBox( - constraints: const BoxConstraints(minWidth: _kMinButtonSize, minHeight: _kMinButtonSize), - child: new Padding( - padding: padding, - child: new SizedBox( - height: iconSize, - width: iconSize, - child: new Align( - alignment: alignment, - child: IconTheme.merge( - data: new IconThemeData( - size: iconSize, - color: currentColor + Widget result = new Semantics( + button: true, + child: new ConstrainedBox( + constraints: const BoxConstraints(minWidth: _kMinButtonSize, minHeight: _kMinButtonSize), + child: new Padding( + padding: padding, + child: new SizedBox( + height: iconSize, + width: iconSize, + child: new Align( + alignment: alignment, + child: IconTheme.merge( + data: new IconThemeData( + size: iconSize, + color: currentColor + ), + child: icon ), - child: icon ), ), ), diff --git a/packages/flutter/test/material/date_picker_test.dart b/packages/flutter/test/material/date_picker_test.dart index c3a01d1b1bc..0d651fb9ca6 100644 --- a/packages/flutter/test/material/date_picker_test.dart +++ b/packages/flutter/test/material/date_picker_test.dart @@ -573,11 +573,13 @@ void _tests() { ], ), new TestSemantics( + flags: [SemanticsFlags.isButton], actions: [SemanticsAction.tap], label: r'Previous month December 2015', textDirection: TextDirection.ltr, ), new TestSemantics( + flags: [SemanticsFlags.isButton], actions: [SemanticsAction.tap], label: r'Next month February 2016', textDirection: TextDirection.ltr, diff --git a/packages/flutter/test/material/icon_button_test.dart b/packages/flutter/test/material/icon_button_test.dart index 78130948503..77c3c137518 100644 --- a/packages/flutter/test/material/icon_button_test.dart +++ b/packages/flutter/test/material/icon_button_test.dart @@ -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: [ + new TestSemantics.rootChild( + rect: new Rect.fromLTRB(0.0, 0.0, 48.0, 48.0), + actions: [SemanticsAction.tap], + flags: [SemanticsFlags.isButton], + label: 'link', + ) + ] + ), ignoreId: true, ignoreTransform: true)); + + semantics.dispose(); + }); } Widget wrap({ Widget child }) {