Skip to content

Commit 82e04d7

Browse files
committed
autofocus, focus, blur to all form controls
1 parent effb4a2 commit 82e04d7

File tree

12 files changed

+117
-4
lines changed

12 files changed

+117
-4
lines changed

client/lib/controls/checkbox.dart

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,17 @@ class CheckboxControl extends StatefulWidget {
2828

2929
class _CheckboxControlState extends State<CheckboxControl> {
3030
bool? _value;
31+
final FocusNode _focusNode = FocusNode();
3132

3233
@override
3334
void initState() {
3435
super.initState();
36+
_focusNode.addListener(() {
37+
ws.pageEventFromWeb(
38+
eventTarget: widget.control.id,
39+
eventName: _focusNode.hasFocus ? "focus" : "blur",
40+
eventData: "");
41+
});
3542
}
3643

3744
@override
@@ -50,6 +57,7 @@ class _CheckboxControlState extends State<CheckboxControl> {
5057
widget.control.attrString("labelPosition", "")!.toLowerCase(),
5158
orElse: () => LabelPosition.right);
5259
bool tristate = widget.control.attrBool("tristate", false)!;
60+
bool autofocus = widget.control.attrBool("autofocus", false)!;
5361
bool disabled = widget.control.isDisabled || widget.parentDisabled;
5462

5563
return StoreConnector<AppState, Function>(
@@ -66,7 +74,7 @@ class _CheckboxControlState extends State<CheckboxControl> {
6674

6775
onChange(bool? value) {
6876
var svalue = value != null ? value.toString() : "";
69-
debugPrint(svalue);
77+
//debugPrint(svalue);
7078
setState(() {
7179
_value = value;
7280
});
@@ -83,6 +91,8 @@ class _CheckboxControlState extends State<CheckboxControl> {
8391
}
8492

8593
var checkbox = Checkbox(
94+
autofocus: autofocus,
95+
focusNode: _focusNode,
8696
value: _value,
8797
tristate: tristate,
8898
onChanged: !disabled

client/lib/controls/dropdown.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,18 @@ class DropdownControl extends StatefulWidget {
2828

2929
class _DropdownControlState extends State<DropdownControl> {
3030
String? _value;
31+
final FocusNode _focusNode = FocusNode();
32+
33+
@override
34+
void initState() {
35+
super.initState();
36+
_focusNode.addListener(() {
37+
ws.pageEventFromWeb(
38+
eventTarget: widget.control.id,
39+
eventName: _focusNode.hasFocus ? "focus" : "blur",
40+
eventData: "");
41+
});
42+
}
3143

3244
@override
3345
Widget build(BuildContext context) {
@@ -41,6 +53,7 @@ class _DropdownControlState extends State<DropdownControl> {
4153
builder: (context, itemsView) {
4254
debugPrint("Dropdown StoreConnector build: ${widget.control.id}");
4355

56+
bool autofocus = widget.control.attrBool("autofocus", false)!;
4457
bool disabled = widget.control.isDisabled || widget.parentDisabled;
4558

4659
String? value = widget.control.attrString("value");
@@ -54,6 +67,8 @@ class _DropdownControlState extends State<DropdownControl> {
5467
itemsView.children.where((c) => c.name == "suffix");
5568

5669
var dropDown = DropdownButtonFormField<String>(
70+
autofocus: autofocus,
71+
focusNode: _focusNode,
5772
value: _value,
5873
decoration: buildInputDecoration(
5974
widget.control,

client/lib/controls/elevated_button.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class ElevatedButtonControl extends StatelessWidget {
2929
Color? iconColor =
3030
HexColor.fromString(context, control.attrString("iconColor", "")!);
3131
var contentCtrls = children.where((c) => c.name == "content");
32+
bool autofocus = control.attrBool("autofocus", false)!;
3233
bool disabled = control.isDisabled || parentDisabled;
3334

3435
Function()? onPressed = disabled
@@ -45,6 +46,7 @@ class ElevatedButtonControl extends StatelessWidget {
4546

4647
if (icon != null) {
4748
button = ElevatedButton.icon(
49+
autofocus: autofocus,
4850
onPressed: onPressed,
4951
icon: Icon(
5052
icon,
@@ -53,6 +55,7 @@ class ElevatedButtonControl extends StatelessWidget {
5355
label: Text(text));
5456
} else if (contentCtrls.isNotEmpty) {
5557
button = ElevatedButton(
58+
autofocus: autofocus,
5659
onPressed: onPressed,
5760
child: createControl(control, contentCtrls.first.id, disabled));
5861
} else {

client/lib/controls/floating_action_button.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class FloatingActionButtonControl extends StatelessWidget {
3030
Color? bgColor =
3131
HexColor.fromString(context, control.attrString("bgColor", "")!);
3232
var contentCtrls = children.where((c) => c.name == "content");
33+
bool autofocus = control.attrBool("autofocus", false)!;
3334
bool disabled = control.isDisabled || parentDisabled;
3435

3536
Function()? onPressed = disabled
@@ -49,16 +50,19 @@ class FloatingActionButtonControl extends StatelessWidget {
4950
Widget button;
5051
if (contentCtrls.isNotEmpty) {
5152
button = FloatingActionButton(
53+
autofocus: autofocus,
5254
onPressed: onPressed,
5355
child: createControl(control, contentCtrls.first.id, disabled));
5456
} else if (icon != null && text == null) {
5557
button = FloatingActionButton(
58+
autofocus: autofocus,
5659
onPressed: onPressed,
5760
child: Icon(icon),
5861
backgroundColor: bgColor,
5962
);
6063
} else if (icon != null && text != null) {
6164
button = FloatingActionButton.extended(
65+
autofocus: autofocus,
6266
onPressed: onPressed,
6367
label: Text(text),
6468
icon: Icon(icon),

client/lib/controls/icon_button.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class IconButtonControl extends StatelessWidget {
3030
HexColor.fromString(context, control.attrString("iconColor", "")!);
3131
double? iconSize = control.attrDouble("iconSize");
3232
var contentCtrls = children.where((c) => c.name == "content");
33+
bool autofocus = control.attrBool("autofocus", false)!;
3334
bool disabled = control.isDisabled || parentDisabled;
3435

3536
Function()? onPressed = disabled
@@ -46,6 +47,7 @@ class IconButtonControl extends StatelessWidget {
4647

4748
if (icon != null) {
4849
button = IconButton(
50+
autofocus: autofocus,
4951
icon: Icon(
5052
icon,
5153
color: iconColor,
@@ -54,6 +56,7 @@ class IconButtonControl extends StatelessWidget {
5456
onPressed: onPressed);
5557
} else if (contentCtrls.isNotEmpty) {
5658
button = IconButton(
59+
autofocus: autofocus,
5760
onPressed: onPressed,
5861
iconSize: iconSize,
5962
icon: createControl(control, contentCtrls.first.id, disabled));

client/lib/controls/outlined_button.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class OutlinedButtonControl extends StatelessWidget {
2929
Color? iconColor =
3030
HexColor.fromString(context, control.attrString("iconColor", "")!);
3131
var contentCtrls = children.where((c) => c.name == "content");
32+
bool autofocus = control.attrBool("autofocus", false)!;
3233
bool disabled = control.isDisabled || parentDisabled;
3334

3435
Function()? onPressed = disabled
@@ -45,6 +46,7 @@ class OutlinedButtonControl extends StatelessWidget {
4546

4647
if (icon != null) {
4748
button = OutlinedButton.icon(
49+
autofocus: autofocus,
4850
onPressed: onPressed,
4951
icon: Icon(
5052
icon,
@@ -53,6 +55,7 @@ class OutlinedButtonControl extends StatelessWidget {
5355
label: Text(text));
5456
} else if (contentCtrls.isNotEmpty) {
5557
button = OutlinedButton(
58+
autofocus: autofocus,
5659
onPressed: onPressed,
5760
child: createControl(control, contentCtrls.first.id, disabled));
5861
} else {

client/lib/controls/radio.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,17 @@ class RadioControl extends StatefulWidget {
3030
}
3131

3232
class _RadioControlState extends State<RadioControl> {
33+
final FocusNode _focusNode = FocusNode();
34+
3335
@override
3436
void initState() {
3537
super.initState();
38+
_focusNode.addListener(() {
39+
ws.pageEventFromWeb(
40+
eventTarget: widget.control.id,
41+
eventName: _focusNode.hasFocus ? "focus" : "blur",
42+
eventData: "");
43+
});
3644
}
3745

3846
@override
@@ -51,6 +59,7 @@ class _RadioControlState extends State<RadioControl> {
5159
p.name.toLowerCase() ==
5260
widget.control.attrString("labelPosition", "")!.toLowerCase(),
5361
orElse: () => LabelPosition.right);
62+
bool autofocus = widget.control.attrBool("autofocus", false)!;
5463
bool disabled = widget.control.isDisabled || widget.parentDisabled;
5564

5665
return StoreConnector<AppState, ControlAncestorViewModel>(
@@ -83,6 +92,8 @@ class _RadioControlState extends State<RadioControl> {
8392
}
8493

8594
var radio = Radio<String>(
95+
autofocus: autofocus,
96+
focusNode: _focusNode,
8697
groupValue: groupValue,
8798
value: value,
8899
onChanged: !disabled

client/lib/controls/slider.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,17 @@ class SliderControl extends StatefulWidget {
2929
class _SliderControlState extends State<SliderControl> {
3030
double _value = 0;
3131
Timer? _debounce;
32+
final FocusNode _focusNode = FocusNode();
3233

3334
@override
3435
void initState() {
3536
super.initState();
37+
_focusNode.addListener(() {
38+
ws.pageEventFromWeb(
39+
eventTarget: widget.control.id,
40+
eventName: _focusNode.hasFocus ? "focus" : "blur",
41+
eventData: "");
42+
});
3643
}
3744

3845
@override
@@ -68,6 +75,7 @@ class _SliderControlState extends State<SliderControl> {
6875
debugPrint("SliderControl build: ${widget.control.id}");
6976

7077
String? label = widget.control.attrString("label");
78+
bool autofocus = widget.control.attrBool("autofocus", false)!;
7179
bool disabled = widget.control.isDisabled || widget.parentDisabled;
7280

7381
double min = widget.control.attrDouble("min", 0)!;
@@ -87,6 +95,8 @@ class _SliderControlState extends State<SliderControl> {
8795
}
8896

8997
var slider = Slider(
98+
autofocus: autofocus,
99+
focusNode: _focusNode,
90100
value: _value,
91101
min: min,
92102
max: max,

client/lib/controls/switch.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,17 @@ class SwitchControl extends StatefulWidget {
2828

2929
class _SwitchControlState extends State<SwitchControl> {
3030
bool _value = false;
31+
final FocusNode _focusNode = FocusNode();
3132

3233
@override
3334
void initState() {
3435
super.initState();
36+
_focusNode.addListener(() {
37+
ws.pageEventFromWeb(
38+
eventTarget: widget.control.id,
39+
eventName: _focusNode.hasFocus ? "focus" : "blur",
40+
eventData: "");
41+
});
3542
}
3643

3744
@override
@@ -49,6 +56,7 @@ class _SwitchControlState extends State<SwitchControl> {
4956
p.name.toLowerCase() ==
5057
widget.control.attrString("labelPosition", "")!.toLowerCase(),
5158
orElse: () => LabelPosition.right);
59+
bool autofocus = widget.control.attrBool("autofocus", false)!;
5260
bool disabled = widget.control.isDisabled || widget.parentDisabled;
5361

5462
return StoreConnector<AppState, Function>(
@@ -81,6 +89,8 @@ class _SwitchControlState extends State<SwitchControl> {
8189
}
8290

8391
var swtch = Switch(
92+
autofocus: autofocus,
93+
focusNode: _focusNode,
8494
value: _value,
8595
onChanged: !disabled
8696
? (bool value) {

client/lib/controls/text_button.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class TextButtonControl extends StatelessWidget {
2929
Color? iconColor =
3030
HexColor.fromString(context, control.attrString("iconColor", "")!);
3131
var contentCtrls = children.where((c) => c.name == "content");
32+
bool autofocus = control.attrBool("autofocus", false)!;
3233
bool disabled = control.isDisabled || parentDisabled;
3334

3435
Function()? onPressed = disabled
@@ -45,6 +46,7 @@ class TextButtonControl extends StatelessWidget {
4546

4647
if (icon != null) {
4748
button = TextButton.icon(
49+
autofocus: autofocus,
4850
onPressed: onPressed,
4951
icon: Icon(
5052
icon,
@@ -53,6 +55,7 @@ class TextButtonControl extends StatelessWidget {
5355
label: Text(text));
5456
} else if (contentCtrls.isNotEmpty) {
5557
button = TextButton(
58+
autofocus: autofocus,
5659
onPressed: onPressed,
5760
child: createControl(control, contentCtrls.first.id, disabled));
5861
} else {

0 commit comments

Comments
 (0)