Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reverts "Fix focus management for text fields (#51009)" #53502

Merged
merged 1 commit into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 3 additions & 14 deletions lib/web_ui/lib/src/engine/dom.dart
Original file line number Diff line number Diff line change
Expand Up @@ -658,16 +658,7 @@ extension DomElementExtension on DomElement {
external JSNumber? get _tabIndex;
double? get tabIndex => _tabIndex?.toDartDouble;

@JS('focus')
external JSVoid _focus(JSAny options);

void focus({bool? preventScroll, bool? focusVisible}) {
final Map<String, bool> options = <String, bool>{
if (preventScroll != null) 'preventScroll': preventScroll,
if (focusVisible != null) 'focusVisible': focusVisible,
};
_focus(options.toJSAnyDeep);
}
external JSVoid focus();

@JS('scrollTop')
external JSNumber get _scrollTop;
Expand Down Expand Up @@ -2258,11 +2249,9 @@ extension DomKeyboardEventExtension on DomKeyboardEvent {
external JSBoolean? get _repeat;
bool? get repeat => _repeat?.toDart;

// Safari injects synthetic keyboard events after auto-complete that don't
// have a `shiftKey` attribute, so this property must be nullable.
@JS('shiftKey')
external JSBoolean? get _shiftKey;
bool? get shiftKey => _shiftKey?.toDart;
external JSBoolean get _shiftKey;
bool get shiftKey => _shiftKey.toDart;

@JS('isComposing')
external JSBoolean get _isComposing;
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/lib/src/engine/keyboard_binding.dart
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ class FlutterHtmlKeyboardEvent {
num? get timeStamp => _event.timeStamp;
bool get altKey => _event.altKey;
bool get ctrlKey => _event.ctrlKey;
bool get shiftKey => _event.shiftKey ?? false;
bool get shiftKey => _event.shiftKey;
bool get metaKey => _event.metaKey;
bool get isComposing => _event.isComposing;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ final class ViewFocusBinding {
///
/// DO NOT rely on this bit as it will go away soon. You're warned :)!
@visibleForTesting
static bool isEnabled = true;
static bool isEnabled = false;

final FlutterViewManager _viewManager;
final ui.ViewFocusChangeCallback _onViewFocusChange;
Expand Down Expand Up @@ -51,7 +51,7 @@ final class ViewFocusBinding {
if (state == ui.ViewFocusState.focused) {
// Only move the focus to the flutter view if nothing inside it is focused already.
if (viewId != _viewId(domDocument.activeElement)) {
viewElement?.focus(preventScroll: true);
viewElement?.focus();
}
} else {
viewElement?.blur();
Expand All @@ -70,7 +70,7 @@ final class ViewFocusBinding {

late final DomEventListener _handleKeyDown = createDomEventListener((DomEvent event) {
event as DomKeyboardEvent;
if (event.shiftKey ?? false) {
if (event.shiftKey) {
_viewFocusDirection = ui.ViewFocusDirection.backward;
}
});
Expand Down
16 changes: 0 additions & 16 deletions lib/web_ui/lib/src/engine/pointer_binding.dart
Original file line number Diff line number Diff line change
Expand Up @@ -982,22 +982,6 @@ class _PointerAdapter extends _BaseAdapter with _WheelEventListenerMixin {
);
_convertEventsToPointerData(data: pointerData, event: event, details: down);
_callback(event, pointerData);

if (event.target == _viewTarget) {
// Ensure smooth focus transitions between text fields within the Flutter view.
// Without preventing the default and this delay, the engine may not have fully
// rendered the next input element, leading to the focus incorrectly returning to
// the main Flutter view instead.
// A zero-length timer is sufficient in all tested browsers to achieve this.
event.preventDefault();
Timer(Duration.zero, () {
EnginePlatformDispatcher.instance.requestViewFocusChange(
viewId: _view.viewId,
state: ui.ViewFocusState.focused,
direction: ui.ViewFocusDirection.undefined,
);
});
}
});

// Why `domWindow` you ask? See this fiddle: https://jsfiddle.net/ditman/7towxaqp
Expand Down
Loading