[GH-ISSUE #555] Widgets inside a grid doesn't change focus when tab key is pressed #406

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

Originally created by @jcbritobr on GitHub (Jan 24, 2021).
Original GitHub issue: https://github.com/rivo/tview/issues/555

The code below has a problem that the bunttons inside the grid doesn't change or receive focus when tab key is pressed:

windows 10 64, golang 1.15.5_64

package main

import (
	"github.com/rivo/tview"
)

func main() {
	app := tview.NewApplication()
	grid := tview.NewGrid().SetRows(3, 3, 3)
	grid.SetBorderPadding(2, 2, 2, 2)

	text := tview.NewTextView()
	text.SetText("initial text")
	button := tview.NewButton("Clique me").SetSelectedFunc(func() {
		app.Stop()
	})

	btn2 := tview.NewButton("Button 2")
	btn2.SetSelectedFunc(func() {
		text.SetText("buttton clicked")
	})

	grid.AddItem(button, 0, 0, 1, 1, 0, 0, true)
	grid.AddItem(btn2, 0, 1, 1, 1, 0, 0, false)
	grid.AddItem(text, 0, 2, 1, 1, 0, 0, false)

	if err := app.SetRoot(grid, true).Run(); err != nil {
		panic(err)
	}
}

I'm very new on tview, and I'm following the examples, but I think there are something wrong with this behavior.

image

Originally created by @jcbritobr on GitHub (Jan 24, 2021). Original GitHub issue: https://github.com/rivo/tview/issues/555 The code below has a problem that the bunttons inside the grid doesn't change or receive focus when tab key is pressed: windows 10 64, golang 1.15.5_64 ```go package main import ( "github.com/rivo/tview" ) func main() { app := tview.NewApplication() grid := tview.NewGrid().SetRows(3, 3, 3) grid.SetBorderPadding(2, 2, 2, 2) text := tview.NewTextView() text.SetText("initial text") button := tview.NewButton("Clique me").SetSelectedFunc(func() { app.Stop() }) btn2 := tview.NewButton("Button 2") btn2.SetSelectedFunc(func() { text.SetText("buttton clicked") }) grid.AddItem(button, 0, 0, 1, 1, 0, 0, true) grid.AddItem(btn2, 0, 1, 1, 1, 0, 0, false) grid.AddItem(text, 0, 2, 1, 1, 0, 0, false) if err := app.SetRoot(grid, true).Run(); err != nil { panic(err) } } ``` I'm very new on tview, and I'm following the examples, but I think there are something wrong with this behavior. ![image](https://user-images.githubusercontent.com/6579862/105642147-b4ec6b00-5e66-11eb-8683-76e2429ebfd9.png)
kerem closed this issue 2026-03-04 01:04:42 +03:00
Author
Owner

@rivo commented on GitHub (Feb 17, 2021):

Your first button has the current focus (you can see that because it's white) so it receives keyboard input. The Tab key is not bound to any action on the buttons, however, so nothing happens. You can use SetInputCapture() to implement the desired action for the buttons.

Or if you really just want to have buttons in a horizontal layout, you could use Form with just buttons and no other fields. It implements button navigation with the Tab key.

Let me know if this helps.

<!-- gh-comment-id:780429138 --> @rivo commented on GitHub (Feb 17, 2021): Your first button has the current focus (you can see that because it's white) so it receives keyboard input. The Tab key is not bound to any action on the buttons, however, so nothing happens. You can use [`SetInputCapture()`](https://pkg.go.dev/github.com/rivo/tview#Box.SetInputCapture) to implement the desired action for the buttons. Or if you really just want to have buttons in a horizontal layout, you could use `Form` with just buttons and no other fields. It implements button navigation with the Tab key. Let me know if this helps.
Author
Owner

@jcbritobr commented on GitHub (Feb 17, 2021):

Hello. Thank you by the help. I1ll try here and will be back.

<!-- gh-comment-id:780597630 --> @jcbritobr commented on GitHub (Feb 17, 2021): Hello. Thank you by the help. I1ll try here and will be back.
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#406
No description provided.