makes PopupMenuitem merge the semantics of its child (#62062)
This commit is contained in:
parent
fe88a88a5a
commit
b2c737547f
@ -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,
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user