Skip to content

Commit

Permalink
[react-events] Ensure screen reader virtual clicks support preventDef…
Browse files Browse the repository at this point in the history
…ault (#16600)
  • Loading branch information
trueadm authored Aug 28, 2019
1 parent 01fb68b commit 34aaec6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions packages/react-events/src/dom/Press.js
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,11 @@ const pressResponderImpl = {
if (isFunction(onPress) && isScreenReaderVirtualClick(nativeEvent)) {
state.pointerType = 'keyboard';
state.pressTarget = event.responderTarget;
const preventDefault = props.preventDefault;

if (preventDefault !== false) {
nativeEvent.preventDefault();
}
dispatchEvent(event, onPress, context, state, 'press', DiscreteEvent);
}
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,9 @@ describe.each(environmentTable)('Press responder', hasPointerEvents => {

it('is called once after virtual screen reader "click" event', () => {
const target = createEventTarget(ref.current);
target.virtualclick();
const preventDefault = jest.fn();
target.virtualclick({preventDefault});
expect(preventDefault).toBeCalled();
expect(onPress).toHaveBeenCalledTimes(1);
expect(onPress).toHaveBeenCalledWith(
expect.objectContaining({
Expand Down

0 comments on commit 34aaec6

Please sign in to comment.