diff --git a/packages/flutter/lib/src/cupertino/text_field.dart b/packages/flutter/lib/src/cupertino/text_field.dart index 9b58ac40c9..0bb33fca4c 100644 --- a/packages/flutter/lib/src/cupertino/text_field.dart +++ b/packages/flutter/lib/src/cupertino/text_field.dart @@ -4,7 +4,7 @@ import 'dart:ui' as ui show BoxHeightStyle, BoxWidthStyle; -import 'package:flutter/foundation.dart' show defaultTargetPlatform; +import 'package:flutter/foundation.dart' show defaultTargetPlatform, kIsWeb; import 'package:flutter/gestures.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter/services.dart'; @@ -18,6 +18,16 @@ import 'theme.dart'; export 'package:flutter/services.dart' show TextInputType, TextInputAction, TextCapitalization, SmartQuotesType, SmartDashesType; +// This is a temporary fix for: https://github.com/flutter/flutter/issues/79012 +/// A map used to disable scrolling shortcuts in text fields. +final Map _webScrollShortcutOverrides = { + LogicalKeySet(LogicalKeyboardKey.space): DoNothingAndStopPropagationIntent(), + LogicalKeySet(LogicalKeyboardKey.arrowUp): DoNothingAndStopPropagationIntent(), + LogicalKeySet(LogicalKeyboardKey.arrowDown): DoNothingAndStopPropagationIntent(), + LogicalKeySet(LogicalKeyboardKey.arrowLeft): DoNothingAndStopPropagationIntent(), + LogicalKeySet(LogicalKeyboardKey.arrowRight): DoNothingAndStopPropagationIntent(), +}; + const TextStyle _kDefaultPlaceholderStyle = TextStyle( fontWeight: FontWeight.w400, color: CupertinoColors.placeholderText, @@ -1212,7 +1222,7 @@ class _CupertinoTextFieldState extends State with Restoratio ), ); - return Semantics( + final Widget child = Semantics( enabled: enabled, onTap: !enabled || widget.readOnly ? null : () { if (!controller.selection.isValid) { @@ -1238,5 +1248,13 @@ class _CupertinoTextFieldState extends State with Restoratio ), ), ); + + if (kIsWeb) { + return Shortcuts( + shortcuts: _webScrollShortcutOverrides, + child: child, + ); + } + return child; } } diff --git a/packages/flutter/lib/src/material/text_field.dart b/packages/flutter/lib/src/material/text_field.dart index 8b908e8f17..7f482ff0ae 100644 --- a/packages/flutter/lib/src/material/text_field.dart +++ b/packages/flutter/lib/src/material/text_field.dart @@ -24,6 +24,16 @@ import 'theme.dart'; export 'package:flutter/services.dart' show TextInputType, TextInputAction, TextCapitalization, SmartQuotesType, SmartDashesType; +// This is a temporary fix for: https://github.com/flutter/flutter/issues/79012 +/// A map used to disable scrolling shortcuts in text fields. +final Map _webScrollShortcutOverrides = { + LogicalKeySet(LogicalKeyboardKey.space): DoNothingAndStopPropagationIntent(), + LogicalKeySet(LogicalKeyboardKey.arrowUp): DoNothingAndStopPropagationIntent(), + LogicalKeySet(LogicalKeyboardKey.arrowDown): DoNothingAndStopPropagationIntent(), + LogicalKeySet(LogicalKeyboardKey.arrowLeft): DoNothingAndStopPropagationIntent(), + LogicalKeySet(LogicalKeyboardKey.arrowRight): DoNothingAndStopPropagationIntent(), +}; + /// Signature for the [TextField.buildCounter] callback. typedef InputCounterWidgetBuilder = Widget? Function( /// The build context for the TextField. @@ -1301,7 +1311,7 @@ class _TextFieldState extends State with RestorationMixin implements semanticsMaxValueLength = null; } - return MouseRegion( + child = MouseRegion( cursor: effectiveMouseCursor, onEnter: (PointerEnterEvent event) => _handleHover(true), onExit: (PointerExitEvent event) => _handleHover(false), @@ -1329,5 +1339,13 @@ class _TextFieldState extends State with RestorationMixin implements ), ), ); + + if (kIsWeb) { + return Shortcuts( + shortcuts: _webScrollShortcutOverrides, + child: child, + ); + } + return child; } }