Skip to content

Commit

Permalink
makes PopupMenuitem merge the semantics of its child (#62062)
Browse files Browse the repository at this point in the history
  • Loading branch information
chunhtai committed Jul 28, 2020
1 parent fe88a88 commit b2c7375
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 9 deletions.
20 changes: 11 additions & 9 deletions packages/flutter/lib/src/material/popup_menu.dart
Expand Up @@ -342,15 +342,17 @@ class PopupMenuItemState<T, W extends PopupMenuItem<T>> extends State<W> {
},
);

return Semantics(
enabled: widget.enabled,
button: true,
child: InkWell(
onTap: widget.enabled ? handleTap : null,
canRequestFocus: widget.enabled,
mouseCursor: effectiveMouseCursor,
child: item,
),
return MergeSemantics(
child: Semantics(
enabled: widget.enabled,
button: true,
child: InkWell(
onTap: widget.enabled ? handleTap : null,
canRequestFocus: widget.enabled,
mouseCursor: effectiveMouseCursor,
child: item,
),
)
);
}
}
Expand Down
84 changes: 84 additions & 0 deletions packages/flutter/test/material/popup_menu_test.dart
Expand Up @@ -836,6 +836,90 @@ void main() {
semantics.dispose();
});

testWidgets('PopupMenuItem merges the semantics of its descendants', (WidgetTester tester) async {
final SemanticsTester semantics = SemanticsTester(tester);
await tester.pumpWidget(
MaterialApp(
home: Material(
child: PopupMenuButton<int>(
itemBuilder: (BuildContext context) {
return <PopupMenuItem<int>>[
PopupMenuItem<int>(
value: 1,
child: Row(
children: <Widget>[
Semantics(
child: const Text('test1'),
),
Semantics(
child: const Text('test2'),
),
],
),
),
];
},
child: const SizedBox(
height: 100.0,
width: 100.0,
child: Text('XXX'),
),
),
),
),
);
await tester.tap(find.text('XXX'));
await tester.pumpAndSettle();

expect(semantics, hasSemantics(
TestSemantics.root(
children: <TestSemantics>[
TestSemantics(
textDirection: TextDirection.ltr,
children: <TestSemantics>[
TestSemantics(
children: <TestSemantics>[
TestSemantics(
flags: <SemanticsFlag>[
SemanticsFlag.scopesRoute,
SemanticsFlag.namesRoute,
],
label: 'Popup menu',
textDirection: TextDirection.ltr,
children: <TestSemantics>[
TestSemantics(
flags: <SemanticsFlag>[
SemanticsFlag.hasImplicitScrolling,
],
children: <TestSemantics>[
TestSemantics(
flags: <SemanticsFlag>[
SemanticsFlag.isButton,
SemanticsFlag.hasEnabledState,
SemanticsFlag.isEnabled,
SemanticsFlag.isFocusable,
],
actions: <SemanticsAction>[SemanticsAction.tap],
label: 'test1\ntest2',
textDirection: TextDirection.ltr,
),
],
),
],
),
],
),
TestSemantics(),
],
),
],
),
ignoreId: true, ignoreTransform: true, ignoreRect: true,
));

semantics.dispose();
});

testWidgets('disabled PopupMenuItem has correct semantics', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/45044.
final SemanticsTester semantics = SemanticsTester(tester);
Expand Down

0 comments on commit b2c7375

Please sign in to comment.