Remove semantics node generated by ExcludeFocus (#56568)

This commit is contained in:
Greg Spencer
2020-05-07 17:59:07 -07:00
committed by GitHub
parent 2d26cbb2bf
commit fd4d6d70d7
2 changed files with 15 additions and 0 deletions

View File

@@ -997,6 +997,7 @@ class ExcludeFocus extends StatelessWidget {
return Focus(
canRequestFocus: false,
skipTraversal: true,
includeSemantics: false,
descendantsAreFocusable: !excluding,
child: child,
);

View File

@@ -8,6 +8,8 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter/semantics.dart';
import 'semantics_tester.dart';
class TestFocus extends StatefulWidget {
const TestFocus({
Key key,
@@ -1585,6 +1587,12 @@ void main() {
expect(containerNode.hasFocus, isFalse);
expect(unfocusableNode.hasFocus, isFalse);
});
testWidgets("Focus doesn't introduce a Semantics node when includeSemantics is false", (WidgetTester tester) async {
final SemanticsTester semantics = SemanticsTester(tester);
await tester.pumpWidget(Focus(includeSemantics: false, child: Container()));
final TestSemantics expectedSemantics = TestSemantics.root();
expect(semantics, hasSemantics(expectedSemantics));
});
});
group(ExcludeFocus, () {
testWidgets("Descendants of ExcludeFocus aren't focusable.", (WidgetTester tester) async {
@@ -1625,5 +1633,11 @@ void main() {
expect(containerNode.hasFocus, isFalse);
expect(unfocusableNode.hasFocus, isFalse);
});
testWidgets("ExcludeFocus doesn't introduce a Semantics node", (WidgetTester tester) async {
final SemanticsTester semantics = SemanticsTester(tester);
await tester.pumpWidget(ExcludeFocus(child: Container()));
final TestSemantics expectedSemantics = TestSemantics.root();
expect(semantics, hasSemantics(expectedSemantics));
});
});
}