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 {
return;
_textPainter.text = value;
markNeedsTextLayout();
markNeedsSemanticsUpdate();
}
/// How the text should be aligned horizontally.
......@@ -203,6 +204,7 @@ class RenderEditable extends RenderBox {
return;
_textPainter.textDirection = value;
markNeedsTextLayout();
markNeedsSemanticsUpdate();
}
/// The color to use when painting the cursor.
......@@ -322,6 +324,8 @@ class RenderEditable extends RenderBox {
super.describeSemanticsConfiguration(config);
config
..value = text.toPlainText()
..textDirection = textDirection
..isFocused = hasFocus
..isTextField = true;
}
......
......@@ -284,6 +284,43 @@ void main() {
await tester.pump();
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, {
class _IncludesNodeWith extends Matcher {
const _IncludesNodeWith({
this.label,
this.value,
this.textDirection,
this.actions,
this.flags,
}) : assert(label != null || actions != null || flags != null);
}) : assert(label != null || value != null || actions != null || flags != null);
final String label;
final String value;
final TextDirection textDirection;
final List<SemanticsAction> actions;
final List<SemanticsFlags> flags;
......@@ -344,6 +346,8 @@ class _IncludesNodeWith extends Matcher {
bool checkNode(SemanticsNode node) {
if (label != null && node.label != label)
return false;
if (value != null && node.value != value)
return false;
if (textDirection != null && node.textDirection != textDirection)
return false;
if (actions != null) {
......@@ -375,6 +379,8 @@ class _IncludesNodeWith extends Matcher {
final List<String> strings = <String>[];
if (label != null)
strings.add('label "$label"');
if (value != null)
strings.add('value "$value"');
if (textDirection != null)
strings.add(' (${describeEnum(textDirection)})');
if (actions != null)
......@@ -391,12 +397,14 @@ class _IncludesNodeWith extends Matcher {
/// If null is provided for an argument, it will match against any value.
Matcher includesNodeWith({
String label,
String value,
TextDirection textDirection,
List<SemanticsAction> actions,
List<SemanticsFlags> flags,
}) {
return new _IncludesNodeWith(
label: label,
value: value,
textDirection: textDirection,
actions: actions,
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