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] Adds preventKeys support to Keyboard responder #16642

Merged
merged 2 commits into from
Sep 4, 2019

Conversation

trueadm
Copy link
Contributor

@trueadm trueadm commented Sep 3, 2019

This PR adds the functionality to natively preventDefault on the Keyboard responder. This is done via a preventKeys prop, which takes an array of key strings that should be preventing during the keydown event; along with a defaultPrevented flag on the callback's event object.

@sizebot
Copy link

sizebot commented Sep 3, 2019

Details of bundled changes.

Comparing: 92f094d...56cb454

react-events

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-events-focus.development.js 0.0% -0.1% 10.9 KB 10.9 KB 2.35 KB 2.35 KB UMD_DEV
react-events-focus.production.min.js 0.0% -0.1% 4.08 KB 4.08 KB 1.38 KB 1.38 KB UMD_PROD
react-events-context-menu.development.js 0.0% -0.1% 2.67 KB 2.67 KB 1001 B 1000 B UMD_DEV
react-events-input.development.js 0.0% -0.1% 4.52 KB 4.52 KB 1.44 KB 1.44 KB UMD_DEV
react-events-context-menu.production.min.js 0.0% -0.1% 1.38 KB 1.38 KB 726 B 725 B UMD_PROD
react-events-input.production.min.js 0.0% -0.1% 1.82 KB 1.82 KB 973 B 972 B UMD_PROD
ReactEventsKeyboard-dev.js +29.8% +20.8% 4.19 KB 5.44 KB 1.57 KB 1.9 KB FB_WWW_DEV
react-events-swipe.production.min.js 0.0% -0.1% 2.43 KB 2.43 KB 1.1 KB 1.1 KB UMD_PROD
ReactEventsKeyboard-prod.js 🔺+27.7% 🔺+22.8% 3.26 KB 4.16 KB 1.15 KB 1.42 KB FB_WWW_PROD
react-events-context-menu.development.js 0.0% -0.1% 2.48 KB 2.48 KB 955 B 954 B NODE_DEV
react-events-input.development.js 0.0% -0.1% 4.33 KB 4.33 KB 1.39 KB 1.39 KB NODE_DEV
react-events-swipe.development.js 0.0% -0.1% 5.81 KB 5.81 KB 1.58 KB 1.58 KB NODE_DEV
react-events-context-menu.production.min.js 0.0% -0.3% 1.19 KB 1.19 KB 666 B 664 B NODE_PROD
react-events-input.production.min.js 0.0% -0.1% 1.64 KB 1.64 KB 907 B 906 B NODE_PROD
react-events-swipe.production.min.js 0.0% -0.1% 2.25 KB 2.25 KB 1.04 KB 1.04 KB NODE_PROD
react-events-hover.development.js 0.0% -0.1% 6.98 KB 6.98 KB 1.55 KB 1.55 KB UMD_DEV
react-events-scroll.development.js 0.0% -0.1% 6.29 KB 6.29 KB 1.65 KB 1.65 KB UMD_DEV
react-events-hover.production.min.js 0.0% -0.1% 3.1 KB 3.1 KB 1.13 KB 1.13 KB UMD_PROD
react-events-hover.development.js 0.0% -0.1% 6.8 KB 6.8 KB 1.5 KB 1.5 KB NODE_DEV
react-events-hover.production.min.js 0.0% -0.1% 2.92 KB 2.92 KB 1.07 KB 1.06 KB NODE_PROD
react-events-scroll.production.min.js 0.0% -0.1% 2.43 KB 2.43 KB 1.09 KB 1.09 KB NODE_PROD
react-events-focus.development.js 0.0% -0.1% 10.72 KB 10.72 KB 2.31 KB 2.31 KB NODE_DEV
react-events-focus.production.min.js 0.0% -0.1% 3.91 KB 3.91 KB 1.31 KB 1.31 KB NODE_PROD
react-events-press.production.min.js 0.0% -0.0% 6.87 KB 6.87 KB 2.58 KB 2.58 KB NODE_PROD
react-events-drag.development.js 0.0% -0.1% 5.21 KB 5.21 KB 1.54 KB 1.54 KB UMD_DEV
react-events-keyboard.development.js +26.5% +17.4% 4.3 KB 5.44 KB 1.64 KB 1.92 KB UMD_DEV
react-events-drag.production.min.js 0.0% -0.1% 2.24 KB 2.24 KB 1.07 KB 1.07 KB UMD_PROD
react-events-keyboard.production.min.js 🔺+18.7% 🔺+17.6% 1.87 KB 2.22 KB 1.01 KB 1.19 KB UMD_PROD
react-events-keyboard.development.js +27.7% +17.9% 4.11 KB 5.25 KB 1.59 KB 1.87 KB NODE_DEV
react-events-drag.production.min.js 0.0% -0.1% 2.87 KB 2.87 KB 1.37 KB 1.37 KB NODE_PROD
react-events-keyboard.production.min.js 🔺+20.8% 🔺+19.8% 1.69 KB 2.04 KB 961 B 1.12 KB NODE_PROD

Generated by 🚫 dangerJS against 56cb454

Copy link
Contributor

@necolas necolas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are situations where it might be necessary to preventDefault only if a modifier key is also held. We should check with Microsoft if there were specific use cases we can reference. Not sure what a nice way to support that could be, maybe:

useKeyboard({
  preventKeys: [
    'Space',
    // second element as "conditions" associated with the native event
    [ 'Enter', { metaKey: true } ]
    // or custom string combos if there is a limited subset of keys that this applies to
    'Enter+Meta'
  ]
});

packages/react-events/src/dom/Keyboard.js Outdated Show resolved Hide resolved
@trueadm trueadm merged commit af03276 into facebook:master Sep 4, 2019
@trueadm trueadm deleted the keyboard-preventing branch September 4, 2019 00:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants