Skip to content

Commit 3e76fa8

Browse files
fix: close popover on add option button clicked and textfield focused
1 parent c8044a9 commit 3e76fa8

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class InputTextField extends StatefulWidget {
99
final void Function(String)? onDone;
1010
final void Function(String)? onChanged;
1111
final void Function() onCanceled;
12+
final void Function()? onFocused;
1213
final bool autoClearWhenDone;
1314
final String text;
1415
final int? maxLength;
@@ -18,6 +19,7 @@ class InputTextField extends StatefulWidget {
1819
this.onDone,
1920
required this.onCanceled,
2021
this.onChanged,
22+
this.onFocused,
2123
this.autoClearWhenDone = false,
2224
this.maxLength,
2325
Key? key,
@@ -90,6 +92,10 @@ class _InputTextFieldState extends State<InputTextField> {
9092
widget.onDone!(_controller.text);
9193
}
9294
}
95+
} else {
96+
if (widget.onFocused != null) {
97+
widget.onFocused!();
98+
}
9399
}
94100
}
95101
}

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

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,15 @@ class SelectOptionTypeOptionWidget extends StatelessWidget {
4343
builder: (context, state) {
4444
List<Widget> children = [
4545
const TypeOptionSeparator(),
46-
const OptionTitle(),
46+
OptionTitle(
47+
popoverMutex: popoverMutex,
48+
),
4749
if (state.isEditingOption)
48-
const Padding(
49-
padding: EdgeInsets.only(bottom: 10),
50-
child: _CreateOptionTextField(),
50+
Padding(
51+
padding: const EdgeInsets.only(bottom: 10),
52+
child: _CreateOptionTextField(
53+
popoverMutex: popoverMutex,
54+
),
5155
),
5256
if (state.options.isEmpty && !state.isEditingOption)
5357
const _AddOptionButton(),
@@ -62,7 +66,9 @@ class SelectOptionTypeOptionWidget extends StatelessWidget {
6266
}
6367

6468
class OptionTitle extends StatelessWidget {
65-
const OptionTitle({Key? key}) : super(key: key);
69+
final PopoverMutex? popoverMutex;
70+
71+
const OptionTitle({this.popoverMutex, Key? key}) : super(key: key);
6672

6773
@override
6874
Widget build(BuildContext context) {
@@ -78,7 +84,9 @@ class OptionTitle extends StatelessWidget {
7884
];
7985
if (state.options.isNotEmpty && !state.isEditingOption) {
8086
children.add(const Spacer());
81-
children.add(const _OptionTitleButton());
87+
children.add(_OptionTitleButton(
88+
popoverMutex: popoverMutex,
89+
));
8290
}
8391

8492
return SizedBox(
@@ -91,7 +99,9 @@ class OptionTitle extends StatelessWidget {
9199
}
92100

93101
class _OptionTitleButton extends StatelessWidget {
94-
const _OptionTitleButton({Key? key}) : super(key: key);
102+
final PopoverMutex? popoverMutex;
103+
104+
const _OptionTitleButton({this.popoverMutex, Key? key}) : super(key: key);
95105

96106
@override
97107
Widget build(BuildContext context) {
@@ -107,6 +117,7 @@ class _OptionTitleButton extends StatelessWidget {
107117
),
108118
hoverColor: theme.hover,
109119
onTap: () {
120+
popoverMutex?.close();
110121
context
111122
.read<SelectOptionTypeOptionBloc>()
112123
.add(const SelectOptionTypeOptionEvent.addingOption());
@@ -252,7 +263,8 @@ class _AddOptionButton extends StatelessWidget {
252263
}
253264

254265
class _CreateOptionTextField extends StatelessWidget {
255-
const _CreateOptionTextField({Key? key}) : super(key: key);
266+
final PopoverMutex? popoverMutex;
267+
const _CreateOptionTextField({this.popoverMutex, Key? key}) : super(key: key);
256268

257269
@override
258270
Widget build(BuildContext context) {
@@ -273,6 +285,9 @@ class _CreateOptionTextField extends StatelessWidget {
273285
.read<SelectOptionTypeOptionBloc>()
274286
.add(SelectOptionTypeOptionEvent.createOption(optionName));
275287
},
288+
onFocused: () {
289+
popoverMutex?.close();
290+
},
276291
);
277292
},
278293
);

0 commit comments

Comments
 (0)