Skip to content

Commit 341708e

Browse files
fix(pointer): use 0.5 as default value for PointerEvent.pressure (#1262)
Co-authored-by: Philipp Fritsche <[email protected]>
1 parent f8f8ff7 commit 341708e

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/event/createEvent.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -256,13 +256,14 @@ function initPointerEvent(
256256
twist,
257257
pointerType,
258258
isPrimary,
259+
buttons,
259260
}: PointerEventInit,
260261
) {
261262
assignProps(event, {
262263
pointerId: sanitizeNumber(pointerId),
263264
width: sanitizeNumber(width ?? 1),
264265
height: sanitizeNumber(height ?? 1),
265-
pressure: sanitizeNumber(pressure),
266+
pressure: sanitizeNumber(pressure ?? (buttons ? 0.5 : 0)),
266267
tangentialPressure: sanitizeNumber(tangentialPressure),
267268
tiltX: sanitizeNumber(tiltX),
268269
tiltY: sanitizeNumber(tiltY),

tests/pointer/index.ts

+21
Original file line numberDiff line numberDiff line change
@@ -267,3 +267,24 @@ test('suppress mouse events per preventDefault on pointerdown', async () => {
267267
expect(eventWasFired('mousemove')).toBe(false)
268268
expect(eventWasFired('mouseup')).toBe(false)
269269
})
270+
271+
test('apply default event properties', async () => {
272+
const {element, user, getEvents, clearEventCalls} = setup(`<div></div>`)
273+
274+
await user.pointer({target: element})
275+
276+
expect(getEvents('pointermove')[0]).toEqual(expect.objectContaining({
277+
width: 1,
278+
height: 1,
279+
pressure: 0,
280+
}))
281+
282+
clearEventCalls()
283+
await user.pointer([{keys: '[MouseLeft>]'}, {coords: {x: 20}}])
284+
285+
expect(getEvents('pointermove')[0]).toEqual(expect.objectContaining({
286+
width: 1,
287+
height: 1,
288+
pressure: 0.5,
289+
}))
290+
})

0 commit comments

Comments
 (0)