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

[react-events] usePress from useKeyboard and useTap #16772

Merged
Merged
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
4 changes: 2 additions & 2 deletions packages/react-ui/accessibility/src/FocusGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
* @flow
*/

import type {KeyboardEvent} from 'react-ui/events/src/dom/Keyboard';
import type {KeyboardEvent} from 'react-ui/events/keyboard';

import React from 'react';
import {tabFocusableImpl} from './TabbableScope';
import {useKeyboard} from '../../events/keyboard';
import {useKeyboard} from 'react-ui/events/keyboard';

type GridComponentProps = {
children: React.Node,
Expand Down
5 changes: 3 additions & 2 deletions packages/react-ui/accessibility/src/ReactTabFocus.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@
*/

import type {ReactScopeMethods} from 'shared/ReactTypes';
import type {KeyboardEvent} from 'react-ui/events/src/dom/Keyboard';
import type {KeyboardEvent} from 'react-ui/events/keyboard';

import React from 'react';
import {TabbableScope} from './TabbableScope';
import {useKeyboard} from '../../events/keyboard';
import {useKeyboard} from 'react-ui/events/keyboard';

type TabFocusControllerProps = {
children: React.Node,
contain?: boolean,
};

const {useRef} = React;

function getTabbableNodes(scope: ReactScopeMethods) {
Expand Down
12 changes: 12 additions & 0 deletions packages/react-ui/events/press-legacy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

'use strict';

module.exports = require('./src/dom/PressLegacy');
11 changes: 7 additions & 4 deletions packages/react-ui/events/src/dom/Keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type KeyboardProps = {|
onClick?: (e: KeyboardEvent) => ?boolean,
onKeyDown?: (e: KeyboardEvent) => ?boolean,
onKeyUp?: (e: KeyboardEvent) => ?boolean,
preventClick?: boolean,
preventKeys?: PreventKeysArray,
|};

Expand Down Expand Up @@ -256,6 +257,12 @@ const keyboardResponderImpl = {
);
}
} else if (type === 'click' && isVirtualClick(event)) {
if (props.preventClick !== false) {
// 'click' occurs before or after 'keyup', and may need native
// behavior prevented
nativeEvent.preventDefault();
state.defaultPrevented = true;
}
const onClick = props.onClick;
if (onClick != null) {
dispatchKeyboardEvent(
Expand All @@ -266,10 +273,6 @@ const keyboardResponderImpl = {
state.defaultPrevented,
);
}
if (state.defaultPrevented && !nativeEvent.defaultPrevented) {
// 'click' occurs before 'keyup' and may need native behavior prevented
nativeEvent.preventDefault();
}
} else if (type === 'keyup') {
state.isActive = false;
const onKeyUp = props.onKeyUp;
Expand Down
Loading