Skip to content

fix(flyout): Close flyout when placement target unloads - #26648

Open
christo-polydorou wants to merge 1 commit into
unoplatform:masterfrom
christo-polydorou:fix/flyout-close-on-target-unloaded
Open

christo-polydorou wants to merge 1 commit into
unoplatform:masterfrom
christo-polydorou:fix/flyout-close-on-target-unloaded

Conversation

@christo-polydorou

Copy link
Copy Markdown
Contributor

GitHub Issue: closes #26398

PR Type:

🐞 Bugfix

What changed? 🚀

If a flyout's placement target was removed from the tree while the flyout was open, the flyout just stayed open: IsOpen stayed true, the popup was still there, and Closing/Closed never fired. On WinUI it closes.

This does what WinUI does in FlyoutBase::SetPlacementTarget: while the flyout is open, it listens to the target's Unloaded and calls Hide(). The handler is attached and detached in the same places as the existing ActualThemeChanged one, so nothing is kept alive after the flyout closes. Closing can still be cancelled, same as WinUI.

This is a bit different from what I described in my comment on the issue. I dropped the IsOpen check in the handler. It turned out to cause a bug: if the target is removed during Opening, IsOpen isn't set yet, so the flyout would open on a detached target. I also dropped the "detach before attach" step, since Hide() and the Target setter already take care of it.

Tests added to Given_Flyout:

  • When_Target_Removed_While_Open_Closes
  • When_Target_Removed_During_Opening_Does_Not_Open
  • When_Target_Removed_After_Closed_No_Extra_Events
  • When_Previous_Target_Removed_After_Reshown_Stays_Open

I ran Given_Flyout, Given_MenuFlyout and Given_CommandBarFlyout on Skia desktop (macOS) and everything passes. The first two new tests fail without the fix. I haven't run anything on WASM or WinUI.

One thing I wasn't able to check: Uno raises Unloaded right away, so removing and re-adding the target in the same tick will close the flyout. I'm not sure whether WinUI does the same.

#26399 and #26400 are related, but they need WinUI's staged flyout logic, so I'll do those in separate PRs.

PR Checklist ✅

Mirror WinUI's FlyoutBase::SetPlacementTarget: while open, subscribe to
the placement target's Unloaded and call Hide() from it. The handler is
attached next to ActualThemeChanged and detached in the same places, so
the target doesn't keep the flyout alive after it closes. Removing the
target during Opening cancels the open.

Fixes unoplatform#26398
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
1 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@mergify

mergify Bot commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue). If it does not match the queue conditions yet, it enters the queue once it does.

  • Queue this pull request once it meets the queue conditions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flyout stays open after its placement target is removed from the visual tree

1 participant