Skip to content

Commit

Permalink
fix: number input pointer event
Browse files Browse the repository at this point in the history
  • Loading branch information
segunadebayo committed Sep 19, 2022
1 parent ab1c42f commit ef722ca
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
8 changes: 8 additions & 0 deletions .changeset/tiny-olives-cheer.md
@@ -0,0 +1,8 @@
---
"@chakra-ui/number-input": patch
---

Fix issue where input spins unexpectedly on right clicking the increment or
decrement button with a pointer.

Now, only left click (or primary button) will trigger a value change.
6 changes: 4 additions & 2 deletions packages/components/number-input/src/use-number-input.ts
Expand Up @@ -465,7 +465,8 @@ export function useNumberInput(props: UseNumberInputProps = {}) {
role: "button",
tabIndex: -1,
onPointerDown: callAllHandlers(props.onPointerDown, (event) => {
if (!disabled) spinUp(event)
if (event.button !== 0 || disabled) return
spinUp(event)
}),
onPointerLeave: callAllHandlers(props.onPointerLeave, spinner.stop),
onPointerUp: callAllHandlers(props.onPointerUp, spinner.stop),
Expand All @@ -485,7 +486,8 @@ export function useNumberInput(props: UseNumberInputProps = {}) {
role: "button",
tabIndex: -1,
onPointerDown: callAllHandlers(props.onPointerDown, (event) => {
if (!disabled) spinDown(event)
if (event.button !== 0 || disabled) return
spinDown(event)
}),
onPointerLeave: callAllHandlers(props.onPointerLeave, spinner.stop),
onPointerUp: callAllHandlers(props.onPointerUp, spinner.stop),
Expand Down

1 comment on commit ef722ca

@vercel
Copy link

@vercel vercel bot commented on ef722ca Sep 19, 2022

Choose a reason for hiding this comment

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

Please sign in to comment.