Repository navigation
[number field] Fix pen pointer handling - #3917
Conversation
commit: |
Bundle size report
Check out the code infra dashboard for more information about this PR. |
✅ Deploy Preview for base-ui ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Greptile OverviewGreptile SummaryThis PR fixes pen pointer handling in number field buttons by distinguishing between desktop and mobile pen usage. Previously, pen pointer types were treated inconsistently - the code had a comment noting that Linux Chrome sometimes reports The fix introduces an The helper is consistently applied across all pointer event handlers (
Confidence Score: 5/5
Important Files Changed
|
| function isTouchPointerType(pointerType: string) { | ||
| return pointerType === 'touch' || (pointerType === 'pen' && (isIOS || isAndroid)); | ||
| } |
There was a problem hiding this comment.
Check that the scrub area component (NumberFieldScrubArea.tsx:267-273) has consistent pen pointer handling - it currently only checks for 'touch' and 'mouse'.
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/react/src/number-field/root/useNumberFieldButton.ts
Line: 58:60
Comment:
Check that the scrub area component (`NumberFieldScrubArea.tsx:267-273`) has consistent pen pointer handling - it currently only checks for `'touch'` and `'mouse'`.
How can I resolve this? If you propose a fix, please make it concise.| : 'decrement-press'; | ||
|
|
||
| // "pen" maps to mouse-like behavior on Linux Chrome, so only treat it as touch on mobile. | ||
| function isTouchPointerType(pointerType: string) { |
There was a problem hiding this comment.
Could this create issues with devices like Windows Surface when actually using a pen? Is neither ios nor android and it should return the pen pointer type as far as I know. From what I understand the intent is not to exclude the desktop stylus devices, right?
I don't have a device to test it, but it could be a common use-case.
Some better check if the above intent is correct is to specifically check for Linux + Chrome desktop:
const ua = navigator.userAgent;
const isChrome =
/Chrome/.test(ua) && !/Edg|OPR/.test(ua);
const isDesktopLinux =
/Linux/.test(ua) && !/Android/.test(ua);
const isChromeOnLinux = isChrome && isDesktopLinux;There was a problem hiding this comment.
The main logic to avoid here is focusing the input when pressing a stepper button. The problem is related to the software keyboard opening, which is why iOS/Android are directly targeted. Desktops don't have the software keyboard issue
There was a problem hiding this comment.
Desktops don't have the software keyboard issue
Windows Surface can be used as a tablet (without keyboard), in that use-case it has the virtual keyboard (the screen can be detached from the hardware keyboard).
There was a problem hiding this comment.
In general, if we know Linux + Chrome is the issue, let's be specific and add a comment with the known issue so we track what exactly was broken.
There was a problem hiding this comment.
I adjusted the approach here:
// Treat pen as touch-like to avoid forcing the software keyboard on stylus taps.
// Linux Chrome may emit "pen" historically for mouse usage due to a bug, but the touch path
// still works with minor behavioral differences.
function isTouchLikePointerType(pointerType: string) {
return pointerType === 'touch' || pointerType === 'pen';
}So pen and touch are considered the same path, and the input won't receive focus and open any virtual keyboards, no matter the device
cec5877 to
6df1517
Compare
Fixes #1528. Linux Chrome has (had?) a bug where
"pen"was emitted for mouse usage