File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -479,6 +479,11 @@ func (f *Form) PrevField() tea.Cmd {
479
479
return cmd
480
480
}
481
481
482
+ // GetFocusedField returns the focused form field.
483
+ func (f * Form ) GetFocusedField () Field {
484
+ return f .selector .Selected ().selector .Selected ()
485
+ }
486
+
482
487
// Init initializes the form.
483
488
func (f * Form ) Init () tea.Cmd {
484
489
cmds := make ([]tea.Cmd , f .selector .Total ())
Original file line number Diff line number Diff line change @@ -918,6 +918,24 @@ func TestAbort(t *testing.T) {
918
918
}
919
919
}
920
920
921
+ func TestGetFocusedField (t * testing.T ) {
922
+ f := NewForm (
923
+ NewGroup (
924
+ NewInput ().Title ("First" ).Key ("First" ),
925
+ NewInput ().Title ("Second" ).Key ("Second" ),
926
+ NewInput ().Title ("Third" ).Key ("Third" ),
927
+ ),
928
+ ).WithWidth (25 )
929
+ f = batchUpdate (f , f .Init ()).(* Form )
930
+
931
+ f .NextField ()
932
+ field := f .GetFocusedField ()
933
+
934
+ if field .GetKey () != "Second" {
935
+ t .Error ("Expected Second field to be focused but was '" + field .GetKey () + "'" )
936
+ }
937
+ }
938
+
921
939
// formProgram returns a new Form with a nil input and output, so it can be used as a test program.
922
940
func formProgram () * Form {
923
941
return NewForm (NewGroup (NewInput ().Title ("Foo" ))).
You can’t perform that action at this time.
0 commit comments