Unverified Commit 6a4808b4 authored by chunhtai's avatar chunhtai Committed by GitHub

Remove unused semantics tap action for readonly textfield and selectable text (#74066)

parent 1b310472
...@@ -1186,7 +1186,7 @@ class _CupertinoTextFieldState extends State<CupertinoTextField> with Restoratio ...@@ -1186,7 +1186,7 @@ class _CupertinoTextFieldState extends State<CupertinoTextField> with Restoratio
return Semantics( return Semantics(
enabled: enabled, enabled: enabled,
onTap: !enabled ? null : () { onTap: !enabled || widget.readOnly ? null : () {
if (!controller.selection.isValid) { if (!controller.selection.isValid) {
controller.selection = TextSelection.collapsed(offset: controller.text.length); controller.selection = TextSelection.collapsed(offset: controller.text.length);
} }
......
...@@ -652,11 +652,6 @@ class _SelectableTextState extends State<SelectableText> with AutomaticKeepAlive ...@@ -652,11 +652,6 @@ class _SelectableTextState extends State<SelectableText> with AutomaticKeepAlive
); );
return Semantics( return Semantics(
onTap: () {
if (!_controller.selection.isValid)
_controller.selection = TextSelection.collapsed(offset: _controller.text.length);
_effectiveFocusNode.requestFocus();
},
onLongPress: () { onLongPress: () {
_effectiveFocusNode.requestFocus(); _effectiveFocusNode.requestFocus();
}, },
......
...@@ -1282,7 +1282,7 @@ class _TextFieldState extends State<TextField> with RestorationMixin implements ...@@ -1282,7 +1282,7 @@ class _TextFieldState extends State<TextField> with RestorationMixin implements
return Semantics( return Semantics(
maxValueLength: semanticsMaxValueLength, maxValueLength: semanticsMaxValueLength,
currentValueLength: _currentLength, currentValueLength: _currentLength,
onTap: () { onTap: widget.readOnly ? null : () {
if (!_effectiveController.selection.isValid) if (!_effectiveController.selection.isValid)
_effectiveController.selection = TextSelection.collapsed(offset: _effectiveController.text.length); _effectiveController.selection = TextSelection.collapsed(offset: _effectiveController.text.length);
_requestKeyboard(); _requestKeyboard();
......
...@@ -13,6 +13,7 @@ import 'package:flutter/gestures.dart' show DragStartBehavior, PointerDeviceKind ...@@ -13,6 +13,7 @@ import 'package:flutter/gestures.dart' show DragStartBehavior, PointerDeviceKind
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import '../rendering/mock_canvas.dart'; import '../rendering/mock_canvas.dart';
import '../widgets/semantics_tester.dart';
class MockClipboard { class MockClipboard {
Object _clipboardData = <String, dynamic>{ Object _clipboardData = <String, dynamic>{
...@@ -1589,6 +1590,25 @@ void main() { ...@@ -1589,6 +1590,25 @@ void main() {
}, },
); );
testWidgets('Readonly text field does not have tap action', (WidgetTester tester) async {
final SemanticsTester semantics = SemanticsTester(tester);
await tester.pumpWidget(
const CupertinoApp(
home: Center(
child: CupertinoTextField(
maxLength: 10,
readOnly: true,
),
),
),
);
expect(semantics, isNot(includesNodeWith(actions: <SemanticsAction>[SemanticsAction.tap])));
semantics.dispose();
});
testWidgets( testWidgets(
'double tap selects word and first tap of double tap moves cursor', 'double tap selects word and first tap of double tap moves cursor',
(WidgetTester tester) async { (WidgetTester tester) async {
......
...@@ -3944,6 +3944,27 @@ void main() { ...@@ -3944,6 +3944,27 @@ void main() {
semantics.dispose(); semantics.dispose();
}); });
testWidgets('Readonly text field does not have tap action', (WidgetTester tester) async {
final SemanticsTester semantics = SemanticsTester(tester);
await tester.pumpWidget(
const MaterialApp(
home: Material(
child: Center(
child: TextField(
maxLength: 10,
readOnly: true,
),
),
),
),
);
expect(semantics, isNot(includesNodeWith(actions: <SemanticsAction>[SemanticsAction.tap])));
semantics.dispose();
});
testWidgets('Disabled text field hides helper and counter', (WidgetTester tester) async { testWidgets('Disabled text field hides helper and counter', (WidgetTester tester) async {
const String helperText = 'helper text'; const String helperText = 'helper text';
const String counterText = 'counter text'; const String counterText = 'counter text';
......
...@@ -1937,7 +1937,6 @@ void main() { ...@@ -1937,7 +1937,6 @@ void main() {
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
value: 'Guten Tag', value: 'Guten Tag',
actions: <SemanticsAction>[ actions: <SemanticsAction>[
SemanticsAction.tap,
SemanticsAction.longPress, SemanticsAction.longPress,
], ],
flags: <SemanticsFlag>[ flags: <SemanticsFlag>[
...@@ -1963,7 +1962,6 @@ void main() { ...@@ -1963,7 +1962,6 @@ void main() {
value: 'Guten Tag', value: 'Guten Tag',
textSelection: const TextSelection.collapsed(offset: 9), textSelection: const TextSelection.collapsed(offset: 9),
actions: <SemanticsAction>[ actions: <SemanticsAction>[
SemanticsAction.tap,
SemanticsAction.longPress, SemanticsAction.longPress,
SemanticsAction.moveCursorBackwardByCharacter, SemanticsAction.moveCursorBackwardByCharacter,
SemanticsAction.moveCursorBackwardByWord, SemanticsAction.moveCursorBackwardByWord,
...@@ -1990,7 +1988,6 @@ void main() { ...@@ -1990,7 +1988,6 @@ void main() {
textSelection: const TextSelection.collapsed(offset: 4), textSelection: const TextSelection.collapsed(offset: 4),
value: 'Guten Tag', value: 'Guten Tag',
actions: <SemanticsAction>[ actions: <SemanticsAction>[
SemanticsAction.tap,
SemanticsAction.longPress, SemanticsAction.longPress,
SemanticsAction.moveCursorBackwardByCharacter, SemanticsAction.moveCursorBackwardByCharacter,
SemanticsAction.moveCursorForwardByCharacter, SemanticsAction.moveCursorForwardByCharacter,
...@@ -2019,7 +2016,6 @@ void main() { ...@@ -2019,7 +2016,6 @@ void main() {
textSelection: const TextSelection.collapsed(offset: 0), textSelection: const TextSelection.collapsed(offset: 0),
value: 'Guten Tag', value: 'Guten Tag',
actions: <SemanticsAction>[ actions: <SemanticsAction>[
SemanticsAction.tap,
SemanticsAction.longPress, SemanticsAction.longPress,
SemanticsAction.moveCursorForwardByCharacter, SemanticsAction.moveCursorForwardByCharacter,
SemanticsAction.moveCursorForwardByWord, SemanticsAction.moveCursorForwardByWord,
...@@ -2062,7 +2058,6 @@ void main() { ...@@ -2062,7 +2058,6 @@ void main() {
value: 'Guten Tag', value: 'Guten Tag',
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
actions: <SemanticsAction>[ actions: <SemanticsAction>[
SemanticsAction.tap,
SemanticsAction.longPress, SemanticsAction.longPress,
// Absent the following because enableInteractiveSelection: false // Absent the following because enableInteractiveSelection: false
// SemanticsAction.moveCursorBackwardByCharacter, // SemanticsAction.moveCursorBackwardByCharacter,
...@@ -2108,7 +2103,6 @@ void main() { ...@@ -2108,7 +2103,6 @@ void main() {
value: 'Hello', value: 'Hello',
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
actions: <SemanticsAction>[ actions: <SemanticsAction>[
SemanticsAction.tap,
SemanticsAction.longPress, SemanticsAction.longPress,
], ],
flags: <SemanticsFlag>[ flags: <SemanticsFlag>[
...@@ -2135,7 +2129,6 @@ void main() { ...@@ -2135,7 +2129,6 @@ void main() {
textSelection: const TextSelection.collapsed(offset: 5), textSelection: const TextSelection.collapsed(offset: 5),
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
actions: <SemanticsAction>[ actions: <SemanticsAction>[
SemanticsAction.tap,
SemanticsAction.longPress, SemanticsAction.longPress,
SemanticsAction.moveCursorBackwardByCharacter, SemanticsAction.moveCursorBackwardByCharacter,
SemanticsAction.moveCursorBackwardByWord, SemanticsAction.moveCursorBackwardByWord,
...@@ -2162,7 +2155,6 @@ void main() { ...@@ -2162,7 +2155,6 @@ void main() {
textSelection: const TextSelection(baseOffset: 5, extentOffset: 3), textSelection: const TextSelection(baseOffset: 5, extentOffset: 3),
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
actions: <SemanticsAction>[ actions: <SemanticsAction>[
SemanticsAction.tap,
SemanticsAction.longPress, SemanticsAction.longPress,
SemanticsAction.moveCursorBackwardByCharacter, SemanticsAction.moveCursorBackwardByCharacter,
SemanticsAction.moveCursorForwardByCharacter, SemanticsAction.moveCursorForwardByCharacter,
...@@ -2218,7 +2210,6 @@ void main() { ...@@ -2218,7 +2210,6 @@ void main() {
textSelection: const TextSelection.collapsed(offset: 5), textSelection: const TextSelection.collapsed(offset: 5),
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
actions: <SemanticsAction>[ actions: <SemanticsAction>[
SemanticsAction.tap,
SemanticsAction.longPress, SemanticsAction.longPress,
SemanticsAction.moveCursorBackwardByCharacter, SemanticsAction.moveCursorBackwardByCharacter,
SemanticsAction.moveCursorBackwardByWord, SemanticsAction.moveCursorBackwardByWord,
...@@ -2265,7 +2256,6 @@ void main() { ...@@ -2265,7 +2256,6 @@ void main() {
textSelection: const TextSelection(baseOffset: 0, extentOffset: 5), textSelection: const TextSelection(baseOffset: 0, extentOffset: 5),
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
actions: <SemanticsAction>[ actions: <SemanticsAction>[
SemanticsAction.tap,
SemanticsAction.longPress, SemanticsAction.longPress,
SemanticsAction.moveCursorBackwardByCharacter, SemanticsAction.moveCursorBackwardByCharacter,
SemanticsAction.moveCursorBackwardByWord, SemanticsAction.moveCursorBackwardByWord,
...@@ -2315,7 +2305,7 @@ void main() { ...@@ -2315,7 +2305,7 @@ void main() {
SemanticsFlag.isTextField, SemanticsFlag.isTextField,
SemanticsFlag.isMultiline, SemanticsFlag.isMultiline,
], ],
actions: <SemanticsAction>[SemanticsAction.tap, SemanticsAction.longPress], actions: <SemanticsAction>[SemanticsAction.longPress],
value: testValue, value: testValue,
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
), ),
...@@ -2324,7 +2314,7 @@ void main() { ...@@ -2324,7 +2314,7 @@ void main() {
ignoreRect: true, ignoreTransform: true, ignoreRect: true, ignoreTransform: true,
)); ));
semanticsOwner.performAction(inputFieldId, SemanticsAction.tap); semanticsOwner.performAction(inputFieldId, SemanticsAction.longPress);
await tester.pump(); await tester.pump();
expect(semantics, hasSemantics( expect(semantics, hasSemantics(
...@@ -2339,7 +2329,6 @@ void main() { ...@@ -2339,7 +2329,6 @@ void main() {
SemanticsFlag.isFocused, SemanticsFlag.isFocused,
], ],
actions: <SemanticsAction>[ actions: <SemanticsAction>[
SemanticsAction.tap,
SemanticsAction.longPress, SemanticsAction.longPress,
SemanticsAction.moveCursorBackwardByCharacter, SemanticsAction.moveCursorBackwardByCharacter,
SemanticsAction.moveCursorBackwardByWord, SemanticsAction.moveCursorBackwardByWord,
......
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