Skip to content

fix(wasm): Keep flyouts open when the soft keyboard resizes the layout - #26663

Open
mikernet wants to merge 2 commits into
unoplatform:masterfrom
mikernet:dev/mikernet/wasm-flyout-soft-keyboard
Open

mikernet wants to merge 2 commits into
unoplatform:masterfrom
mikernet:dev/mikernet/wasm-flyout-soft-keyboard

Conversation

@mikernet

Copy link
Copy Markdown
Contributor

GitHub Issue: closes #26662

PR Type:

🐞 Bugfix

What changed? 🚀

On Skia WebAssembly in a mobile browser, a flyout that focuses its TextBox when it opens can close as soon as the soft keyboard comes up. It was reported in Brave on an Android phone, with a DropDownButton in a ContentDialog whose flyout focuses a search box on Opened.

The report did not reproduce with Brave's default settings in an Android emulator: there the keyboard only shrinks the visual viewport, and nothing closes. This PR fixes the path where the height of the layout viewport changes around the keyboard. Forcing that with interactive-widget=resizes-content reproduces the report every time. The reporter confirmed the fix on their phone.

Cause: when the layout viewport's height changes around the keyboard, WebAssemblyWindowWrapper reports a window resize. XamlRoot.Changed → PopupRoot.CloseLightDismissablePopups closes the flyout, focus leaves the TextBox, and the keyboard hides. A browser changes that height in two ways:

  • it shrinks the layout viewport by the keyboard height (interactive-widget=resizes-content);
  • it hides and restores its bottom toolbar. Martin Zikmund measured this on a device in Edge (fix(wasm): Keep popups open when the soft keyboard hides #25387): when the keyboard hides with the TextBox still focused, the layout grows 793 → 845 → 793 px over about 130 ms.

In WinUI the touch keyboard never resizes the window: it occludes it, and InputPane reports that.

Fix (WebAssemblyWindowWrapper.ts). A touch text entry is a text input that has focus after a touch or pen press:

  • Held during a touch text entry: the window and canvas keep their size.
    • What is held: a shrink (it can be the keyboard), and a growth while the keyboard covers part of the layout (a toolbar hidden under the keyboard).
    • What the app sees: the part the keyboard covers is reported through InputPane.OccludedRect, measured against the window size.
    • When it ends: when the height comes back, when the width changes, 1 s after the text entry ends, or, for a growth, once it has settled after the keyboard went down with the TextBox still focused.
  • Settled during a touch text entry and for 1 s after it ends: any other growth is reported once it has lasted 300 ms. A toolbar that comes back sooner never resizes the window. This covers the Edge sequence above, whether the keyboard hid with the TextBox focused or because the focus moved out.
  • Reported at once, as before: everything else, including any change of width and any height change during a text entry started with a mouse (a desktop window resized, DevTools closed, an info bar going away while a TextBox has focus).
  • Pointer type: the window wrapper records it from startup, with a capture listener on the window. The TextBox extension used to record it only once its listener was installed with the first TextBox. In the report's layout, the first TextBox is the one in the flyout, so the tap that opened the flyout would not have been seen.
  • Canvas: BrowserRenderer sizes the canvas from the window size rather than from the layout viewport.

Behavior change: a page that opts into interactive-widget=resizes-content no longer has its window shrunk for the keyboard during a touch text entry. It gets the keyboard through InputPane (bring-into-view, flyouts placed above the keyboard), as on WinUI.

Relationship to #25387: that PR holds back height-only changes for 300 ms around a keyboard hide, which fixes the Edge blip in #25380. This PR uses its measurements but stands on its own:

  • it settles growths during and right after a touch text entry, which covers that blip;
  • it also holds the keyboard's own shrink of the layout viewport, and a toolbar hidden under the keyboard, which a settle delay would still report once they last.

Both change the same code and would conflict. This PR also moves the pointer type from BrowserInvisibleTextBoxViewExtension.lastPointerType to WebAssemblyWindowWrapper.isTouchInput(). #25185 adds a read of lastPointerType: the two merge cleanly in git but don't compile together, so whichever lands second needs that one line changed.

Validation:

  • Runtime (reporter's phone, Android 17, Brave 1.99.57): on a build with this fix, the flyout stays open when the keyboard comes up, on the page that showed the bug.
  • Runtime (Skia WASM, Chrome 157 desktop, Given_InputPane), seven new tests:
    • When_Browser_Keyboard_Shrinks_Layout_Viewport_Then_Flyout_Stays_Open: after a touch press, a keyboard that shrinks the layout viewport, then hides. The window never changes size and the flyout stays open.
    • When_Viewport_Blips_As_Soft_Keyboard_Hides_Then_Flyout_Stays_Open: fix(wasm): Keep popups open when the soft keyboard hides #25387's measured sequence. The keyboard comes up through the visual viewport and goes down, then the layout grows 52 px and comes back 150 ms later. The window never changes size and the flyout stays open.
    • When_Viewport_Blips_After_Focus_Moves_Out_Then_Flyout_Stays_Open: the same blip, after the focus moved to a button in the flyout.
    • When_Browser_Toolbar_Hides_Under_Keyboard_Then_Window_Keeps_Size: while the keyboard is up, the layout grows 52 px and stays grown. The window keeps its size and the flyout stays open; once the keyboard is down, the window takes the new height after the settle.
    • When_Viewport_Grows_During_Text_Entry_Then_Window_Resized_Once_Settled: a growth that lasts is not reported after 50 ms, and is reported once settled.
    • When_Text_Entry_Ends_With_Viewport_Still_Shrunk_Then_Window_Resized (synthetic): a held shrink is released once the text entry ends.
    • When_Browser_Layout_Height_Changes_During_Mouse_Text_Entry_Then_Window_Resized: during a mouse text entry, a shrink and a growth are both reported at once.
    • Results: 7/7 pass with the fix. Each mutation was confirmed in the served JS:
      • without the shrink hold and the growth settle: the shrink, release, both blip and growth tests fail;
      • without the growth hold under the keyboard: the toolbar test fails;
      • with the settle applied to any focused text input: the mouse test fails (its growth waits);
      • without the second after a touch text entry ends: the blip-after-focus test fails;
      • without the touch gate (round 2, same gate): the mouse test fails.
  • Runtime (Skia WASM, Chrome 157 desktop, wider): Given_InputPane, Given_Flyout, Given_Popup, Given_ContentDialog, Given_TextBox, Given_PasswordBox (480 tests): 437 passed, 11 failed, 32 inconclusive (skipped by platform or condition). Unmodified master with the same filter gives 473 tests, 430 passed, the same 11 failures and the same 32 skipped. The failures are Check_Placement_All_* rounding at 125% scaling, the When_DefaultButton_* colors, and the iOS-only When_Touch_LongPress_Drag_Release_Does_Not_Open_Flyout_iOS.
  • Runtime (Android 16 emulator, Brave 1.100.58 / Chromium 158.0.8127.42, new manual sample Windows.UI.ViewManagement/SoftKeyboardFocusedFlyout):
    • Before the fix (master), with interactive-widget=resizes-content: the layout shrank from 762 to 498 px, XamlRoot.Changed fired, the flyout closed and the keyboard hid. Same on the page and in a ContentDialog. Also reproduced on an Android 14 emulator.
    • After the fix, same setting: no XamlRoot.Changed, OccludedRect height 264. On the page and in the dialog, the flyout stays open above the keyboard and typing works. Back hides the keyboard with the TextBox still focused: no resize, flyout open. Tapping a list item hides the keyboard: no resize, flyout open.
    • Brave's defaults (visual viewport only): page and dialog behave as on master, with an occlusion of 312 px and no resize.
  • Compile: SamplesApp WASM (net11.0-browserwasm). The WinAppSDK build was not compiled; the sample's Uno-only XamlRoot.HostWindow is behind #if HAS_UNO (code review).
  • Code review only: the pointer type is recorded from startup by the window wrapper. No test isolates it: in the runtime tests and in SamplesApp, a TextBox already exists before the flyout opens.
  • Not covered:
    • Other real devices and browsers than the reporter's.
    • Brave's toolbar never changed the layout height on the emulators. The toolbar cases rest on fix(wasm): Keep popups open when the soft keyboard hides #25387's Edge measurements and are replayed in the runtime tests.
    • Some shrinks are still ambiguous during a touch text entry: a split-screen divider drag, or a window-edge drag right after a touch tap. They are held like a keyboard until the text entry ends (plus 1 s) or the width changes.

PR Checklist ✅

A manual sample for a phone browser: a DropDownButton flyout that focuses
its TextBox when it opens, on the page and inside a ContentDialog. It logs
the window activation, XamlRoot changes and InputPane occlusion, to show
what closes the flyout when the soft keyboard comes up.
Some browsers change the height of the layout viewport around the soft
keyboard: they shrink it by the keyboard height (resizes-content), or
hide and restore their bottom toolbar, which grows it while the
keyboard is up or briefly when it hides. That was reported as a window
resize, so XamlRoot.Changed light-dismissed the open popups: a flyout
focusing its TextBox on open closed as soon as the keyboard came up.

As in WinUI, the keyboard occludes the window instead. During a text
entry started by touch, a shrink and a growth under the keyboard are
held as InputPane occlusion, until the height comes back, the width
changes, the keyboard goes down or a second after the text entry ends.
Any other growth during or right after such a text entry is reported
once it has lasted 300 ms. A height change during text entry started
with a mouse is still reported at once.

The pointer type is recorded by the window from startup: the TextBox
extension only installs its listener with the first TextBox, which can
be the one in the flyout that the tap opened.
@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.

@github-actions github-actions Bot added platform/wasm 🌐 Categorizes an issue or PR as relevant to the WebAssembly platform area/automation Categorizes an issue or PR as relevant to project automation labels Nov 23, 2026
@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

area/automation Categorizes an issue or PR as relevant to project automation platform/wasm 🌐 Categorizes an issue or PR as relevant to the WebAssembly platform

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[WASM Skia] A flyout that focuses its TextBox on open closes when the browser resizes the layout for the soft keyboard

1 participant