Skip to content

Commit

Permalink
fix: fix to ignore press event when button is disabled (#3056)
Browse files Browse the repository at this point in the history
  • Loading branch information
gs18004 authored Feb 10, 2025
1 parent 345d60d commit 37751df
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/framer-motion/src/gestures/__tests__/press.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -721,4 +721,19 @@ describe("press", () => {
0.5, 0.75, 1, 1, 1, 1, 1, 1, 1,
])
})

test("ignore press event when button is disabled", async () => {
const press = jest.fn()
const Component = () => <motion.button onTap={() => press()} disabled />

const { container, rerender } = render(<Component />)
rerender(<Component />)

pointerDown(container.firstChild as Element)
pointerUp(container.firstChild as Element)

await nextFrame()

expect(press).toBeCalledTimes(0)
})
})
4 changes: 4 additions & 0 deletions packages/framer-motion/src/gestures/press.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ function handlePressEvent(
) {
const { props } = node

if (node.current instanceof HTMLButtonElement && node.current.disabled) {
return
}

if (node.animationState && props.whileTap) {
node.animationState.setActive("whileTap", lifecycle === "Start")
}
Expand Down

0 comments on commit 37751df

Please sign in to comment.