[GH-ISSUE #202] After init how to set focus in Flex #159

Closed
opened 2026-03-04 01:02:29 +03:00 by kerem · 2 comments
Owner

Originally created by @delaneyj on GitHub (Dec 5, 2018).
Original GitHub issue: https://github.com/rivo/tview/issues/202

There appears to be no way to set the focused item in a Flex after initialization. I tried adding stuff like

func (f *Flex) FocusItem(p Primitive) *Flex {
	for _, item := range f.items {
		item.Focus = item.Item == p
	}
	return f
}
``` but didn't have desired effect
Originally created by @delaneyj on GitHub (Dec 5, 2018). Original GitHub issue: https://github.com/rivo/tview/issues/202 There appears to be no way to set the focused item in a `Flex` after initialization. I tried adding stuff like ``` func (f *Flex) FocusItem(p Primitive) *Flex { for _, item := range f.items { item.Focus = item.Item == p } return f } ``` but didn't have desired effect
kerem closed this issue 2026-03-04 01:02:29 +03:00
Author
Owner

@rivo commented on GitHub (Dec 14, 2018):

I'm not quite sure I understand. (Your code appears to extend this package which confuses me.)

The Flex.AddItem() function includes a parameter focus which can be set to true to give it focus. If you don't know at that time which element should have focus, you can always use Application.SetFocus() later and provide your flex item.

Let me know if this clarifies it for you. If not, it would help to see some example code that illustrates your issue.

<!-- gh-comment-id:447387967 --> @rivo commented on GitHub (Dec 14, 2018): I'm not quite sure I understand. (Your code appears to extend this package which confuses me.) The [`Flex.AddItem()`](https://godoc.org/github.com/rivo/tview#Flex.AddItem) function includes a parameter `focus` which can be set to `true` to give it focus. If you don't know at that time which element should have focus, you can always use [`Application.SetFocus()`](https://godoc.org/github.com/rivo/tview#Application.SetFocus) later and provide your flex item. Let me know if this clarifies it for you. If not, it would help to see some example code that illustrates your issue.
Author
Owner

@rivo commented on GitHub (Dec 25, 2018):

I'll reopen if it turns out this is not yet resolved.

<!-- gh-comment-id:449847029 --> @rivo commented on GitHub (Dec 25, 2018): I'll reopen if it turns out this is not yet resolved.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/tview#159
No description provided.