Unverified Commit 736b414f authored by Michael Goderbauer's avatar Michael Goderbauer Committed by GitHub

Add text field content to semantics (#13000)

* Add text field content to semantics

* remove controller dup
parent 62ed4f59
...@@ -169,6 +169,7 @@ class RenderEditable extends RenderBox { ...@@ -169,6 +169,7 @@ class RenderEditable extends RenderBox {
return; return;
_textPainter.text = value; _textPainter.text = value;
markNeedsTextLayout(); markNeedsTextLayout();
markNeedsSemanticsUpdate();
} }
/// How the text should be aligned horizontally. /// How the text should be aligned horizontally.
...@@ -203,6 +204,7 @@ class RenderEditable extends RenderBox { ...@@ -203,6 +204,7 @@ class RenderEditable extends RenderBox {
return; return;
_textPainter.textDirection = value; _textPainter.textDirection = value;
markNeedsTextLayout(); markNeedsTextLayout();
markNeedsSemanticsUpdate();
} }
/// The color to use when painting the cursor. /// The color to use when painting the cursor.
...@@ -322,6 +324,8 @@ class RenderEditable extends RenderBox { ...@@ -322,6 +324,8 @@ class RenderEditable extends RenderBox {
super.describeSemanticsConfiguration(config); super.describeSemanticsConfiguration(config);
config config
..value = text.toPlainText()
..textDirection = textDirection
..isFocused = hasFocus ..isFocused = hasFocus
..isTextField = true; ..isTextField = true;
} }
......
...@@ -284,6 +284,43 @@ void main() { ...@@ -284,6 +284,43 @@ void main() {
await tester.pump(); await tester.pump();
expect(semantics, includesNodeWith(flags: <SemanticsFlags>[SemanticsFlags.isTextField, SemanticsFlags.isFocused])); expect(semantics, includesNodeWith(flags: <SemanticsFlags>[SemanticsFlags.isTextField, SemanticsFlags.isFocused]));
});
testWidgets('EditableText includes text as value in semantics', (WidgetTester tester) async {
final SemanticsTester semantics = new SemanticsTester(tester);
const String value1 = 'EditableText content';
controller.text = value1;
await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new FocusScope(
node: focusScopeNode,
child: new EditableText(
controller: controller,
focusNode: focusNode,
style: textStyle,
cursorColor: cursorColor,
),
),
),
);
expect(semantics, includesNodeWith(
flags: <SemanticsFlags>[SemanticsFlags.isTextField],
value: value1,
));
const String value2 = 'Changed the EditableText content';
controller.text = value2;
await tester.idle();
await tester.pump();
expect(semantics, includesNodeWith(
flags: <SemanticsFlags>[SemanticsFlags.isTextField],
value: value2,
));
}); });
} }
...@@ -314,12 +314,14 @@ Matcher hasSemantics(TestSemantics semantics, { ...@@ -314,12 +314,14 @@ Matcher hasSemantics(TestSemantics semantics, {
class _IncludesNodeWith extends Matcher { class _IncludesNodeWith extends Matcher {
const _IncludesNodeWith({ const _IncludesNodeWith({
this.label, this.label,
this.value,
this.textDirection, this.textDirection,
this.actions, this.actions,
this.flags, this.flags,
}) : assert(label != null || actions != null || flags != null); }) : assert(label != null || value != null || actions != null || flags != null);
final String label; final String label;
final String value;
final TextDirection textDirection; final TextDirection textDirection;
final List<SemanticsAction> actions; final List<SemanticsAction> actions;
final List<SemanticsFlags> flags; final List<SemanticsFlags> flags;
...@@ -344,6 +346,8 @@ class _IncludesNodeWith extends Matcher { ...@@ -344,6 +346,8 @@ class _IncludesNodeWith extends Matcher {
bool checkNode(SemanticsNode node) { bool checkNode(SemanticsNode node) {
if (label != null && node.label != label) if (label != null && node.label != label)
return false; return false;
if (value != null && node.value != value)
return false;
if (textDirection != null && node.textDirection != textDirection) if (textDirection != null && node.textDirection != textDirection)
return false; return false;
if (actions != null) { if (actions != null) {
...@@ -375,6 +379,8 @@ class _IncludesNodeWith extends Matcher { ...@@ -375,6 +379,8 @@ class _IncludesNodeWith extends Matcher {
final List<String> strings = <String>[]; final List<String> strings = <String>[];
if (label != null) if (label != null)
strings.add('label "$label"'); strings.add('label "$label"');
if (value != null)
strings.add('value "$value"');
if (textDirection != null) if (textDirection != null)
strings.add(' (${describeEnum(textDirection)})'); strings.add(' (${describeEnum(textDirection)})');
if (actions != null) if (actions != null)
...@@ -391,12 +397,14 @@ class _IncludesNodeWith extends Matcher { ...@@ -391,12 +397,14 @@ class _IncludesNodeWith extends Matcher {
/// If null is provided for an argument, it will match against any value. /// If null is provided for an argument, it will match against any value.
Matcher includesNodeWith({ Matcher includesNodeWith({
String label, String label,
String value,
TextDirection textDirection, TextDirection textDirection,
List<SemanticsAction> actions, List<SemanticsAction> actions,
List<SemanticsFlags> flags, List<SemanticsFlags> flags,
}) { }) {
return new _IncludesNodeWith( return new _IncludesNodeWith(
label: label, label: label,
value: value,
textDirection: textDirection, textDirection: textDirection,
actions: actions, actions: actions,
flags: flags, flags: flags,
......
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