[GH-ISSUE #286] Reset form focused element to 0 #222

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

Originally created by @mikeschinkel on GitHub (Jun 1, 2019).
Original GitHub issue: https://github.com/rivo/tview/issues/286

First, let me thank you profusely for tview. It is empowering me to build a UI for an open-source CLI tool that I would likely never have been able to implement otherwise!

I have a flex with a treeview on the left and a form on the right. If I select a treeview node it my app changes to focus on the form. If the user selects the cancel button it returns to the treeview.

However, when the user selects the treeview node again it returns to the form with the cancel button still selected. I think it would be a better UX if the form reset to having its first element having focus. However, review the source it appears that form.focusedElement is private and there does not appear to be a method to set it.

Am I missing something obvious, or is this currently not possible with the existing feature set?
If the latter, would you accept a pull request to add this (assuming I can figure out how?)

Originally created by @mikeschinkel on GitHub (Jun 1, 2019). Original GitHub issue: https://github.com/rivo/tview/issues/286 First, let me thank you profusely for tview. It is empowering me to build a UI for an open-source CLI tool that I would likely never have been able to implement otherwise! I have a flex with a treeview on the left and a form on the right. If I select a treeview node it my app changes to focus on the form. If the user selects the cancel button it returns to the treeview. However, when the user selects the treeview node again it returns to the form with the cancel button still selected. I think it would be a better UX if the form reset to having its first element having focus. However, review the source it appears that `form.focusedElement` is private and there does not appear to be a method to set it. Am I missing something obvious, or is this currently not possible with the existing feature set? If the latter, would you accept a pull request to add this _(assuming I can figure out how?)_
kerem closed this issue 2026-03-04 01:03:06 +03:00
Author
Owner

@rivo commented on GitHub (Jun 2, 2019):

The latest commit adds a function SetFocus() to Form and I believe form.SetFocus(0) should do what you're asking for. Cheers!

<!-- gh-comment-id:498058944 --> @rivo commented on GitHub (Jun 2, 2019): The latest commit adds a function `SetFocus()` to `Form` and I believe `form.SetFocus(0)` should do what you're asking for. Cheers!
Author
Owner

@mikeschinkel commented on GitHub (Jun 3, 2019):

@rivo Wow, talks about service! Thank you for such a quick response on an open-source package.

<!-- gh-comment-id:498083275 --> @mikeschinkel commented on GitHub (Jun 3, 2019): @rivo Wow, talks about service! Thank you for such a quick response on an open-source package.
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#222
No description provided.