Skip to content

Commit b64d8cd

Browse files
authored
Merge pull request #1890 from EnsembleUI/keep-keyboard-focus
new properties to form and TextInput widget for keyboard dissmiss control
2 parents 3375794 + 9234bcb commit b64d8cd

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed

modules/ensemble/lib/layout/form.dart

+2
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class EnsembleForm extends StatefulWidget
6868
_controller.labelStyle = Utils.getTextStyle(value),
6969
'enabled': (value) => _controller.enabled = Utils.optionalBool(value),
7070
'readOnly': (value) => _controller.readOnly = Utils.optionalBool(value),
71+
'dismissibleKeyboard': (value) => _controller.dismissibleKeyboard = Utils.getBool(value, fallback: _controller.dismissibleKeyboard),
7172
'width': (value) => _controller.width = Utils.optionalInt(value),
7273
'height': (value) => _controller.height = Utils.optionalInt(value),
7374
'gap': (value) => _controller.gap =
@@ -110,6 +111,7 @@ class FormController extends WidgetController {
110111
String? labelOverflow;
111112
bool? enabled;
112113
bool? readOnly;
114+
bool dismissibleKeyboard = true;
113115

114116
// labelMaxWidth applicable only to labelPosition=start
115117
int? labelMaxWidth;

modules/ensemble/lib/widget/button.dart

+3-1
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,9 @@ class ButtonState extends EWidgetState<Button> {
280280
// if focus in on a formfield (e.g. TextField), clicking on button will
281281
// not remove focus, so its value is never updated. Unfocus here before
282282
// executing button click ensure we get all the latest value of the form fields
283-
FocusManager.instance.primaryFocus?.unfocus();
283+
if (widget._controller.submitForm == false) {
284+
FocusManager.instance.primaryFocus?.unfocus();
285+
}
284286

285287
// submit the form if specified
286288
if (widget._controller.submitForm == true) {

modules/ensemble/lib/widget/helpers/form_helper.dart

+4
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ class FormHelper {
118118
event: EnsembleEvent(formState.widget));
119119
}
120120
}
121+
// only dismiss keyboard if dismissKeyboardOnSubmit is true (By default it is true)
122+
if(formState?.widget.controller.dismissibleKeyboard == true) {
123+
FocusManager.instance.primaryFocus?.unfocus();
124+
}
121125
}
122126
}
123127

modules/ensemble/lib/widget/input/form_textfield.dart

+6
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ abstract class BaseTextInput extends StatefulWidget
145145
'validator': (value) => _controller.validator = Utils.getValidator(value),
146146
'enableClearText': (value) =>
147147
_controller.enableClearText = Utils.optionalBool(value),
148+
'dismissibleKeyboard': (value) =>
149+
_controller.dismissibleKeyboard = Utils.getBool(value, fallback: _controller.dismissibleKeyboard),
148150
'obscureToggle': (value) =>
149151
_controller.obscureToggle = Utils.optionalBool(value),
150152
'obscured': (widget) => _controller.obscureText == true,
@@ -224,6 +226,7 @@ class TextInputController extends FormFieldController with HasTextPlaceholder {
224226
EnsembleAction? onFocusReceived;
225227
EnsembleAction? onFocusLost;
226228
bool? enableClearText;
229+
bool dismissibleKeyboard = true;
227230

228231
// applicable only for TextInput
229232
bool? obscureText;
@@ -305,7 +308,10 @@ class TextInputState extends FormFieldWidgetState<BaseTextInput>
305308
overlayEntry!.remove();
306309
overlayEntry = null;
307310
}
311+
// only dismiss if dismissibleKeyboard is true (By Default dismissibleKeyboard is true)
312+
if(widget._controller.dismissibleKeyboard == true){
308313
FocusManager.instance.primaryFocus?.unfocus();
314+
}
309315
}
310316

311317
@override

0 commit comments

Comments
 (0)