fix: don't treat touch-screen laptops as virtual-keyboard devices#2289
Open
Koushik-Salammagari wants to merge 1 commit into
Open
Conversation
isVirtualKeyboard() returned true whenever "ontouchstart" was present on window, which is the case for touch-screen laptops too. Those devices were incorrectly given the mobile UI behaviour, breaking Enter-to-send and the related focus handling in ChatInput/ChatWindow. Detect on-screen-keyboard devices via the coarse primary pointer media query ((pointer: coarse)) instead. Phones and tablets report a coarse primary pointer, while touch laptops keep a fine primary pointer (mouse/trackpad) and are therefore no longer misclassified. The user agent check is retained as a fallback for browsers without pointer media queries. The decision logic is extracted into a pure detectVirtualKeyboard() helper so it can be unit-tested without browser globals. Closes huggingface#1767
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
isVirtualKeyboard()returnedtruewhenever"ontouchstart" in windowwas truthy. That check is satisfied by touch-screen laptops (Windows touch laptops, Chromebooks, etc.), not just phones and tablets. As a result those machines were given the mobile UI behaviour, which most visibly breaks Enter-to-send (the keydown handler inChatInput.sveltebails out whenisVirtualKeyboard()is true) and changes focus/spacing handling inChatWindow.svelte.Closes #1767.
Fix
Detect on-screen-keyboard devices via the coarse primary pointer media query (
(pointer: coarse)) instead of mere touch capability:The decision logic is extracted into a pure
detectVirtualKeyboard()helper that takes the device signals as input, so it can be unit-tested without browser globals.isVirtualKeyboard()remains the thin browser wrapper and its public signature is unchanged.Testing
src/lib/utils/isVirtualKeyboard.spec.tscovering phone (coarse pointer), touch-screen laptop (fine pointer + desktop UA), plain desktop, and the user-agent fallback path.npm run test(server workspace) passes.npm run lintandnpm run checkpass with no new errors.