Unverified Commit 79400b24 authored by Rami's avatar Rami Committed by GitHub

[Material] Update some semantics for time picker controls (#66652)

parent 9d41ddcb
...@@ -560,6 +560,7 @@ class _DayPeriodControl extends StatelessWidget { ...@@ -560,6 +560,7 @@ class _DayPeriodControl extends StatelessWidget {
onTap: Feedback.wrapForTap(() => _setAm(context), context), onTap: Feedback.wrapForTap(() => _setAm(context), context),
child: Semantics( child: Semantics(
selected: amSelected, selected: amSelected,
button: true,
child: Center( child: Center(
child: Text( child: Text(
materialLocalizations.anteMeridiemAbbreviation, materialLocalizations.anteMeridiemAbbreviation,
...@@ -577,6 +578,7 @@ class _DayPeriodControl extends StatelessWidget { ...@@ -577,6 +578,7 @@ class _DayPeriodControl extends StatelessWidget {
onTap: Feedback.wrapForTap(() => _setPm(context), context), onTap: Feedback.wrapForTap(() => _setPm(context), context),
child: Semantics( child: Semantics(
selected: pmSelected, selected: pmSelected,
button: true,
child: Center( child: Center(
child: Text( child: Text(
materialLocalizations.postMeridiemAbbreviation, materialLocalizations.postMeridiemAbbreviation,
...@@ -1522,6 +1524,7 @@ class _HourTextField extends StatelessWidget { ...@@ -1522,6 +1524,7 @@ class _HourTextField extends StatelessWidget {
selectedTime: selectedTime, selectedTime: selectedTime,
isHour: true, isHour: true,
style: style, style: style,
semanticHintText: MaterialLocalizations.of(context).timePickerHourLabel,
validator: validator, validator: validator,
onSavedSubmitted: onSavedSubmitted, onSavedSubmitted: onSavedSubmitted,
onChanged: onChanged, onChanged: onChanged,
...@@ -1549,6 +1552,7 @@ class _MinuteTextField extends StatelessWidget { ...@@ -1549,6 +1552,7 @@ class _MinuteTextField extends StatelessWidget {
selectedTime: selectedTime, selectedTime: selectedTime,
isHour: false, isHour: false,
style: style, style: style,
semanticHintText: MaterialLocalizations.of(context).timePickerMinuteLabel,
validator: validator, validator: validator,
onSavedSubmitted: onSavedSubmitted, onSavedSubmitted: onSavedSubmitted,
); );
...@@ -1561,6 +1565,7 @@ class _HourMinuteTextField extends StatefulWidget { ...@@ -1561,6 +1565,7 @@ class _HourMinuteTextField extends StatefulWidget {
@required this.selectedTime, @required this.selectedTime,
@required this.isHour, @required this.isHour,
@required this.style, @required this.style,
@required this.semanticHintText,
@required this.validator, @required this.validator,
@required this.onSavedSubmitted, @required this.onSavedSubmitted,
this.onChanged, this.onChanged,
...@@ -1569,6 +1574,7 @@ class _HourMinuteTextField extends StatefulWidget { ...@@ -1569,6 +1574,7 @@ class _HourMinuteTextField extends StatefulWidget {
final TimeOfDay selectedTime; final TimeOfDay selectedTime;
final bool isHour; final bool isHour;
final TextStyle style; final TextStyle style;
final String semanticHintText;
final FormFieldValidator<String> validator; final FormFieldValidator<String> validator;
final ValueChanged<String> onSavedSubmitted; final ValueChanged<String> onSavedSubmitted;
final ValueChanged<String> onChanged; final ValueChanged<String> onChanged;
...@@ -1636,10 +1642,14 @@ class _HourMinuteTextFieldState extends State<_HourMinuteTextField> { ...@@ -1636,10 +1642,14 @@ class _HourMinuteTextFieldState extends State<_HourMinuteTextField> {
); );
} }
final Color unfocusedFillColor = timePickerTheme.hourMinuteColor ?? colorScheme.onSurface.withOpacity(0.12); final Color unfocusedFillColor = timePickerTheme.hourMinuteColor ?? colorScheme.onSurface.withOpacity(0.12);
// If screen reader is in use, make the hint text say hours/minutes.
// Otherwise, remove the hint text when focused because the centered cursor
// appears odd above the hint text.
final String hintText = MediaQuery.of(context).accessibleNavigation
? widget.semanticHintText
: (focusNode.hasFocus ? null : _formattedValue);
inputDecoration = inputDecoration.copyWith( inputDecoration = inputDecoration.copyWith(
// Remove the hint text when focused because the centered cursor appears hintText: hintText,
// odd above the hint text.
hintText: focusNode.hasFocus ? null : _formattedValue,
fillColor: focusNode.hasFocus ? Colors.transparent : inputDecorationTheme?.fillColor ?? unfocusedFillColor, fillColor: focusNode.hasFocus ? Colors.transparent : inputDecorationTheme?.fillColor ?? unfocusedFillColor,
); );
......
...@@ -324,8 +324,22 @@ void _tests() { ...@@ -324,8 +324,22 @@ void _tests() {
final SemanticsTester semantics = SemanticsTester(tester); final SemanticsTester semantics = SemanticsTester(tester);
await mediaQueryBoilerplate(tester, false); await mediaQueryBoilerplate(tester, false);
expect(semantics, includesNodeWith(label: 'AM', actions: <SemanticsAction>[SemanticsAction.tap])); expect(
expect(semantics, includesNodeWith(label: 'PM', actions: <SemanticsAction>[SemanticsAction.tap])); semantics,
includesNodeWith(
label: 'AM',
actions: <SemanticsAction>[SemanticsAction.tap],
flags: <SemanticsFlag>[SemanticsFlag.isButton, SemanticsFlag.isSelected, SemanticsFlag.isFocusable],
),
);
expect(
semantics,
includesNodeWith(
label: 'PM',
actions: <SemanticsAction>[SemanticsAction.tap],
flags: <SemanticsFlag>[SemanticsFlag.isButton, SemanticsFlag.isFocusable],
),
);
semantics.dispose(); semantics.dispose();
}); });
...@@ -349,6 +363,32 @@ void _tests() { ...@@ -349,6 +363,32 @@ void _tests() {
semantics.dispose(); semantics.dispose();
}); });
testWidgets('provides semantics information for text fields', (WidgetTester tester) async {
final SemanticsTester semantics = SemanticsTester(tester);
await mediaQueryBoilerplate(tester, true, entryMode: TimePickerEntryMode.input, accessibleNavigation: true);
expect(
semantics,
includesNodeWith(
label: 'Hour',
value: '07',
actions: <SemanticsAction>[SemanticsAction.tap],
flags: <SemanticsFlag>[SemanticsFlag.isTextField, SemanticsFlag.isMultiline],
),
);
expect(
semantics,
includesNodeWith(
label: 'Minute',
value: '00',
actions: <SemanticsAction>[SemanticsAction.tap],
flags: <SemanticsFlag>[SemanticsFlag.isTextField, SemanticsFlag.isMultiline],
),
);
semantics.dispose();
});
testWidgets('can increment and decrement hours', (WidgetTester tester) async { testWidgets('can increment and decrement hours', (WidgetTester tester) async {
final SemanticsTester semantics = SemanticsTester(tester); final SemanticsTester semantics = SemanticsTester(tester);
...@@ -840,6 +880,7 @@ Future<void> mediaQueryBoilerplate( ...@@ -840,6 +880,7 @@ Future<void> mediaQueryBoilerplate(
double textScaleFactor = 1.0, double textScaleFactor = 1.0,
TimePickerEntryMode entryMode = TimePickerEntryMode.dial, TimePickerEntryMode entryMode = TimePickerEntryMode.dial,
String helpText, String helpText,
bool accessibleNavigation = false,
}) async { }) async {
await tester.pumpWidget( await tester.pumpWidget(
Localizations( Localizations(
...@@ -852,6 +893,7 @@ Future<void> mediaQueryBoilerplate( ...@@ -852,6 +893,7 @@ Future<void> mediaQueryBoilerplate(
data: MediaQueryData( data: MediaQueryData(
alwaysUse24HourFormat: alwaysUse24HourFormat, alwaysUse24HourFormat: alwaysUse24HourFormat,
textScaleFactor: textScaleFactor, textScaleFactor: textScaleFactor,
accessibleNavigation: accessibleNavigation,
), ),
child: Material( child: Material(
child: Directionality( child: Directionality(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment