Skip to content

Conversation

@johannesmutter
Copy link
Collaborator

So after trying like two dozen different techniques I finally found a solution that works well in Chromium (Android) and semi-ok in Safari. In Safari there are temporary placment issues of the toolbar when the viewport shifts (the user scrolls, but the browser doesn't actually scroll the page, but instead moves the visual viewport up / down until the "edge" is reached" ... hard to explain in words … but it's a known issue and there are several bug reports for Safari. The solution for chromium is just a line of css and an additional meta viewport tag attribute.

@michael
Copy link
Owner

michael commented Oct 19, 2024

Is the updateViewport() method there only to tame Safari? Or is that also needed for Chrome?

I think we should forget about Safari for now, and tackle cross-browser compatibility in a separate development round, and re-evaluate based on the timing. If the timing is early, we may drop CSS anchor positioning if we want to target both browsers (to avoid two implementation paths). Or we sit it out, and wait till CSS Anchor Positioning is supported in Safari as well.

It's good however we have a potential solution for handling virtual keyboard placement, so we should keep this PR around for reference.

Could you maybe make another PR that only includes the minimum amount of code to make this work in Chrome/Android (without the safari workarounds)?

I'll try to get myself an Android phone for testing our mobile solution. Can't do any tests atm.

@michael
Copy link
Owner

michael commented Oct 19, 2024

FYI: The clipboard solution currently also only supports Chrome. I know about a workaround for Safari, but wanted to keep things minimal for now.

@johannesmutter
Copy link
Collaborator Author

johannesmutter commented Oct 19, 2024

Yes the updateViewport() method is only needed for Safari, though I haven't tested with Android either. I can borrow an Android Phone later today, so I can check and then create a separate minimal version that targets Chrone only.

@johannesmutter
Copy link
Collaborator Author

johannesmutter commented Oct 19, 2024

This image sums up the issue:
Left iOS Safari, right chromium on Android

in chromium the visible viewport resizes, in Safari it stays the same.
So elements with position fixed and bottom will be hidden by the soft keyboard
CleanShot 2024-10-19 at 11 53 53@2x

@johannesmutter
Copy link
Collaborator Author

johannesmutter commented Oct 19, 2024

The additional problem on iOS is that if the focused input is either too low or too high, it will offset the viewport

Source: From this video

CleanShot 2024-10-19 at 11 56 26@2x
CleanShot 2024-10-19 at 11 56 48@2x

@johannesmutter
Copy link
Collaborator Author

johannesmutter commented Oct 19, 2024

How does everyone else solve this?

Seems they don't …

For example Notion/ Fibery/ LinkedIn/ ... have their toolbar fixed over the keyboard in their native apps, but floating somewhere on the screen near the selection in their web apps.

This works for them since the blocks one select here are usually just a single line of text, and not a block that spans multiple rows/ an area beyond the visible screen. But it's also create the terrible UX where you have both the native text actions visible (copy/paste/…) and the custom floating toolbar ... so not really a great experience on the web in these apps ...

CleanShot 2024-10-19 at 13 04 28@2x

Notion Web Notion Native LinkedIn
image image image

@johannesmutter
Copy link
Collaborator Author

johannesmutter commented Oct 19, 2024

Another insight: regardless of the placement of the toolbar we need to manually control wether the virtual keyboard should be shown or hidden, otherwise click on any tool will cause the keyboard to disappear (toolbar moves) as the focus is no longer on a "text" node.

There's a new API for this:
VirtualKeyboard: show() and hid() method
(No support on Safari yet).

RPReplay_Final1729337411.MP4

@michael
Copy link
Owner

michael commented Oct 19, 2024

We may be able to keep the selection when clicking the tools, if we use preventdefault. However, we need to careful that this doesn’t mess with other behavior.

@johannesmutter
Copy link
Collaborator Author

These properties may help with the iOS context menu appearing for text selections:

    -webkit-user-select: none;
    -webkit-touch-callout: none;

Repository owner deleted a comment from vercel bot Nov 11, 2024
@michael michael closed this Sep 24, 2025
@johannesmutter
Copy link
Collaborator Author

Just cleaning up? As the problem still persists.

The proposed solution in this PR with env(safe-area-inset-top) may now be better supported in Safari on iOS 26. Haven't updated myself yet.

@michael
Copy link
Owner

michael commented Sep 24, 2025

Sorry, will reopen it. Just thought that we need generally a different approach to this.

@michael michael reopened this Sep 24, 2025
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.

3 participants