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

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
Copy link
Owner

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
Copy link
Contributor Author

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
Copy link
Owner

clauderic 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 configure-keycodes branch 2 times, most recently from f36aa21 to 6c2b218 Compare August 22, 2019 17:13
@pimterry
Copy link
Contributor Author

Sure, that works nicely, done 👍

Copy link
Owner

@clauderic clauderic left a comment

Choose a reason for hiding this comment

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

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
Copy link
Contributor Author

@clauderic all fixed up 👍

Copy link
Owner

@clauderic clauderic left a comment

Choose a reason for hiding this comment

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

Beautiful, will include this in the next release 👍

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

Released in 1.10.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make key to start dragging configurable
2 participants