Skip to content

Commit

Permalink
Fixes TextField hinttext in a11y_assessment (#150007)
Browse files Browse the repository at this point in the history
b/317131589
  • Loading branch information
chunhtai authored Jun 10, 2024
1 parent c0b2645 commit bc0134d
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
2 changes: 2 additions & 0 deletions dev/a11y_assessments/lib/use_cases/text_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class _MainWidget extends StatelessWidget {
children: <Widget>[
const TextField(
key: Key('enabled text field'),
maxLines: null,
decoration: InputDecoration(
labelText: 'Email',
suffixText: '@gmail.com',
Expand All @@ -40,6 +41,7 @@ class _MainWidget extends StatelessWidget {
),
TextField(
key: const Key('disabled text field'),
maxLines: null,
decoration: const InputDecoration(
labelText: 'Email',
suffixText: '@gmail.com',
Expand Down
2 changes: 0 additions & 2 deletions dev/a11y_assessments/lib/use_cases/text_field_password.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,13 @@ class _MainWidget extends StatelessWidget {
key: Key('enabled password'),
decoration: InputDecoration(
labelText: 'Password',
hintText: 'Enter your password',
),
obscureText: true,
),
TextField(
key: Key('disabled password'),
decoration: InputDecoration(
labelText: 'Password',
hintText: 'Enter your password',
),
enabled: false,
obscureText: true,
Expand Down
20 changes: 20 additions & 0 deletions dev/a11y_assessments/test/text_field_password_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,24 @@ void main() {
expect(passwordField.enabled, isFalse);
}
});

testWidgets('text field passwords do not have hint text', (WidgetTester tester) async {
await pumpsUseCase(tester, TextFieldPasswordUseCase());
expect(find.byType(TextField), findsExactly(2));

// Test the enabled password
{
final Finder finder = find.byKey(const Key('enabled password'));
final TextField textField = tester.widget<TextField>(finder);
expect(textField.decoration?.hintText, isNull);

}

// Test the disabled password
{
final Finder finder = find.byKey(const Key('disabled password'));
final TextField textField = tester.widget<TextField>(finder);
expect(textField.decoration?.hintText, isNull);
}
});
}
24 changes: 24 additions & 0 deletions dev/a11y_assessments/test/text_field_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,28 @@ void main() {
expect(textField.enabled, isFalse);
}
});

testWidgets('font size increase does not ellipsize hint text', (WidgetTester tester) async {
await pumpsUseCase(tester, TextFieldUseCase());
await tester.pumpWidget(MaterialApp(
home: MediaQuery.withClampedTextScaling(
minScaleFactor: 3,
maxScaleFactor: 3,
child: Builder(
builder: (BuildContext context) {
return TextFieldUseCase().build(context);
},
),
),
));
// Test the enabled text field
{
final Finder finder = find.byKey(const Key('enabled text field'));
await tester.tap(finder);
await tester.pumpAndSettle();
final Size size = tester.getSize(finder);
// Should have a multi-line height.
expect(size.height, 280);
}
});
}

0 comments on commit bc0134d

Please sign in to comment.