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

Add prop onSortOver on SortableContainer #278

Merged
merged 7 commits into from May 17, 2018

Conversation

SamyPesse
Copy link
Contributor

@SamyPesse SamyPesse commented Sep 21, 2017

This PR adds a prop onSortOver. The goal of this prop is for the parent component to be notified when the user is dragging over another item before it drops it.

It follows the convention of the other props: named as onSortX with same named arguments.

Example:

Let's say we want to show an alert message at the bottom of the page if we are hovering a specific item:

onSortOver = ({ newIndex, oldIndex }) => {
  const { items } = this.state;
  const item = newIndex != null ? items[newIndex] : null;

  this.setState({
    showAlert: item && item.someProperty
  });
});

render() {
   return (
       <div>
           <SortableList
               items={this.state.items}
               onSortEnd={this.onSortEnd}
               onSortOver={this.onSortOver}
           />
           {this.state.showAlert && <div>Some message !</div>}
       </div>
   );
}

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.

This is great, thanks for contributing 🙏

Sorry for the late review 😅

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.

None yet

2 participants