[GH-ISSUE #869] Focus callback not called when a form receives focus? #631

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

Originally created by @adrianludwin on GitHub (Aug 23, 2023).
Original GitHub issue: https://github.com/rivo/tview/issues/869

Hi, I have a form in a grid layout, and I'd like the form to be highlighted when it has focus. For Lists, I was able to set the Focus/Blur callback to change the background colour, but this didn't seem to work for the Form. I believe this is because, while Box.Focus() calls the callback, Form.Focus() does not.

Would it be possible/advisable to call the callback in the form before passing the focus to the FormItem? After all, Form.HasFocus() returns true if any of its items have focus, so it might make sense for the callback to be called too. But I don't know what the implications of this are, or whether Blur() would be called properly as well.

Originally created by @adrianludwin on GitHub (Aug 23, 2023). Original GitHub issue: https://github.com/rivo/tview/issues/869 Hi, I have a form in a grid layout, and I'd like the form to be highlighted when it has focus. For Lists, I was able to set the Focus/Blur callback to change the background colour, but this didn't seem to work for the Form. I believe this is because, while `Box.Focus()` calls the callback, `Form.Focus()` does not. Would it be possible/advisable to call the callback in the form before passing the focus to the FormItem? After all, `Form.HasFocus()` returns true if any of its items have focus, so it might make sense for the callback to be called too. But I don't know what the implications of this are, or whether Blur() would be called properly as well.
Author
Owner

@carpii commented on GitHub (Aug 25, 2023):

Facing a similar issue with flex too #870

I'll keep mine open for now, just because it contains some sample code to repro

<!-- gh-comment-id:1693843111 --> @carpii commented on GitHub (Aug 25, 2023): Facing a similar issue with flex too #870 I'll keep mine open for now, just because it contains some sample code to repro
Author
Owner

@rivo commented on GitHub (Aug 28, 2025):

With the latest commit, the "focus" and "blur" notifications are now invoked for all primitives along the hierarchy (see SetFocusFunc and SetBlurFunc for details). Please have a look and let me know if this solves your problem.

<!-- gh-comment-id:3233169050 --> @rivo commented on GitHub (Aug 28, 2025): With the latest commit, the "focus" and "blur" notifications are now invoked for all primitives along the hierarchy (see [`SetFocusFunc`](https://github.com/rivo/tview/blob/f9502cf99cec5166dc89e09faab8ef73c18d1e97/box.go#L453) and [`SetBlurFunc`](https://github.com/rivo/tview/blob/f9502cf99cec5166dc89e09faab8ef73c18d1e97/box.go#L470) for details). Please have a look and let me know if this solves your problem.
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#631
No description provided.