Skip to content

Commit 20f527f

Browse files
authored
Merge pull request #1384 from Cyrine-benabid/fix-option_button_doesnt-close_popover
Close popover on text field tap
2 parents 992be37 + c7d8a0b commit 20f527f

File tree

2 files changed

+42
-7
lines changed

2 files changed

+42
-7
lines changed

frontend/app_flowy/lib/plugins/grid/presentation/widgets/common/text_field.dart

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class InputTextField extends StatefulWidget {
1313
final bool autoClearWhenDone;
1414
final String text;
1515
final int? maxLength;
16+
final FocusNode? focusNode;
1617

1718
const InputTextField({
1819
required this.text,
@@ -21,6 +22,7 @@ class InputTextField extends StatefulWidget {
2122
this.onChanged,
2223
this.autoClearWhenDone = false,
2324
this.maxLength,
25+
this.focusNode,
2426
Key? key,
2527
}) : super(key: key);
2628

@@ -35,7 +37,7 @@ class _InputTextFieldState extends State<InputTextField> {
3537

3638
@override
3739
void initState() {
38-
_focusNode = FocusNode();
40+
_focusNode = widget.focusNode ?? FocusNode();
3941
_controller = TextEditingController(text: widget.text);
4042
SchedulerBinding.instance.addPostFrameCallback((Duration _) {
4143
_focusNode.requestFocus();
@@ -81,7 +83,10 @@ class _InputTextFieldState extends State<InputTextField> {
8183
@override
8284
void dispose() {
8385
_focusNode.removeListener(notifyDidEndEditing);
84-
_focusNode.dispose();
86+
// only dispose the focusNode if it was created in this widget's initState
87+
if (widget.focusNode == null) {
88+
_focusNode.dispose();
89+
}
8590
super.dispose();
8691
}
8792

frontend/app_flowy/lib/plugins/grid/presentation/widgets/header/type_option/select_option.dart

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,11 @@ class SelectOptionTypeOptionWidget extends StatelessWidget {
4545
const TypeOptionSeparator(),
4646
const OptionTitle(),
4747
if (state.isEditingOption)
48-
const Padding(
49-
padding: EdgeInsets.only(bottom: 10),
50-
child: _CreateOptionTextField(),
48+
Padding(
49+
padding: const EdgeInsets.only(bottom: 10),
50+
child: _CreateOptionTextField(
51+
popoverMutex: popoverMutex,
52+
),
5153
),
5254
if (state.options.isEmpty && !state.isEditingOption)
5355
const _AddOptionButton(),
@@ -251,8 +253,35 @@ class _AddOptionButton extends StatelessWidget {
251253
}
252254
}
253255

254-
class _CreateOptionTextField extends StatelessWidget {
255-
const _CreateOptionTextField({Key? key}) : super(key: key);
256+
class _CreateOptionTextField extends StatefulWidget {
257+
final PopoverMutex? popoverMutex;
258+
const _CreateOptionTextField({
259+
Key? key,
260+
this.popoverMutex,
261+
}) : super(key: key);
262+
263+
@override
264+
State<_CreateOptionTextField> createState() => _CreateOptionTextFieldState();
265+
}
266+
267+
class _CreateOptionTextFieldState extends State<_CreateOptionTextField> {
268+
late final FocusNode _focusNode;
269+
270+
@override
271+
void initState() {
272+
_focusNode = FocusNode();
273+
_focusNode.addListener(() {
274+
if (_focusNode.hasFocus) {
275+
widget.popoverMutex?.close();
276+
}
277+
});
278+
widget.popoverMutex?.listenOnPopoverChanged(() {
279+
if (_focusNode.hasFocus) {
280+
_focusNode.unfocus();
281+
}
282+
});
283+
super.initState();
284+
}
256285

257286
@override
258287
Widget build(BuildContext context) {
@@ -263,6 +292,7 @@ class _CreateOptionTextField extends StatelessWidget {
263292
autoClearWhenDone: true,
264293
maxLength: 30,
265294
text: text,
295+
focusNode: _focusNode,
266296
onCanceled: () {
267297
context
268298
.read<SelectOptionTypeOptionBloc>()

0 commit comments

Comments
 (0)