Giter Site home page Giter Site logo

react-dragula's Introduction

logo.png

Drag and drop so simple it hurts

Official React wrapper for dragula.

Demo

demo.png

Try out the demo!

Install

You can get it on npm.

npm install react-dragula --save

Or bower, too.

bower install react-dragula --save

Usage

Refer to the documentation for dragula. The API for react-dragula is identical, but a few tiny tweaks were made around it so that it works out the box with React.

Example

Here's an example application using react and react-dragula.

var React = require('react');
var dragula = require('react-dragula');
var App = React.createClass({
  render: function () {
    return <div className='container'>
      <div>Swap me around</div>
      <div>Swap her around</div>
      <div>Swap him around</div>
      <div>Swap them around</div>
      <div>Swap us around</div>
      <div>Swap things around</div>
      <div>Swap everything around</div>
    </div>;
  },
  componentDidMount: function () {
    var container = React.findDOMNode(this);
    dragula([container]);
  }
});
React.render(<App />, document.getElementById('examples'));

Example using refs (ES2015 syntax)

Here's an example using refs (ES2015 syntax): React: The ref Callback Attribute

import * as React from "react";
import * as ReactDOM from 'react-dom';
import Dragula from 'react-dragula';
export class App extends React.Component {
  render () {
    return <div className='container' ref={this.dragulaDecorator}>
      <div>Swap me around</div>
      <div>Swap her around</div>
      <div>Swap him around</div>
      <div>Swap them around</div>
      <div>Swap us around</div>
      <div>Swap things around</div>
      <div>Swap everything around</div>
    </div>;
  },
  dragulaDecorator = (componentBackingInstance) => {
    if (componentBackingInstance) {
      let options = { };
      Dragula([componentBackingInstance], options);
    }
  };
});
ReactDOM.render(<App />, document.getElementById('examples'));

License

MIT

react-dragula's People

Contributors

bevacqua avatar piotrwitek avatar razh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-dragula's Issues

Features in the demo?

Why does the react-dragula demo only show a very basic example? Does react-dragula support the same features demonstrated in the AngularJS and Angular 2 demos?

document is not defined

I'm getting this error when compiling my react project with gulp, tought it was a linting problem but apparently not.

ReferenceError: document is not defined

Select in draggable component

Hi guys,
just a weirdness I observed. I have a component which is draggable (you can drag & drop it somewhere) and inside of that component I have a simple select. When I try to open the select to see all the options it just does not work. It does not show the options. I guess it is not a desired behaviour because, well I am not able to change the value of the select. I am currently doing something like this to make this work:

moves: function(el, source, handle){
    if(handle.className.indexOf('exercise-collection-type') > -1) return false;
    else return true;
  } 

'exercise-collection-type' is a class of the select so I know that when I grab it by the select, I do not want to drag & drop. Is this ok or a bug? I can provide jsfiddle, but I guess the description is straight forward.

Thanks!

Issue with Accepts callback

Hi,

I need to create Action once drop completed... but accept callback fires ,when move starts and passing multiple unwanted updates to server

let options = {

      accepts: function (el, target, source, sibling) {
        console.log(el, source, target, sibling); // This fires when moving 
        return true; 
      }

  };

Unit test scenario with jest&enzyme

Hello, I've been searching for unit test scenario for drag&drop inside nested component. I cannot find solution using enzyme shallow/mount methods. Adding an example in repository would be great.

This library should be deprecated

To react-dragula users

This library was built around the time of React v0.13. These days have long passed (so much so that React 13 isn't even listed in versions of React anymore).

React 15 has removed the data-reactid attribute that this library was working around. Therefore, for React 15+ this library is just an empty husk.

Worse yet, this library ships with [email protected], meanwhile [email protected] was released with an important bug fix. This library has not received development since 2016.

If you're using React, use regular dragula.

To maintainers

Please, mark this library as deprecated for the reasons outlined above

Accessing Child Items in dragula callbacks

Hi there,

I'm struggling to understand the best way to map the dom elements passed back in dragula callbacks to react child items. My code is as follows:

    componentDidMount: function () {
      var container = React.findDOMNode(this),
      drake = ReactDragula([container], {
        moves: function (el, source, handle, sibling) {
          // there are some items in the list of children associated with this container
          // which should not be draggable. Identifying these by their class name feels
          // somewhat wrong (shouldnt be reaching into the DOM to understand a child's state?).
          return el.className !== 'draggable';
        },
        direction: 'horizontal'
      });
      drake.on('drop', (el, target, source, sibling) => {
        // how to I convert the DOM `el` here into the corresponding child item
        this.props.moveFrameCallback(item.id);
      });
    }

The el parameter passed into the drop method is a dom child element of the dnd container. Was wondering what's the best way to map this dom element to the react child item so I can invoke a callback?

I'd like to be able to make an API call based on the drop action and need the id of the child element. The id of the child item is somewhat parsable in the data-reactid attribute of the dom node - is that where I should be taking it from, or is there a more advisable way?

Thanks again for dragula,

Sean

how can i remove some containers from the dragula decorator ?

i have a react component
that under some conditions , needs to disable the drag and drop abilities on some elements

so after the dragula component was instantiated with 3 containers
how can i remove some of them ?

i tried using react's state and it didnt work , the decorator didnt update on setState

Reactify issue.

Not exactly sure why, maybe it's browserify bug, but for some reason when I try to browserify and this module is included it will attempt to run the "reactify" transform. Since "reactify" is a devdependency and I use babel instead it doesn't find it and errors out.

Cannot find module 'reactify' from '/.../node_modules/react-dragula'

A quick fix would just be making reactify a regular dependency or not using the package.json browserify fields.

On drop html is not render properly

I am working on react js app where I used "react-dragula" to drag and drop the list items. I am showing the preview of the child component html inside the parent wrapper component. After dropping an element my html is not render properly. I have no idea whether it is because of Dragula or there is some other issue.
After dropping the list item I am updating list values according to the element index and updating the json value in parent component which returns new updated data in props, and then I am re rendering the child component. But it shows me old html it's not re rendering the html of child component using updated props return by parent component.

Here is my code::

class App extends React.Component {
	drake = null;
	socialContainers = [];

	/** lifecycle method */
	componentDidMount() {
		this.drake = Dragula(this.socialContainers, {
			isContainer: function (el) {
				return (el.id === 'social-container');
			},
			moves: function (el, source, handle, sibling) {
				return (handle.id === "socialSortBtn");
			},
			accepts: function (el, target, source, sibling) {
				return (target.id === 'social-container' && source.id === 'social-container');
			},
		});
		this.drake.on('drop', (el, target, source, sibling) => {
			el.style.cursor = "grab";
			let oldIndex = el.dataset.index
			let type = el.dataset.type
			let iconIndx = Array.prototype.indexOf.call(target.children, el);
			let targetIndex = iconIndx > 0 ? iconIndx : 0;
			if (type) {
				let content = {}
				content.reOrder = true;
				content.oldIndex = oldIndex;
				this.props.callback(content, 'content', targetIndex)
			}
		});
		this.drake.on('drag', (el, source) => {
			el.style.cursor="grabbing";
		})
	}

	updateLinkText(val, index) {
		const { data, callback } = this.props;
		let textParsedHtml = new DOMParser().parseFromString(data.content[index].text, 'text/html');
		if (textParsedHtml.getElementsByTagName("a")[0]) {
			textParsedHtml.getElementsByTagName("a")[0].innerHTML = val;
		}
		let content = {}
		content.changeLinkTxt = true
		content.linkText = val
		content.linkTextHtml = textParsedHtml.body.innerHTML
		//update content
		callback(content, 'content', index)
	}

	onSelectShareOpt(selectedVal, selectedIndx, event) {
		event.stopPropagation();
		let socialObj = socialShareArr.find((obj) => obj.value === selectedVal)
		if (socialObj) {
			let htmlObj = this.getHTMLObj(socialObj);
			let content = {}
			content.active_social_icons = socialObj
			if(htmlObj) { content.content = htmlObj }
			// update content
			this.props.callback(content, 'content', selectedIndx)
		}	
	}

	isIconDisabled = (data, val) => {
		let found = false;
		found = data.some(function (obj) {
			if (obj.value === val) {
				return true;
			}
			return false;
		});
		return found;
	}

	renderSocialIcons(dragulaDecoratorRef) {
		const { data } = this.props;
		let socialIcons = data.activeIcons;
		if (!socialIcons) {
			return null
		}
		return (
			<Fragment>
				{socialIcons && socialIcons.length > 0 && socialIcons.map((activeIcon, index) => (
					<li key={index} data-index={index} data-type={activeIcon.value} className="mb-30">
						<div className="mr-2">
							<button data-toggle="tooltip" title="Drag to reorder" className="btn btn-primary btn-sm btn-icon" id="dragBtn"><span id="socialSortBtn" className="material-icons m-0">drag_indicator</span>
							</button>
						</div>
						<div className="mb-30">
							<img className="mr-2" src={activeIcon.icon} alt="social-icon" width="36" height="36" />
							<FormControl
								value={activeIcon.value}
								as="select"
								onChange={e => this.onSelectShareOpt(e.target.value, index, e)}
								custom
								size=''
							>
								{socialShareArr && socialShareArr.map((option, index) => (
									<option
										key={index}
										disabled={this.isIconDisabled(socialIcons, option.value)}
										value={option.value}
									>
										{option.label}
									</option>
								))}
							</FormControl>
						</div>
						<Form.Group>
							<Form.Label>Link Text</Form.Label>
							<TextInput
								value={activeIcon.linkText}
								onChange={(e) => this.updateLinkText(e.target.value, index)}
								wrapperClass="mx-10 mb-0"
							/>
						</Form.Group>
					</li>
				))}
			</Fragment>
		);
	}

	// main function
	render() {
		const { data } = this.props;
		const dragulaDecoratorRef = (componentBackingInstance) => {
			if (componentBackingInstance) {
				this.socialContainers.push(componentBackingInstance)
			}
		};
		return (
			<Fragment>
				{data &&
					<AppCard>
						<Card.Body>
							<div className="social-opt-container">
								<ul id='social-container' ref={dragulaDecoratorRef}>
									{this.renderSocialIcons(dragulaDecoratorRef)}
								</ul>
							</div>
						</Card.Body>
					</AppCard>
				}
			</Fragment>
		)
	}
}

export { App }

I have also tried to remove innerHTML of "<ul>" and then return new structure but in this case it returns nothing in html. Please check this once why this issue occurring.

Getting Uncaught DOMException: Failed to execute 'removeChild' on 'Node' when rerendering component

Hi,

I am getting this error: Uncaught DOMException: Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node, when my react component is rerendered after the drag is completed.

It is probably because the DOM was changed without telling React, and it can no longer find the dragged item in the right place. Is there a workaround for me for this issue? Thank you.

Drop target not working between two divs?

hi, so i'm trying to drop elements from one div to another one.. it drags but doesnt drop into the second target. just extended the example code to add a second div - any suggestions?

console log shows both divs

import 'react-datepicker/dist/react-datepicker.css'
import * as React from "react";
import Dragula from 'react-dragula';

export class App extends React.Component {
  render () {
    return <div className='container' ref={this.dragulaDecorator}>
      <div>Swap me around</div>
      <div>Swap her around</div>
      <div>Swap him around</div>
      <div>Swap them around</div>
      <div>Swap us around</div>
      <div>Swap things around</div>
      <div>Swap everything around</div>
    </div>
<div className='container' ref={this.dragulaDecorator}>
</div>;
  },
  dragulaDecorator = (componentBackingInstance) => {
    if (componentBackingInstance) {
      let options = { };
      Dragula([componentBackingInstance], options);
      console.log(componentBackingInstance);
    }
  };
});
ReactDOM.render(<App />, document.getElementById('examples'));

ReferenceError: document is not defined when reload page.

captura de pantalla 2017-09-04 a la s 12 06 36 p m

Line 4 in dragula.js

var crossvent = require('crossvent');

Line 24 in custom-event/index.js

'function' === typeof document.createEvent ? function CustomEvent (type, params) {

This error happens each time when i reload a page with dragula import.

The library works perfect if not doing reload to the page

Cannot render React Component on Clone Drop

When clone is set to true from container1 to container2, the drop function will not return a referenced React Component but rather the source el as either an object or html wrapping the object. Is there any way to reference the replacement of el correctly to render the React Component in place of el on drop?

Use Case: container1 holds a preview image and when dropped into container2, the image reference creates the React Component on drop.

drake.on('drop', function(el, target, source, sibling) {
   if (source === container1) {
     var type = el.getAttributeNode('data-type').value;
     var ReactComponent = window[type + 'Component'];
     // variation A
     el = <ReactComponent/> //result -> [object][object]
     // variation B
     el.innerHTML = <ReactComponent/> //result -> <div>[object][object]</div>
     // variation C
     el.parentNode.replaceChild(<ReactComponent/>, el);
     //result -> Failed to execute 'replaceChild' on 'Node': parameter 1 is not of type 'Node'
     //Using React.createElement fails as well
});

I can't seem to get around any of these errors to create the element as an actual node to the DOM.

Uncaught ReferenceError: global is not defined

I am using react-dragula with React v16.13.0 along with TypeScript.

This is the error I get:

Uncaught ReferenceError: global is not defined
    at Object../node_modules/custom-event/index.js (index.js:2)
    at __webpack_require__ (bootstrap:725)
    at fn (bootstrap:100)
    at Object../node_modules/crossvent/src/crossvent.js (crossvent.js:3)
    at __webpack_require__ (bootstrap:725)
    at fn (bootstrap:100)
    at Object../node_modules/dragula/dragula.js (dragula.js:4)
    at __webpack_require__ (bootstrap:725)
    at fn (bootstrap:100)
    at Object../node_modules/react-dragula/react-dragula.js (react-dragula.js:3)

obtain reference to react component on clone

dragula([container1,container2], {
        direction: 'horizontal',
        copy: function(el, source) {
            return source === container1
        },
        accepts: function(el, target) {
            return target !== container1
        },
        removeOnSpill: true
      }).on('cloned', function(clonedElement,clonedFrom) {
        reactComp = // how do i get the react component from clonedFrom dom?, can 'cloned' event return the react component too?
      });

how do i get the react component from clonedFrom dom node?, can 'cloned' event return the react component too?
thanks

What is the correct way import the CSS?

I have a component which I want to use dragula on:

import React, { Component } from 'react';
import styles from './SomeComponent.scss';
import Dragula from 'react-dragula';

class SomeComponent extends Component{
	render(){
		let {children} = this.props
		return(
			<div className={styles['someClass']}>
				<div ref={this.dragulaDecorator}>
					{children}
				</div>
			</div>
		)
	}

	dragulaDecorator = (componentBackingInstance) => {
		if (componentBackingInstance) {
			let options = { };
			Dragula([componentBackingInstance], options);
		}
	};
}

When I try and use it, nothing appears to happen. When looking in Chromes Elements Inspector I can see it's creating the 'mirror' element and doing its thing, but the styles for the classes it's attaching to these elements are not loaded.

In the standard dragula docs it states that the styles must be imported, @import 'node_modules/dragula/dragula'

However, are these not supposed to auto load here when including the Dragula component? And if not what is the best way to get this in?

Creating a draggable container without using findDOMNode()

Creating a dragula object without using findDOMNode() is not possible right now, if the container element is a custom React component. I understand Facebook will eventually deprecate this method, so it is an important feature to have.

Conflicting display order update when combined with setState (Maybe bug)

I have a dynamically ordered array of data entries, and how I want it to work is initially populate it with the dataOrder and after the order is changed by dragula to save the new order to dataOrder. This would trigger a re-render of the list with the correct order.

However, when the drop event is detected, the handleReorder runs setState(dataOrder), and I think what happens is dragula modifies the display, but then the setState modifies the underlying order resulting in a displayed list that's out of order with the underlying data.

This seems like a common use-case, so I'm wondering what's the best practice for dealing with this? I've already figured out one potential solution, but it's kinda hacky and not the react way of writing the code.

I've included the example code to demonstrate what I'm talking about.

*Note using flux, redux may potentially solve this issue since it triggers whole app re-render.

import React from 'react';
import Dragula from 'react-dragula';

export default class App extends React.Component {
  constructor(props) {
      super(props);
      this.state={
          dataOrder: [1,2,3,4,5],
      };
      this.start = 0;
      this.end = 0;
      this.getIndexInParent = this.getIndexInParent.bind(this);
      this.dragulaDecorator = this.dragulaDecorator.bind(this);
      this.displayEntries = this.displayEntries.bind(this);
      this.handleReorder = this.handleReorder.bind(this);
  }

  handleReorder(start, end) {
    console.log(start,end)

    var dataOrder = this.state.dataOrder;

    dataOrder.move = function (old_index, new_index) {
        if (new_index >= this.length) {
            var k = new_index - this.length;
            while ((k--) + 1) {
                this.push(undefined);
            }
        }
        this.splice(new_index, 0, this.splice(old_index, 1)[0]);
        return this; // for testing purposes
    };

    var newList = dataOrder.move(start,end)

    this.setState({ dataOrder: newList})
    console.log(this.state.dataOrder)
  }

  getIndexInParent(el) {
    return Array.from(el.parentNode.children).indexOf(el)
  }

  dragulaDecorator(componentBackingInstance) {
      if (componentBackingInstance) {
        var options = {
          moves: function (el, container, handle, sibling) {
              let pickedLocation = this.getIndexInParent(el);
              this.start = pickedLocation;
              return handle.classList.contains('handle');
          }.bind(this)
      };

        var drake = Dragula([componentBackingInstance], options);

        drake.on('drop', (el, target, source, sibling) => {
          let droppedLocation = this.getIndexInParent(el);
          this.end = droppedLocation;
          this.handleReorder(this.start, this.end);
        });
      }}

    displayEntries() {
      var dataOrder = this.state.dataOrder;
      var results = dataOrder.map( (val) => {
        return <div><span className='handle'>XXX</span> {val.toString().repeat(val)} </div>
      })
      return results;
    }

  render () {

    return (<div className='container' ref={this.dragulaDecorator}>
      {this.displayEntries()}
    </div>)
  }
}

Drag and drop between Container

Hi,

How can we integrate, Drag and drop between container.. In Jquery cersion i can see the example but i stuck with React Version

Different between react-dragula and dragula?

I want to know properly what different between react-dragula and normal dragula. If I use normal dragula in a React project, not use react version of it, then what is the side effect?

Just curious, because I used normal version and still found nothing wrong.
Thank you.

drake.on drop event not occurs react dragulla

I am using dragula container inside child component, but the drop event not occurs. I have tried every possible way but the drop event not occurs. I want to reorder my list on drag and drop.

This is my code.

import React, { Fragment } from 'react';
import { Tabs, Tab, Card } from 'react-bootstrap';
import Dragula from 'react-dragula';
import { AppCard } from '../../../../../Components/AppCard'

class App extends React.Component {
	drake = null;
	dragullaContainers = [];

	componentDidMount() {
		this.drake = Dragula(this.dragullaContainers, {
			isContainer: function (el) {
				if (el.id === 'social-container') {
					return true;
				}
				return false;
			},
			moves: function (el, source, handle, sibling) {
				if (handle.id === "socialSortBtn") {
					return true;
				}
				return false;
			},
			accepts: function (el, target, source, sibling) {
				return true; // elements can be dropped in any of the `containers` by default
			},

		});
		this.drake.on('drop', (el, target) => {
			// this event not occurs
			console.log('drop', el, target)
		});
		this.drake.on('drag', (el, source) => {
			console.log('drag', el)
		})
	}

	// main function
	render() {
		const { data } = this.props;
		const dragulaDecoratorRef = (componentBackingInstance) => {
			if (componentBackingInstance) {
				this.dragullaContainers.push(componentBackingInstance)
			}
		};
		return (
			<Fragment>
				{data ?
					<Tabs variant="pills" className="btn-group border rounded"  defaultActiveKey="content" id="tools-header">
						<Tab eventKey="content" title="Content" tabClassName="btn shadow-none">
							<AppCard>
								<Card.Body>
									<div>
										<ul id='social-container' ref={dragulaDecoratorRef}>
											{data.active_social_icons && data.active_social_icons.length > 0 && data.active_social_icons.map((activeIcon, index) => (
												<li key={index} data-index={index} className="d-flex mb-30">
													<div className="">
														<div className="mr-2">
															<button data-toggle="tooltip" title="Drag to reorder" className="btn btn-primary btn-sm btn-icon" id="dragBtn"><span id="socialSortBtn" className="material-icons m-0">drag_indicator</span>
															</button>
														</div>
														<div className="d-flex mb-30">List item</div>
													</div>
												</li>
											))}
										</ul>
									</div>
								</Card.Body>
							</AppCard>
						</Tab>
						<Tab eventKey="style" title="Style">
							tab2 content
						</Tab>
					</Tabs>
				:
				null
			}
			</Fragment>
		)
	}
}

export default App;

Please suggest why drop event is not occuring? I want to update list item position via drag and drop.

Can I change states when using Dragula?

Hi!
I’m trying to use Dragula to implement a drag-and-drop exercise in our web application. The problem I’ve encountered is that we can’t change states from within the built-in Dragula functions. In the example further down I have a counter “counts” that counts each element that is dragged correctly. The problem is in the if-statement were I’ve written /* the following line is not working */, here I would like to change states.

The problem is that I can’t use “this” and I can’t find anyway to make my code rerender from the Dragula function…

Do you have any idea on how to solve this problem?


Example:

dragulaCreator = (container) => {
let drake = Dragula([container, $('drop-target1'), $('drop-target2')])

   drake.on('drop', function(el, target){
    if ((el == $('drag-elements1'))&&(target == $('drop-target1'))){
     
           /* the following line is not working */
           this.setState({endExercise: true})
          }
    else {
           drake.cancel();
    }
 }

}

Does it support react `16.8.1`?

I am using react 16.8.1 but it doesn't seem to work well with react-dragula. There is no css created for gu-mirrow and gu-transit. And the gu-transit element is not moving during drag. I wonder whether this library work with react16?

Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined.

npm run start on this project results in a page showing this error:
Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined.

Console output:

  - ReactMultiChild.js:196 ReactDOMComponent.ReactMultiChild.Mixin.mountChildren    [wwe-draft]/[react]/lib/ReactMultiChild.js:196:27

  - ReactDOMComponent.js:593 ReactDOMComponent.Mixin._createContentMarkup
    [wwe-draft]/[react]/lib/ReactDOMComponent.js:593:32


  Error: Invariant Violation: Element type is invalid: expected a string (for bu  ilt-in components) or a class/function (for composite components) but got: und  efined.

  - invariant.js:38 invariant
    [wwe-draft]/[react]/[fbjs]/lib/invariant.js:38:15

  - instantiateReactComponent.js:66 instantiateReactComponent
    [wwe-draft]/[react]/lib/instantiateReactComponent.js:66:134

  - ReactChildReconciler.js:29 instantiateChild
    [wwe-draft]/[react]/lib/ReactChildReconciler.js:29:28

  - traverseAllChildren.js:67 traverseAllChildrenImpl
    [wwe-draft]/[react]/lib/traverseAllChildren.js:67:5

  - traverseAllChildren.js:83 traverseAllChildrenImpl
    [wwe-draft]/[react]/lib/traverseAllChildren.js:83:23

  - traverseAllChildren.js:155 traverseAllChildren
    [wwe-draft]/[react]/lib/traverseAllChildren.js:155:10

  - ReactChildReconciler.js:52 Object.ReactChildReconciler.instantiateChildren
    [wwe-draft]/[react]/lib/ReactChildReconciler.js:52:5

  - ReactMultiChild.js:159 ReactDOMComponent.ReactMultiChild.Mixin._reconcilerIn    stantiateChildren
    [wwe-draft]/[react]/lib/ReactMultiChild.js:159:41

  - ReactMultiChild.js:196 ReactDOMComponent.ReactMultiChild.Mixin.mountChildren    [wwe-draft]/[react]/lib/ReactMultiChild.js:196:27

  - ReactDOMComponent.js:593 ReactDOMComponent.Mixin._createContentMarkup
    [wwe-draft]/[react]/lib/ReactDOMComponent.js:593:32

Getting the same error implementing it into my own project.

Not compatible with React v15

This will no longer work with React v15

function rm (el) {
    el.removeAttribute('data-reactid');
  }

since React 15 dropped data-reactid.

How to use it in `typescript`?

I get an error Could not find a declaration file for module 'react-dragula' when using react-dragula in typescript. Where can I find the type definition for this component?

drake.on drop not working on routing change

I am working on react js app, and using react-dragula to sort the list rows. It's working fine on page reload but having an issue if coming from another page to this listing page. Basically it's having an issue with routing(because it works on page reload)

I am using below mention version of packages::
react-dragula: 1.1.17
react-router-dom: 5.2.0

This my code of list row::

import React, { Fragment } from "react";
  import Dragula from "react-dragula";
  import ListItem from 'Components/ListItem';
  
  class MyListComp extends React.Component {
  
  	/** variables */
  	drake = null;
  	containers = [];
  	sequence = [];
  
  	componentDidMount() {
  		this.renderDragDrop();
  	}
  	
  	renderDragDrop() {
  		this.drake = Dragula(this.containers, {
  			isContainer: function (el) {
  				return (el.id === "seq-drag");
  			},
  			moves: function (el, source, handle, sibling) {
  				return (handle.id === "seqSortBtn");
  			},
  		});
  		this.drake.on("drop", async (el, target, source, sibling) => {
  			if (target) {
  				var ids = [];
  				var parentElement = document.querySelector("#" + target.id); // Select parent element
  				var childElements = parentElement.querySelectorAll(".seq-el"); // Select child elements
  				for (var i = 0; i < childElements.length; i++) {
  					let objToPush = {
  						_id: childElements[i].getAttribute("id"),
  						seq: i + 1,
  					}
  					ids.push(objToPush);
  				}
  				this.sequence = ids; // store in variable;
  			}
  		});
  	}
  
  	render() {
  		const { lists } = this.props;
  		const dragulaDecorator = (componentBackingInstance) => {
  			if (componentBackingInstance) {
  				this.containers.push(componentBackingInstance)
  			}
  		};
  		return (
  			<Fragment>
  				<div id="seq-drag" ref={dragulaDecorator}>
  					{lists && lists.length > 0 && lists.map((seq, key)=>(
  						<ListItem key={key} seq={seq} />
  					))}
  				</div>		
  			</Fragment>
  		)
  	}
  }
  
  export default MyListComp;

Please suggest someone what is problem while loading component via routing using react-dragula? and is there any issue in react-dragula or we can resolve this using some custom code, please suggest.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.