Hint text semantics to be excluded in a11y read out if textfield in not empty and label text is provided (#115010)
* update hint semantics * Update input_date_picker_form_field_test.dart
This commit is contained in:
parent
2d77ac5846
commit
136b46ba91
@ -2136,7 +2136,7 @@ class _InputDecoratorState extends State<InputDecorator> with TickerProviderStat
|
|||||||
opacity: (isEmpty && !_hasInlineLabel) ? 1.0 : 0.0,
|
opacity: (isEmpty && !_hasInlineLabel) ? 1.0 : 0.0,
|
||||||
duration: _kTransitionDuration,
|
duration: _kTransitionDuration,
|
||||||
curve: _kTransitionCurve,
|
curve: _kTransitionCurve,
|
||||||
alwaysIncludeSemantics: true,
|
alwaysIncludeSemantics: isEmpty || (decoration.labelText == null && decoration.label == null),
|
||||||
child: Text(
|
child: Text(
|
||||||
hintText,
|
hintText,
|
||||||
style: hintStyle,
|
style: hintStyle,
|
||||||
|
@ -274,7 +274,7 @@ void main() {
|
|||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
expect(tester.getSemantics(find.byType(EditableText)), matchesSemantics(
|
expect(tester.getSemantics(find.byType(EditableText)), matchesSemantics(
|
||||||
label: 'Enter Date\nmm/dd/yyyy',
|
label: 'Enter Date',
|
||||||
isTextField: true,
|
isTextField: true,
|
||||||
isFocused: true,
|
isFocused: true,
|
||||||
value: '01/15/2016',
|
value: '01/15/2016',
|
||||||
|
@ -6586,7 +6586,39 @@ void main() {
|
|||||||
expect(tester.getBottomLeft(find.byKey(keyB)).dy, rowBottomY);
|
expect(tester.getBottomLeft(find.byKey(keyB)).dy, rowBottomY);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('TextField semantics include label when unfocused and label/hint when focused', (WidgetTester tester) async {
|
testWidgets('TextField semantics include label when unfocused and label/hint when focused if input is empty', (WidgetTester tester) async {
|
||||||
|
final SemanticsTester semantics = SemanticsTester(tester);
|
||||||
|
final TextEditingController controller = TextEditingController(text: '');
|
||||||
|
final Key key = UniqueKey();
|
||||||
|
|
||||||
|
await tester.pumpWidget(
|
||||||
|
overlay(
|
||||||
|
child: TextField(
|
||||||
|
key: key,
|
||||||
|
controller: controller,
|
||||||
|
decoration: const InputDecoration(
|
||||||
|
hintText: 'hint',
|
||||||
|
labelText: 'label',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
final SemanticsNode node = tester.getSemantics(find.byKey(key));
|
||||||
|
|
||||||
|
expect(node.label, 'label');
|
||||||
|
expect(node.value, '');
|
||||||
|
|
||||||
|
// Focus text field.
|
||||||
|
await tester.tap(find.byKey(key));
|
||||||
|
await tester.pump();
|
||||||
|
|
||||||
|
expect(node.label, 'label\nhint');
|
||||||
|
expect(node.value, '');
|
||||||
|
semantics.dispose();
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('TextField semantics alway include label and not hint when input value is not empty', (WidgetTester tester) async {
|
||||||
final SemanticsTester semantics = SemanticsTester(tester);
|
final SemanticsTester semantics = SemanticsTester(tester);
|
||||||
final TextEditingController controller = TextEditingController(text: 'value');
|
final TextEditingController controller = TextEditingController(text: 'value');
|
||||||
final Key key = UniqueKey();
|
final Key key = UniqueKey();
|
||||||
@ -6613,7 +6645,7 @@ void main() {
|
|||||||
await tester.tap(find.byKey(key));
|
await tester.tap(find.byKey(key));
|
||||||
await tester.pump();
|
await tester.pump();
|
||||||
|
|
||||||
expect(node.label, 'label\nhint');
|
expect(node.label, 'label');
|
||||||
expect(node.value, 'value');
|
expect(node.value, 'value');
|
||||||
semantics.dispose();
|
semantics.dispose();
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user