Commit aeb12144 authored by Anthony's avatar Anthony Committed by Flutter GitHub Bot

Use a separately focusable semantics node for the chip delete icon (#48740)

parent b04dc46a
...@@ -1784,23 +1784,27 @@ class _RawChipState extends State<RawChip> with TickerProviderStateMixin<RawChip ...@@ -1784,23 +1784,27 @@ class _RawChipState extends State<RawChip> with TickerProviderStateMixin<RawChip
if (!hasDeleteButton) { if (!hasDeleteButton) {
return null; return null;
} }
return _wrapWithTooltip( return Semantics(
widget.deleteButtonTooltipMessage ?? MaterialLocalizations.of(context)?.deleteButtonTooltip, container: true,
widget.onDeleted, button: true,
GestureDetector( child: _wrapWithTooltip(
key: deleteIconKey, widget.deleteButtonTooltipMessage ?? MaterialLocalizations.of(context)?.deleteButtonTooltip,
behavior: HitTestBehavior.opaque, widget.onDeleted,
onTap: widget.isEnabled GestureDetector(
key: deleteIconKey,
behavior: HitTestBehavior.opaque,
onTap: widget.isEnabled
? () { ? () {
Feedback.forTap(context); Feedback.forTap(context);
widget.onDeleted(); widget.onDeleted();
} }
: null, : null,
child: IconTheme( child: IconTheme(
data: theme.iconTheme.copyWith( data: theme.iconTheme.copyWith(
color: widget.deleteIconColor ?? chipTheme.deleteIconColor, color: widget.deleteIconColor ?? chipTheme.deleteIconColor,
),
child: widget.deleteIcon,
), ),
child: widget.deleteIcon,
), ),
), ),
); );
......
...@@ -1630,6 +1630,50 @@ void main() { ...@@ -1630,6 +1630,50 @@ void main() {
semanticsTester.dispose(); semanticsTester.dispose();
}); });
testWidgets('delete', (WidgetTester tester) async {
final SemanticsTester semanticsTester = SemanticsTester(tester);
await tester.pumpWidget(MaterialApp(
home: Material(
child: RawChip(
label: const Text('test'),
onDeleted: () { },
),
),
));
expect(semanticsTester, hasSemantics(
TestSemantics.root(
children: <TestSemantics>[
TestSemantics(
textDirection: TextDirection.ltr,
children: <TestSemantics>[
TestSemantics(
flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
children: <TestSemantics>[
TestSemantics(
label: 'test',
textDirection: TextDirection.ltr,
children: <TestSemantics>[
TestSemantics(
label: 'Delete',
actions: <SemanticsAction>[SemanticsAction.tap],
textDirection: TextDirection.ltr,
flags: <SemanticsFlag>[
SemanticsFlag.isButton,
],
),
],
),
],
),
],
),
],
), ignoreTransform: true, ignoreId: true, ignoreRect: true));
semanticsTester.dispose();
});
testWidgets('with onPressed', (WidgetTester tester) async { testWidgets('with onPressed', (WidgetTester tester) async {
final SemanticsTester semanticsTester = SemanticsTester(tester); final SemanticsTester semanticsTester = SemanticsTester(tester);
......
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