From 9d70c85f5a21b0c5d65f67640c3fe9d64eb5c9f6 Mon Sep 17 00:00:00 2001 From: Michael Goderbauer Date: Fri, 13 Sep 2019 09:23:27 -0700 Subject: [PATCH] a11y improvements for textfield (#40390) --- .../lib/src/material/input_decorator.dart | 17 ++-- .../lib/src/widgets/implicit_animations.dart | 12 +++ .../test/material/text_field_test.dart | 96 ++++++++++++++++++- 3 files changed, 118 insertions(+), 7 deletions(-) diff --git a/packages/flutter/lib/src/material/input_decorator.dart b/packages/flutter/lib/src/material/input_decorator.dart index d51f53ac26..35e8b0aaa8 100644 --- a/packages/flutter/lib/src/material/input_decorator.dart +++ b/packages/flutter/lib/src/material/input_decorator.dart @@ -827,14 +827,18 @@ class _RenderDecoration extends RenderBox { visitor(prefix); if (prefixIcon != null) visitor(prefixIcon); - if (isFocused && hint != null) { - // Bypass opacity to always read hint when focused. This prevents the - // label from changing when text is entered. - final RenderProxyBox typedHint = hint; - visitor(typedHint.child); - } else if (!isFocused && label != null) { + + if (label != null) { visitor(label); } + if (hint != null) { + if (isFocused) { + visitor(hint); + } else if (label == null) { + visitor(hint); + } + } + if (input != null) visitor(input); if (suffixIcon != null) @@ -2060,6 +2064,7 @@ class _InputDecoratorState extends State with TickerProviderStat opacity: (isEmpty && !_hasInlineLabel) ? 1.0 : 0.0, duration: _kTransitionDuration, curve: _kTransitionCurve, + alwaysIncludeSemantics: true, child: Text( decoration.hintText, style: hintStyle, diff --git a/packages/flutter/lib/src/widgets/implicit_animations.dart b/packages/flutter/lib/src/widgets/implicit_animations.dart index 40b8364b0a..98c4d076f9 100644 --- a/packages/flutter/lib/src/widgets/implicit_animations.dart +++ b/packages/flutter/lib/src/widgets/implicit_animations.dart @@ -1274,6 +1274,7 @@ class AnimatedOpacity extends ImplicitlyAnimatedWidget { @required this.opacity, Curve curve = Curves.linear, @required Duration duration, + this.alwaysIncludeSemantics = false, }) : assert(opacity != null && opacity >= 0.0 && opacity <= 1.0), super(key: key, curve: curve, duration: duration); @@ -1290,6 +1291,16 @@ class AnimatedOpacity extends ImplicitlyAnimatedWidget { /// The opacity must not be null. final double opacity; + /// Whether the semantic information of the children is always included. + /// + /// Defaults to false. + /// + /// When true, regardless of the opacity settings the child semantic + /// information is exposed as if the widget were fully visible. This is + /// useful in cases where labels may be hidden during animations that + /// would otherwise contribute relevant semantics. + final bool alwaysIncludeSemantics; + @override _AnimatedOpacityState createState() => _AnimatedOpacityState(); @@ -1319,6 +1330,7 @@ class _AnimatedOpacityState extends ImplicitlyAnimatedWidgetState[ TestSemantics.rootChild( - label: 'hint', + label: 'label\nhint', id: 1, textDirection: TextDirection.ltr, textSelection: const TextSelection(baseOffset: 0, extentOffset: 0),