Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update PointerEvent to have default pressure set to 0.5 #1262

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/event/createEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,13 +258,14 @@ function initPointerEvent(
twist,
pointerType,
isPrimary,
buttons,
}: PointerEventInit,
) {
assignProps(event, {
pointerId: sanitizeNumber(pointerId),
width: sanitizeNumber(width ?? 1),
height: sanitizeNumber(height ?? 1),
pressure: sanitizeNumber(pressure),
pressure: sanitizeNumber(pressure ?? (buttons ? 0.5 : 0)),
tangentialPressure: sanitizeNumber(tangentialPressure),
tiltX: sanitizeNumber(tiltX),
tiltY: sanitizeNumber(tiltY),
Expand Down
21 changes: 21 additions & 0 deletions tests/pointer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,3 +267,24 @@ test('suppress mouse events per preventDefault on pointerdown', async () => {
expect(eventWasFired('mousemove')).toBe(false)
expect(eventWasFired('mouseup')).toBe(false)
})

test('apply default event properties', async () => {
const {element, user, getEvents, clearEventCalls} = setup(`<div></div>`)

await user.pointer({target: element})

expect(getEvents('pointermove')[0]).toEqual(expect.objectContaining({
width: 1,
height: 1,
pressure: 0,
}))

clearEventCalls()
await user.pointer([{keys: '[MouseLeft>]'}, {coords: {x: 20}}])

expect(getEvents('pointermove')[0]).toEqual(expect.objectContaining({
width: 1,
height: 1,
pressure: 0.5,
}))
})