Skip to content

Commit a33575c

Browse files
authored
[Property Editor] Add workaround for embedded TextField focus issues (#8957)
1 parent 5e5b16e commit a33575c

4 files changed

Lines changed: 69 additions & 5 deletions

File tree

packages/devtools_app/lib/src/standalone_ui/ide_shared/property_editor/property_editor_view.dart

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class PropertyEditorView extends StatelessWidget {
6464
}
6565
}
6666

67-
class _PropertiesList extends StatelessWidget {
67+
class _PropertiesList extends StatefulWidget {
6868
const _PropertiesList({
6969
required this.editableProperties,
7070
required this.editProperty,
@@ -76,16 +76,34 @@ class _PropertiesList extends StatelessWidget {
7676
static const defaultItemPadding = borderPadding;
7777
static const denseItemPadding = defaultItemPadding / 2;
7878

79+
@override
80+
State<_PropertiesList> createState() => _PropertiesListState();
81+
}
82+
83+
class _PropertiesListState extends State<_PropertiesList> {
84+
@override
85+
void initState() {
86+
super.initState();
87+
// Workaround for https://github.com/flutter/devtools/issues/8929.
88+
setUpTextFieldFocusFixHandler();
89+
}
90+
91+
@override
92+
void dispose() {
93+
super.dispose();
94+
// Workaround for https://github.com/flutter/devtools/issues/8929.
95+
removeTextFieldFocusFixHandler();
96+
}
97+
7998
@override
8099
Widget build(BuildContext context) {
81100
return Column(
82101
children: <Widget>[
83-
...editableProperties.map(
84-
(property) => _EditablePropertyItem(
102+
for (final property in widget.editableProperties)
103+
_EditablePropertyItem(
85104
property: property,
86-
editProperty: editProperty,
105+
editProperty: widget.editProperty,
87106
),
88-
),
89107
].joinWith(const PaddedDivider.noPadding()),
90108
);
91109
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright 2025 The Flutter Authors
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file or at https://developers.google.com/open-source/licenses/bsd.
4+
5+
void addBlurListener() {
6+
// No-op for desktop platforms.
7+
}
8+
9+
void removeBlurListener() {
10+
// No-op for desktop platforms.
11+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2025 The Flutter Authors
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file or at https://developers.google.com/open-source/licenses/bsd.
4+
5+
import 'dart:js_interop';
6+
7+
import 'package:web/web.dart';
8+
9+
void addBlurListener() {
10+
window.addEventListener('blur', _onBlur.toJS);
11+
}
12+
13+
void removeBlurListener() {
14+
window.removeEventListener('blur', _onBlur.toJS);
15+
}
16+
17+
void _onBlur(Event _) {
18+
final inputElement = document.activeElement as HTMLElement?;
19+
inputElement?.blur();
20+
}

packages/devtools_app/lib/src/standalone_ui/ide_shared/property_editor/utils/utils.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// found in the LICENSE file or at https://developers.google.com/open-source/licenses/bsd.
44

55
import 'package:flutter/widgets.dart';
6+
import '_utils_desktop.dart' if (dart.library.js_interop) '_utils_web.dart';
67

78
/// Converts a [dartDocText] String into a [RichText] widget.
89
///
@@ -76,3 +77,17 @@ RichText convertDartDocToRichText(
7677

7778
return RichText(text: TextSpan(children: children));
7879
}
80+
81+
/// Workaround to prevent TextFields from holding onto focus when IFRAME-ed.
82+
///
83+
/// See https://github.com/flutter/devtools/issues/8929 for details.
84+
void setUpTextFieldFocusFixHandler() {
85+
addBlurListener();
86+
}
87+
88+
/// Workaround to prevent TextFields from holding onto focus when IFRAME-ed.
89+
///
90+
/// See https://github.com/flutter/devtools/issues/8929 for details.
91+
void removeTextFieldFocusFixHandler() {
92+
removeBlurListener();
93+
}

0 commit comments

Comments
 (0)