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

feat: Add activationKeyCodes to configure the keyboard shortcuts #588

Merged
merged 1 commit into from Aug 22, 2019

Conversation

@pimterry
Copy link
Contributor

commented Aug 22, 2019

Fixes #584: you can now set activationKeyCodes on the sortable container as an array of the keycodes which should be used to activate/deactivate sorting.

By default it's [32] (just space, as before) and I've tested it working in my app with [32, 13] (space and enter).

@clauderic

This comment has been minimized.

Copy link
Owner

commented Aug 22, 2019

What do you think of taking a more holistic approach and making all of the keycodes configurable?

Something like:

<SortableContainer 
  keyCodes={{
    lift: [32],
    drop: [32],
    cancel: [27],
    up: [38],
    down: [40],
  }}
/>
@pimterry

This comment has been minimized.

Copy link
Contributor Author

commented Aug 22, 2019

It's interesting, I can definitely see the argument for providing more control. Doing it with one object doesn't play nicely with defaultProps though afaik; you'd have to either use the default set of keys, or redefine all of them, which is a bit awkward. Is there an easy way around that?

@clauderic

This comment has been minimized.

Copy link
Owner

commented Aug 22, 2019

Something like this should probably do the trick:

const defaultKeyCodes = {
  lift: [32],
  drop: [32],
  cancel: [27],
  up: [38],
  down: [40],
};

const {keyCodes: customKeyCodes = {}} = this.props;
const keyCodes = {
   ...defaultKeyCodes,
   ...customKeyCodes,
};

@pimterry pimterry force-pushed the pimterry:configure-keycodes branch 2 times, most recently from f36aa21 to 6c2b218 Aug 22, 2019

@pimterry

This comment has been minimized.

Copy link
Contributor Author

commented Aug 22, 2019

Sure, that works nicely, done 👍

@clauderic
Copy link
Owner

left a comment

Looks great, just two minor nitpicks then good to go 👍

types/index.d.ts Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved

@pimterry pimterry force-pushed the pimterry:configure-keycodes branch from 6c2b218 to 7bb73bf Aug 22, 2019

@pimterry

This comment has been minimized.

Copy link
Contributor Author

commented Aug 22, 2019

@clauderic all fixed up 👍

@clauderic
Copy link
Owner

left a comment

Beautiful, will include this in the next release 👍

@clauderic clauderic merged commit 4c6d8dd into clauderic:master Aug 22, 2019

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
@clauderic

This comment has been minimized.

Copy link
Owner

commented Aug 22, 2019

Released in 1.10.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.