From d5cd65b4ad12e190459b6728fbcdc23aa269d9d1 Mon Sep 17 00:00:00 2001 From: Bruno Leroux Date: Tue, 23 Sep 2025 10:00:24 +0200 Subject: [PATCH] [a11y-app] Fix Autocomplete semantics label (#175409) ## Description This PR updates the autocomplete page of the A11y assessments app. It creates a single semantics node for the text above the autocomplete and the autocomplete. ## Related Issue Fixes [[VPAT][A11y][a11y-app] fix a11y_assessment autocomplete to have proper labels](https://github.com/flutter/flutter/issues/173002) ## Tests Adds 1 test. --- .../lib/use_cases/auto_complete.dart | 35 ++++++++++--------- .../test/auto_complete_test.dart | 16 +++++++++ 2 files changed, 35 insertions(+), 16 deletions(-) diff --git a/dev/a11y_assessments/lib/use_cases/auto_complete.dart b/dev/a11y_assessments/lib/use_cases/auto_complete.dart index d6a7137291f..82eceabc911 100644 --- a/dev/a11y_assessments/lib/use_cases/auto_complete.dart +++ b/dev/a11y_assessments/lib/use_cases/auto_complete.dart @@ -55,22 +55,25 @@ class _MainWidgetState extends State<_MainWidget> { title: Semantics(headingLevel: 1, child: Text('$pageTitle Demo')), ), body: Center( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text('Type below to autocomplete the following possible results: $_kOptions.'), - Autocomplete( - optionsBuilder: (TextEditingValue textEditingValue) { - if (textEditingValue.text == '') { - return const Iterable.empty(); - } - return _kOptions.where((String option) { - return option.contains(textEditingValue.text.toLowerCase()); - }); - }, - fieldViewBuilder: _fieldViewBuilder, - ), - ], + child: Semantics( + container: true, + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text('Type below to autocomplete the following possible results: $_kOptions.'), + Autocomplete( + optionsBuilder: (TextEditingValue textEditingValue) { + if (textEditingValue.text == '') { + return const Iterable.empty(); + } + return _kOptions.where((String option) { + return option.contains(textEditingValue.text.toLowerCase()); + }); + }, + fieldViewBuilder: _fieldViewBuilder, + ), + ], + ), ), ), ); diff --git a/dev/a11y_assessments/test/auto_complete_test.dart b/dev/a11y_assessments/test/auto_complete_test.dart index 0bf795ee820..42e8d86d96c 100644 --- a/dev/a11y_assessments/test/auto_complete_test.dart +++ b/dev/a11y_assessments/test/auto_complete_test.dart @@ -4,6 +4,7 @@ import 'package:a11y_assessments/use_cases/auto_complete.dart'; import 'package:flutter/material.dart'; +import 'package:flutter/semantics.dart'; import 'package:flutter_test/flutter_test.dart'; import 'test_utils.dart'; @@ -28,4 +29,19 @@ void main() { await tester.pumpAndSettle(); expect(findHeadingLevelOnes, findsOne); }); + + testWidgets('The text is used as semantics label for the text field', ( + WidgetTester tester, + ) async { + await pumpsUseCase(tester, AutoCompleteUseCase()); + await tester.pumpAndSettle(); + + const List kOptions = ['apple', 'banana', 'lemon']; + const String label = 'Fruit'; + final String message = + 'Type below to autocomplete the following possible results: $kOptions.\n$label'; + + final SemanticsNode node = tester.semantics.find(find.bySemanticsLabel(message)); + expect(node.flagsCollection.isTextField, isTrue); + }); }