fyne icon indicating copy to clipboard operation
fyne copied to clipboard

[Regression] calling Hide() on a widget.PopUp does not call FocusLost() on focused widgets contained in it

Open dweymouth opened this issue 2 years ago • 4 comments

Checklist

  • [X] I have searched the issue tracker for open issues that relate to the same problem, before opening a new one.
  • [X] This issue only relates to a single bug. I will open new issues for any other problems.

Describe the bug

This applies to both modal and non-modal popups but only affects non-modal popups when they are programmatically hidden. (ie when hidden by a user tap elsewhere it has the correct behavior)

Note also that the widget IS actually unfocused. If you show the popup again the widget does not have focus, but its styling will still suggest that it does!

How to reproduce

Run the example code, show the popup, then hide it without focusing the entry. Show it again, and all is good. Now, focus the entry and hide the popup, and re-show it. The entry will appear focused without actually being focused. This is because its FocusLost isn't called when hiding the popup.

Screenshots

No response

Example code

package main

import (
	"log"

	"fyne.io/fyne/v2"
	"fyne.io/fyne/v2/app"
	"fyne.io/fyne/v2/container"
	"fyne.io/fyne/v2/widget"
)

type focusLostEntry struct {
	widget.Entry
}

func newFocusLostEntry() *focusLostEntry {
	e := &focusLostEntry{}
	e.ExtendBaseWidget(e)
	return e
}

func (e *focusLostEntry) FocusLost() {
	log.Println("Focus lost")
	e.Entry.FocusLost()
}

func main() {
	app := app.New()
	win := app.NewWindow("Popup FocusLost bug")

	var pop *widget.PopUp
	hide := widget.NewButton("Hide", func() {
		pop.Hide()
	})
	e := newFocusLostEntry()
	e.PlaceHolder = "Focus me"
	pop = widget.NewModalPopUp(container.NewVBox(
		widget.NewLabel("This is a modal popup"),
		e,
		hide,
	), win.Canvas())

	win.SetContent(container.NewBorder(
		widget.NewLabel("This is the main window content"), nil, nil, nil,
		container.NewCenter(widget.NewButton("Show", func() {
			pop.Show()
		})),
	))
	win.Resize(fyne.NewSize(400, 300))
	win.ShowAndRun()
}

Fyne version

2.4.1

Go compiler version

go1.21.1

Operating system and version

macOS Ventura M2

Additional Information

No response

dweymouth avatar Nov 06 '23 02:11 dweymouth

On further investigation this appears to be a regression from 2.3.5 -> 2.4.0

dweymouth avatar Nov 06 '23 04:11 dweymouth

Is this truly a blocker for v2.5.0, or is that tag just carried over from 2.4.x but it was not fixed when it should have been?

andydotxyz avatar Jul 07 '24 13:07 andydotxyz

I think it was just carried over. Would be nice to get a fix but I certainly don't think it's a blocker, it can be addressed in a bug fix release

dweymouth avatar Jul 07 '24 14:07 dweymouth

Thanks

andydotxyz avatar Jul 07 '24 21:07 andydotxyz