Skip to content

Commit 06e915f

Browse files
authored
added Semantics label to TextField with InputDecoration to let user k… (flutter#151996)
Semantics label to TextField with InputDecoration to let user know about existing suffix Before: https://screenshot.googleplex.com/3U9QyZ6Pqx2xeCf After: https://screenshot.googleplex.com/73BSKQJhssGCoZu fixes b/341998411 fixes b/342002217 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
1 parent 6fdcb0a commit 06e915f

File tree

2 files changed

+30
-16
lines changed

2 files changed

+30
-16
lines changed

dev/a11y_assessments/lib/use_cases/text_field.dart

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,31 @@ class _MainWidget extends StatelessWidget {
3030
),
3131
body: ListView(
3232
children: <Widget>[
33-
const TextField(
34-
key: Key('enabled text field'),
35-
maxLines: null,
36-
decoration: InputDecoration(
37-
labelText: 'Email',
38-
suffixText: '@gmail.com',
39-
hintText: 'Enter your email',
33+
Semantics(
34+
label: 'Input field with suffix @gmail.com',
35+
child: const TextField(
36+
key: Key('enabled text field'),
37+
maxLines: null,
38+
decoration: InputDecoration(
39+
labelText: 'Email',
40+
suffixText: '@gmail.com',
41+
hintText: 'Enter your email',
42+
),
4043
),
4144
),
42-
TextField(
43-
key: const Key('disabled text field'),
44-
maxLines: null,
45-
decoration: const InputDecoration(
46-
labelText: 'Email',
47-
suffixText: '@gmail.com',
48-
hintText: 'Enter your email',
45+
Semantics(
46+
label: 'Input field with suffix @gmail.com',
47+
child: TextField(
48+
key: const Key('disabled text field'),
49+
maxLines: null,
50+
decoration: const InputDecoration(
51+
labelText: 'Email',
52+
suffixText: '@gmail.com',
53+
hintText: 'Enter your email',
54+
),
55+
enabled: false,
56+
controller: TextEditingController(text: 'xyz'),
4957
),
50-
enabled: false,
51-
controller: TextEditingController(text: 'xyz'),
5258
),
5359
],
5460
),

dev/a11y_assessments/test/text_field_test.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,12 @@ void main() {
5454
expect(size.height, 280);
5555
}
5656
});
57+
58+
testWidgets('text field wrapper exists', (WidgetTester tester) async {
59+
await pumpsUseCase(tester, TextFieldUseCase());
60+
const String textFieldLabel = 'Input field with suffix @gmail.com';
61+
62+
final Finder semanticsWidgets = find.bySemanticsLabel(RegExp(textFieldLabel));
63+
expect(semanticsWidgets, findsExactly(2));
64+
});
5765
}

0 commit comments

Comments
 (0)