[GH-ISSUE #115] Dropdowns -- selected func called twice #90

Closed
opened 2026-03-04 01:01:50 +03:00 by kerem · 3 comments
Owner

Originally created by @hoop33 on GitHub (May 11, 2018).
Original GitHub issue: https://github.com/rivo/tview/issues/115

When you select an item in the dropdown, the selected func runs twice. First, the wrapped list runs it:

https://github.com/rivo/tview/blob/master/list.go#L301

And then the dropdown handler runs it:

https://github.com/rivo/tview/blob/master/dropdown.go#L365

I would guess that deferring to the list's call would be fine, and that the dropdown's "Trigger selected event" block could be removed. I can submit a PR.

Thanks for this library!

Originally created by @hoop33 on GitHub (May 11, 2018). Original GitHub issue: https://github.com/rivo/tview/issues/115 When you select an item in the dropdown, the `selected` func runs twice. First, the wrapped `list` runs it: https://github.com/rivo/tview/blob/master/list.go#L301 And then the `dropdown` handler runs it: https://github.com/rivo/tview/blob/master/dropdown.go#L365 I would guess that deferring to the list's call would be fine, and that the dropdown's "Trigger selected event" block could be removed. I can submit a PR. Thanks for this library!
kerem closed this issue 2026-03-04 01:01:51 +03:00
Author
Owner

@hoop33 commented on GitHub (May 11, 2018):

Actually, removing the call from dropdown would cause an issue if the selected func changes focus -- the call from list would change the focus, and then dropdown changes it back ( https://github.com/rivo/tview/blob/master/dropdown.go#L360 ), so it looks like the fix isn't simply to remove that call.

<!-- gh-comment-id:388411530 --> @hoop33 commented on GitHub (May 11, 2018): Actually, removing the call from `dropdown` would cause an issue if the `selected` func changes focus -- the call from `list` would change the focus, and then `dropdown` changes it back ( https://github.com/rivo/tview/blob/master/dropdown.go#L360 ), so it looks like the fix isn't simply to remove that call.
Author
Owner

@rivo commented on GitHub (May 12, 2018):

Thank you for spotting this. I actually removed the per-item List callback to resolve this. I couldn't find any issue with this solution but if this doesn't work for you, let me know.

<!-- gh-comment-id:388559396 --> @rivo commented on GitHub (May 12, 2018): Thank you for spotting this. I actually removed the per-item `List` callback to resolve this. I couldn't find any issue with this solution but if this doesn't work for you, let me know.
Author
Owner

@hoop33 commented on GitHub (May 14, 2018):

Ah -- much cleaner solution. Thanks!

<!-- gh-comment-id:388905979 --> @hoop33 commented on GitHub (May 14, 2018): Ah -- much cleaner solution. Thanks!
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#90
No description provided.