GeezerVison is showing github.com — Merge branch 'master' into devtools-v4-merge · react/react@33d439f
File treeExpand file treeCollapse file tree Open diff view settings packages/react-events/src/dom
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/react-events/src/dom/Press.js +20Lines changed: 20 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -476,6 +476,19 @@ function handleStopPropagation( | 476 | 476 | } | 477 | 477 | } | 478 | 478 |
| | 479 | +// After some investigation work, screen reader virtual | | 480 | +// clicks (NVDA, Jaws, VoiceOver) do not have co-ords associated with the click | | 481 | +// event and "detail" is always 0 (where normal clicks are > 0) | | 482 | +function isScreenReaderVirtualClick(nativeEvent): boolean { | | 483 | + return ( | | 484 | + nativeEvent.detail === 0 && | | 485 | + nativeEvent.screenX === 0 && | | 486 | + nativeEvent.screenY === 0 && | | 487 | + nativeEvent.clientX === 0 && | | 488 | + nativeEvent.clientY === 0 | | 489 | + ); | | 490 | +} | | 491 | + | 479 | 492 | function targetIsDocument(target: null | Node): boolean { | 480 | 493 | // When target is null, it is the root | 481 | 494 | return target === null || target.nodeType === 9; | @@ -617,6 +630,13 @@ const pressResponderImpl = { | 617 | 630 | if (state.shouldPreventClick) { | 618 | 631 | nativeEvent.preventDefault(); | 619 | 632 | } | | 633 | + const onPress = props.onPress; | | 634 | + | | 635 | + if (isFunction(onPress) && isScreenReaderVirtualClick(nativeEvent)) { | | 636 | + state.pointerType = 'keyboard'; | | 637 | + state.pressTarget = event.responderTarget; | | 638 | + dispatchEvent(event, onPress, context, state, 'press', DiscreteEvent); | | 639 | + } | 620 | 640 | break; | 621 | 641 | } | 622 | 642 | } | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-events/src/dom/__tests__/Press-test.internal.js +12Lines changed: 12 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -420,6 +420,18 @@ describe.each(environmentTable)('Press responder', hasPointerEvents => { | 420 | 420 | innerTarget.pointerup({pointerType: 'mouse'}); | 421 | 421 | expect(onPress).toBeCalled(); | 422 | 422 | }); | | 423 | + | | 424 | + it('is called once after virtual screen reader "click" event', () => { | | 425 | + const target = createEventTarget(ref.current); | | 426 | + target.virtualclick(); | | 427 | + expect(onPress).toHaveBeenCalledTimes(1); | | 428 | + expect(onPress).toHaveBeenCalledWith( | | 429 | + expect.objectContaining({ | | 430 | + pointerType: 'keyboard', | | 431 | + type: 'press', | | 432 | + }), | | 433 | + ); | | 434 | + }); | 423 | 435 | }); | 424 | 436 |
| 425 | 437 | describe('onPressMove', () => { | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-events/src/dom/testing-library/domEvents.js +17-11Lines changed: 17 additions & 11 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -170,28 +170,30 @@ function createMouseEvent( | 170 | 170 | x = 0, | 171 | 171 | y = 0, | 172 | 172 | } = {}, | | 173 | + virtual = false, | 173 | 174 | ) { | 174 | 175 | const modifierState = {altKey, ctrlKey, metaKey, shiftKey}; | 175 | 176 |
| 176 | 177 | return createEvent(type, { | 177 | 178 | altKey, | 178 | 179 | buttons, | 179 | | - clientX: x, | 180 | | - clientY: y, | | 180 | + clientX: virtual ? 0 : x, | | 181 | + clientY: virtual ? 0 : y, | 181 | 182 | ctrlKey, | | 183 | + detail: virtual ? 0 : 1, | 182 | 184 | getModifierState(keyArg) { | 183 | 185 | createGetModifierState(keyArg, modifierState); | 184 | 186 | }, | 185 | 187 | metaKey, | 186 | | - movementX, | 187 | | - movementY, | 188 | | - offsetX, | 189 | | - offsetY, | 190 | | - pageX: pageX || x, | 191 | | - pageY: pageY || y, | | 188 | + movementX: virtual ? 0 : movementX, | | 189 | + movementY: virtual ? 0 : movementY, | | 190 | + offsetX: virtual ? 0 : offsetX, | | 191 | + offsetY: virtual ? 0 : offsetY, | | 192 | + pageX: virtual ? 0 : pageX || x, | | 193 | + pageY: virtual ? 0 : pageY || y, | 192 | 194 | preventDefault, | 193 | | - screenX: x, | 194 | | - screenY: y + defaultBrowserChromeSize, | | 195 | + screenX: virtual ? 0 : x, | | 196 | + screenY: virtual ? 0 : y + defaultBrowserChromeSize, | 195 | 197 | shiftKey, | 196 | 198 | }); | 197 | 199 | } | @@ -251,7 +253,11 @@ export function blur({relatedTarget} = {}) { | 251 | 253 | } | 252 | 254 |
| 253 | 255 | export function click(payload) { | 254 | | - return createMouseEvent('click', payload); | | 256 | + return createMouseEvent('click', payload, false); | | 257 | +} | | 258 | + | | 259 | +export function virtualclick(payload) { | | 260 | + return createMouseEvent('click', payload, true); | 255 | 261 | } | 256 | 262 |
| 257 | 263 | export function contextmenu(payload) { | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-events/src/dom/testing-library/index.js +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -44,6 +44,9 @@ const createEventTarget = node => ({ | 44 | 44 | keyup(payload) { | 45 | 45 | node.dispatchEvent(domEvents.keyup(payload)); | 46 | 46 | }, | | 47 | + virtualclick(payload) { | | 48 | + node.dispatchEvent(domEvents.virtualclick(payload)); | | 49 | + }, | 47 | 50 | scroll(payload) { | 48 | 51 | node.dispatchEvent(domEvents.scroll(payload)); | 49 | 52 | }, | |
|