From 35a7f43749b02f4683d5a47e0aff0c36f367fff7 Mon Sep 17 00:00:00 2001 From: Michael Goderbauer Date: Thu, 29 Mar 2018 15:37:05 -0400 Subject: [PATCH] Fix FAB Tooltip semantics label (#16072) --- .../src/material/floating_action_button.dart | 18 ++++++---- .../material/floating_action_button_test.dart | 34 +++++++++++++++++++ 2 files changed, 45 insertions(+), 7 deletions(-) diff --git a/packages/flutter/lib/src/material/floating_action_button.dart b/packages/flutter/lib/src/material/floating_action_button.dart index ee0a8401e8..103ec9c5b9 100644 --- a/packages/flutter/lib/src/material/floating_action_button.dart +++ b/packages/flutter/lib/src/material/floating_action_button.dart @@ -253,6 +253,17 @@ class _FloatingActionButtonState extends State { ); } + if (widget.tooltip != null) { + // The long-pressable area for the tooltip should always be as big as + // the tooltip even if there is no child. + result = new SizedBox.expand( + child: new Tooltip( + message: widget.tooltip, + child: result, + ), + ); + } + result = new RawMaterialButton( onPressed: widget.onPressed, onHighlightChanged: _handleHighlightChanged, @@ -267,13 +278,6 @@ class _FloatingActionButtonState extends State { child: result, ); - if (widget.tooltip != null) { - result = new Tooltip( - message: widget.tooltip, - child: result, - ); - } - if (widget.heroTag != null) { result = new Hero( tag: widget.heroTag, diff --git a/packages/flutter/test/material/floating_action_button_test.dart b/packages/flutter/test/material/floating_action_button_test.dart index 01e22d20bf..6602a9839c 100644 --- a/packages/flutter/test/material/floating_action_button_test.dart +++ b/packages/flutter/test/material/floating_action_button_test.dart @@ -253,6 +253,40 @@ void main() { semantics.dispose(); }); + testWidgets('Tooltip is used as semantics label', (WidgetTester tester) async { + final SemanticsTester semantics = new SemanticsTester(tester); + + await tester.pumpWidget( + new MaterialApp( + home: new Scaffold( + floatingActionButton: new FloatingActionButton( + onPressed: () { }, + tooltip: 'Add Photo', + child: const Icon(Icons.add_a_photo), + ), + ), + ), + ); + + expect(semantics, hasSemantics(new TestSemantics.root( + children: [ + new TestSemantics.rootChild( + label: 'Add Photo', + actions: [ + SemanticsAction.tap + ], + flags: [ + SemanticsFlag.isButton, + SemanticsFlag.hasEnabledState, + SemanticsFlag.isEnabled, + ], + ), + ], + ), ignoreTransform: true, ignoreId: true, ignoreRect: true)); + + semantics.dispose(); + }); + group('ComputeNotch', () { testWidgets('host and guest must intersect', (WidgetTester tester) async { final ComputeNotch computeNotch = await fetchComputeNotch(tester, const FloatingActionButton(onPressed: null));