diff --git a/base_control.go b/base_control.go index a98049e..fd89b97 100644 --- a/base_control.go +++ b/base_control.go @@ -172,7 +172,7 @@ func (c *BaseControl) SetVisible(visible bool) { } go func() { - if !c.inactive { + if FindFirstActiveControl(c) != nil && !c.inactive { PutEvent(Event{Type: EventKey, Key: term.KeyTab}) } PutEvent(Event{Type: EventLayout, Target: p}) diff --git a/ctrlutil.go b/ctrlutil.go index 6ec926a..bf031b7 100644 --- a/ctrlutil.go +++ b/ctrlutil.go @@ -178,6 +178,16 @@ func ActiveControl(parent Control) Control { return FindFirstControl(parent, fnActive) } +// FindFirstActiveControl returns the first active control of a parent +func FindFirstActiveControl(parent Control) Control { + for _, curr := range getLinearControlList(parent, nil) { + if curr.Active() { + return curr + } + } + return nil +} + func getLinearControlList(parent Control, fn func(Control) bool) []Control { result := []Control{}