Skip to content

VirtualKeyboard API #16

Open
Open

Description

@bramus

Activity

  1. othermaciej commented on Jun 29, 2022

    @othermaciej
  2. added
    topic: editing
    topic: device apis
    topic: web apis
    on Jun 29, 2022
  3. bramus commented on Jun 29, 2022

    @bramus
    Author
  4. litherum commented on Jun 30, 2022

    @litherum

    I have concerns about navigator.virtualKeyboard.show() for 2 reasons:

    1. User confusion. If the keyboard randomly appears, that would/could be very disconcerting for a user. Even if this was guarded by user gesture, there are plenty of use gestures which have nothing to do with text entry.
    2. Currently when we show the keyboard, we have a reason for doing so, and a context that the keyboard is meant for. We can show different keyboards depending on which input element triggered the keyboard to appear. We can scroll the triggering element into view. If script has the ability to show the keyboard for any reason, we lose this context.
  5. tomayac commented on Jun 30, 2022

    @tomayac

    FWIW, the inability to control how the virtual keyboard appears was brought up as a top pain point by Telegram in a technical post on WebKit issues:

    2. Text Field.

    Safari automatically scrolls the page after tapping a text field, in order to center it – completely ignoring the interface layout. The devs have no way to tune or adjust it.

  6. othermaciej commented on Jun 30, 2022

    @othermaciej

    If scroll-to-center behavior is bad for their app, there's probably a much simpler feature that could meet that specific need - this API seems too complex to be the obvious way to address this problem.

  7. snianu commented on Jun 30, 2022

    @snianu
    1. User confusion. If the keyboard randomly appears, that would/could be very disconcerting for a user. Even if this was guarded by user gesture, there are plenty of use gestures which have nothing to do with text entry.
    2. Currently when we show the keyboard, we have a reason for doing so, and a context that the keyboard is meant for. We can show different keyboards depending on which input element triggered the keyboard to appear. We can scroll the triggering element into view. If script has the ability to show the keyboard for any reason, we lose this context.

    VK would only appear if the focus is inside an editable element and there is a sticky user activation. This API lets the web author control the show/hide behavior of the VK only when the virtualKeyboardPolicy is in manual mode. Default behavior is auto. The discussion in the TAG review thread has more details about the behavior of this API. Based on feedback from @rniwa & @whsieh, I thought we had positive support from Apple?

  8. whsieh commented on Jun 30, 2022

    @whsieh
    Member

    My understanding is that we will only allow web authors to programmatically show the keyboard using the Virtual Keyboard API in scenarios where authors are already capable of programmatically showing the keyboard by focusing an editable element.

    (At one point, I recall giving feedback during TPAC that show() and possibly also hide() should return a promise, that rejects if the UA prefers to not show the keyboard, for the reasons Myles noted earlier).

  9. liamdebeasi commented on Jun 30, 2022

    @liamdebeasi

    This API is something that would be very valuable for developers using Ionic. Our use case is ensuring that inputs that scroll on non-body elements are not covered by the keyboard.

    The default scroll-to-center behavior in Safari is not ideal because it causes other content to be shifted offscreen. We wrote a "scroll assist" utility to prevent the browser from shifting content off screen while ensuring that the input is not covered by the keyboard: https://github.com/ionic-team/ionic-framework/blob/main/core/src/utils/input-shims/hacks/scroll-assist.ts.

    Below is an example of the default behavior as well as the custom Ionic behavior:

    default Safari behavior custom Ionic behavior
    default-safari.mp4
    custom-ionic.mp4

    With the default behavior, observe that the header and part of the content are shifted offscreen. With the custom behavior, observe that neither the header nor the content is shifted offscreen.

    The downside of this custom approach is we need to estimate the height of the keyboard. This can cause inputs to still be hidden by particularly tall keyboards. It can also cause inputs to be scrolled more than they need to be.

    Being able to know a) the geometry of the keyboard and b) when the geometry of the keyboard changes would significantly improve the user experience of apps built with Ionic. We do not have a big need for programmatically showing/hiding the keyboard at the moment, but I do see how that functionality could be considered confusing by some.

    edit: We do also make use of the Virtual Viewport API to get a better idea of the keyboard geometry. Our main problem with that is the event fires after the keyboard is fully open. As a result, we have to wait ~500ms before we can scroll the input into view. This gives the impression of a slow/unresponsive application.

  10. brunostasse commented on Jul 1, 2022

    @brunostasse

    If scroll-to-center behavior is bad for their app, there's probably a much simpler feature that could meet that specific need - this API seems too complex to be the obvious way to address this problem.

    Apart from preventing the scroll-to-center and the layout viewport shrinking behaviours, which is useful in itself as shown by @liamdebeasi example, this API also provides information about the size of the virtual keyboard. It is provided both through the JS API, and through CSS environment variables (keyboard-inset-*).

    Such information is useful to properly scroll into view in-flow inputs as suggested above, but also for element which are supposed to be fixed right above the VK. This is very common in chat interfaces, where the text input is usually at the bottom of the viewport by default, and moves up with the keyboard as it opens. It is also common for note taking apps, where you often have a toolbar positioned right above the keyboard. Without this information, there is currently no way to produce these kind of interfaces.

    As pointed out above, it appears that in Chrome's implementation the ongeometrychange event might be fired too late (I haven't tested myself). It would indeed be much better for the event allowing to detect change in the geometry to be sent as the VK starts appearing, and not after it has fully appeared. This is what the specification seems to be recommending, so this might just be an implementation issue.

    The event is dispatched when the intersection of the VK and the document's viewport changes, e.g., in response to the VK being shown or hidden or the browser window being repositioned.

    Virtual Keyboard API specification

  11. added
    from: Microsoft
    on Sep 25, 2022
  12. added
    concerns: device independence
    on Mar 2, 2023
  13. 3 remaining items

  14. moved this from Needs position to Needs assignees in Standards Positions Review Backlogon Mar 27, 2023
  15. moved this from Needs assignees to Needs position in Standards Positions Review Backlogon Mar 27, 2023
  16. jamie-pate commented on Apr 18, 2023

    @jamie-pate

    This api would also be useful for webassembly projects that afaik currently have no supported way to control the virtual keyboard?

  17. HolgerJeromin commented on Apr 19, 2023

    @HolgerJeromin

    I want to prevent my own keyboard when there is a native keyboard.
    So having navigator.virtualKeyboard.boundingRect and the geometrychange event would be great for some use cases even without having show and hide.

  18. woody-li commented on Aug 7, 2024

    @woody-li
  19. user-0a commented on Jan 24, 2025

    @user-0a
  20. sandstrom commented on Oct 9, 2025

    @sandstrom
  21. ApoloApps commented on Jun 8, 2026

    @ApoloApps

    I was working in the https://github.com/JetBrains/compose-multiplatform for Web implementation of WindowInsets.ime and stumbled across this api. The web APIs are a mess of supported and unsupported and it makes implmentation of full canvas canvas almost impossible or just difficult to implement consistently across OSs and browsers. This API would greatly simplify the code in our side and make it more maintainable long-term. See weird workarounds). There are definitely valid usecases and I would like for the WebKit team to at least consider to implement it. Thanks!

  22. rniwa commented on Jun 8, 2026

    @rniwa
    Member
  23. ApoloApps commented on Jun 8, 2026

    @ApoloApps

    FWIW, developer.mozilla.org/en-US/docs/Web/API/VisualViewport does get updated when a software keyboard comes up.

    VisualViewport has some bugs that prevents the devs to get the correct viewport size (it is impossible to get the correct size of the full viewport including system bars, which makes canvas apps look weird) and it would introduce more problems than it solves (at least with the current shape of the API). Also, VisualViewport is resized when 2-pinch zooming and again another vector to take into account.
    Edit: and then fact that we need to get the actual values via workarounds just to get them, it makes a pretty bad DX :)

  24. cameronapak commented on Jul 24, 2026

    @cameronapak

    +1 I want this feature and am willing to be a sounding board for feedback

  25. TingPing commented on Nov 20, 2026

    @TingPing

    I've spent some time looking into real world usage of this and I'd like to propose implementing a subset of the API: drop show(), hide() and virtualkeyboardpolicy, and consider only the read-only geometry part: boundingRect, geometrychange, env(keyboard-inset-*) and overlaysContent.

    These seem like the most valuable portions of the API allowing sites to consistently know where the keyboard is.

    WebKit recently enabled interactive-widget (319118@main). With interactive-widget=resizes-content, the page resizes above the keyboard, and together with VisualViewport that covers the common layouts. It doesn't cover the cases where the keyboard doesn't resize the viewport, or where something else does:

    • overlays-content: nothing resizes, so the page can't tell what the keyboard covers.
    • Floating and split iPad keyboards: they don't resize the viewport.
    • Pinch-zoom and toolbar collapse: they change the visual viewport when no keyboard is open.
    • Timing: VisualViewport only updates after the keyboard animation ends.

    The keyboard's geometry answers all of these directly.

    If WebKit is open to this subset, I can prototype it.

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

Metadata

Metadata

Labels

concerns: device independencefrom: Microsofttopic: device apistopic: editingtopic: web apisvenue: W3C Web Editing WG

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions