Skip to content

[number field] Fix pen pointer handling - #3917

Merged
atomiks merged 2 commits into
mui:masterfrom
atomiks:atomiks/fix-issue-1528
Feb 12, 2026
Merged

atomiks merged 2 commits into
mui:masterfrom
atomiks:atomiks/fix-issue-1528

Conversation

@atomiks

@atomiks atomiks commented Feb 1, 2026

Copy link
Copy Markdown
Contributor

Fixes #1528. Linux Chrome has (had?) a bug where "pen" was emitted for mouse usage

@atomiks atomiks added component: number field Changes related to the number field component. type: bug It doesn't behave as expected. labels Feb 1, 2026
@pkg-pr-new

pkg-pr-new Bot commented Feb 1, 2026 •

Copy link
Copy Markdown
  • base-ui-tanstack-start

  • vite-css-base-ui-example

    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/react@3917
    
    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/utils@3917
    

commit: bba26e4

@mui-bot

mui-bot commented Feb 1, 2026 •

Copy link
Copy Markdown

Bundle size report

Bundle Parsed size Gzip size
@base-ui/react 🔺+23B(+0.01%) 🔺+31B(+0.02%)

Details of bundle changes


Check out the code infra dashboard for more information about this PR.

@netlify

netlify Bot commented Feb 1, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit bba26e4
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/698dabe546e1d80008e31f5d
😎 Deploy Preview https://deploy-preview-3917--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@atomiks
atomiks marked this pull request as ready for review February 1, 2026 19:35
@greptile-apps

greptile-apps Bot commented Feb 1, 2026

Copy link
Copy Markdown
Contributor

Greptile Overview

Greptile Summary

This 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 "pen" for mouse usage, but all pen inputs were being treated uniformly.

The fix introduces an isTouchPointerType() helper that treats pen as touch-like only on mobile platforms (isIOS or isAndroid), while treating it as mouse-like on desktop platforms. This prevents issues where pen input on Linux Chrome was incorrectly handled, and ensures that stylus taps on mobile devices don't inappropriately focus the input and trigger the software keyboard.

The helper is consistently applied across all pointer event handlers (onClick, onPointerDown, onPointerUp, onPointerMove, and onMouseEnter) to ensure uniform behavior.

  • Fixed Linux Chrome bug where pen pointer type was reported for mouse usage
  • Prevents mobile stylus taps from focusing input and showing keyboard
  • Added platform-aware isTouchPointerType() helper function
  • Note: The scrub area component doesn't have similar pen handling and may need consistent treatment

Confidence Score: 5/5

  • This PR is safe to merge - it's a focused bug fix with clear platform-specific logic
  • The change is well-contained, addresses a specific browser bug, uses proper platform detection utilities, and maintains consistent behavior across all pointer event handlers
  • No files require special attention

Important Files Changed

Filename Overview
packages/react/src/number-field/root/useNumberFieldButton.ts Added isTouchPointerType helper to correctly handle pen pointer type on mobile vs desktop platforms

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment on lines +58 to +60
function isTouchPointerType(pointerType: string) {
return pointerType === 'touch' || (pointerType === 'pen' && (isIOS || isAndroid));
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

@atomiks atomiks Feb 11, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@michaldudak michaldudak left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I verified it with iPad + Apple Pencil, both standalone and when used as a secondary screen connected to a MacBook.

@atomiks
atomiks force-pushed the atomiks/fix-issue-1528 branch from cec5877 to 6df1517 Compare February 12, 2026 02:49
@atomiks
atomiks merged commit 1849d05 into mui:master Feb 12, 2026
7 checks passed
@atomiks
atomiks deleted the atomiks/fix-issue-1528 branch February 12, 2026 10:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: number field Changes related to the number field component. type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[number field] Increment/decrement buttons toggle virtual keyboard when pressed with stylus

4 participants