Make DropDown accessible (#11149)
This commit is contained in:
committed by
GitHub
parent
792c98751f
commit
7b90bdc908
@@ -550,6 +550,12 @@ class RenderIndexedStack extends RenderStack {
|
||||
alignment: alignment
|
||||
);
|
||||
|
||||
@override
|
||||
void visitChildrenForSemantics(RenderObjectVisitor visitor) {
|
||||
if (index != null)
|
||||
visitor(_childAtIndex());
|
||||
}
|
||||
|
||||
/// The index of the child to show, null if nothing is to be displayed.
|
||||
int get index => _index;
|
||||
int _index;
|
||||
|
||||
@@ -8,6 +8,8 @@ import 'dart:ui' show window;
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../widgets/semantics_tester.dart';
|
||||
|
||||
const List<String> menuItems = const <String>['one', 'two', 'three', 'four'];
|
||||
|
||||
final Type dropdownButtonType = new DropdownButton<String>(
|
||||
@@ -476,4 +478,16 @@ void main() {
|
||||
expect(find.byType(ListView, skipOffstage: false), findsNothing);
|
||||
});
|
||||
|
||||
|
||||
testWidgets('Semantics Tree contains only selected element', (WidgetTester tester) async {
|
||||
final SemanticsTester semantics = new SemanticsTester(tester);
|
||||
await tester.pumpWidget(buildFrame(items: menuItems));
|
||||
|
||||
expect(semantics, isNot(includesNodeWith(label: menuItems[0])));
|
||||
expect(semantics, includesNodeWith(label: menuItems[1]));
|
||||
expect(semantics, isNot(includesNodeWith(label: menuItems[2])));
|
||||
expect(semantics, isNot(includesNodeWith(label: menuItems[3])));
|
||||
|
||||
semantics.dispose();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -46,5 +46,35 @@ void main() {
|
||||
expect(green.size.height, equals(100.0));
|
||||
});
|
||||
|
||||
|
||||
group('RenderIndexedStack', () {
|
||||
test('visitChildrenForSemantics only visits displayed child', () {
|
||||
final RenderBox child1 = new RenderConstrainedBox(
|
||||
additionalConstraints: new BoxConstraints.tight(const Size(100.0, 100.0))
|
||||
);
|
||||
final RenderBox child2 = new RenderConstrainedBox(
|
||||
additionalConstraints: new BoxConstraints.tight(const Size(100.0, 100.0))
|
||||
);
|
||||
final RenderBox child3 = new RenderConstrainedBox(
|
||||
additionalConstraints: new BoxConstraints.tight(const Size(100.0, 100.0))
|
||||
);
|
||||
final RenderBox stack = new RenderIndexedStack(
|
||||
children: <RenderBox>[child1, child2, child3],
|
||||
index: 1,
|
||||
);
|
||||
|
||||
final List<RenderObject> vistedChildren = <RenderObject>[];
|
||||
final RenderObjectVisitor visitor = (RenderObject child) {
|
||||
vistedChildren.add(child);
|
||||
};
|
||||
|
||||
stack.visitChildrenForSemantics(visitor);
|
||||
|
||||
expect(vistedChildren, hasLength(1));
|
||||
expect(vistedChildren.first, child2);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
// More tests in ../widgets/stack_test.dart
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user