IE ghost image issue
I have a scenario where I want to move items from there source to a container (pretty straight forward), So the items should keep on showing at there source till they are moved to the container and the drop completes. In this case how can I use the CSS trick to hide the ghost image as explained in here #88 .
How can I work around this ?
@verona123 Were you ever able to figure out how to do this? I am running into the same issue in IE 11. Hiding the ghost image causes the source to be removed.
no, i haven't. There are workarounds to do this, but this needs to be done in the html5 backend code. We are currently trying to do our own version of dnd because of this one reason. In it we are able to get around this issue.
I actually was able to get this to work using most of the code from #88. The only difference is the style function. I removed the opacity style and this left the source where it was and used my custom drag layer.
function getStyles(props) {
const { isDragging } = props;
//const transform = `translate3d(${left}px, ${top}px, 0)`;
return {
// IE fallback: hide the real node using CSS when dragging
// because IE will ignore our custom "empty image" drag preview.
height: isDragging ? 0 : ''
};
}
Thats good. We really want to show preview though, which i dont think is possible to hack today. Did you also get preview working in IE
Yes, I have it working with a custom preview in IE.
👍 cool. From the code I understand that we are hiding the source element, but does it take care of snapshotting the preview for us in IE. Also i cannot hide the source node in my case. How long does the source element remain hidden
I may not fully understand what you mean by snapshotting the preview in IE. I was always able to see the preview image I was rendering in IE. The issue was that the actual source element was being dragged right above the preview image (only in IE).
Hiding the source node will last as long as dragging is taking place.
Using the combination of the captureDraggingState set to true and the getStyles function shown above as explained in #88 is what allows the css to hide the source node for the duration of the dragging.
Right even I am able to see preview. Sorry for confusion, its been long since I visited IE for my scenario, Just played around again. I am facing the same issue as you, i am also seeing the source element along with preview.
Where do you set captureDraggingState to true ?
I am doing as below public componentDidMount() { this.props.connectDragPreview(getEmptyImage(), { captureDraggingState: true, }); }
Inside of the lifecycle method componentDidMount for your Drag component.
That looks correct. The issue I'm guessing is in the render method of your Drag component. Make sure you have the style on your div tag.
connectDragSource(
<div style={getStyles(this.props)}></div>
);
In my case isDragging is false. I just set an alert inside collect function and I am alerting the monitor.isDragging(). This alerts as false as soon as I start dragging
Got this working now https://github.com/gaearon/react-dnd/issues/227 . Element is hiding and also only preview is shown
But in my case I cannot hide the item. I need a move Effect. So that the item remains in the source position and in a visible state.
Can this be achived ? Thats what my previous question was.
I've run into a similar issue where the source element being dragged needs to be visible throughout the dragging phase but I wanted to have a custom drag preview. In IE the ghost image was interfering with the custom drag preview. For now I've solved it by having a false dragging source.
For e.g instead of having
render() {
return connectDragSource(<div className="dragSource"></div>);
}
I have something like this
render() {
return (
<div className="dragSource">
connectDragSource(<div className="dragSource__draggable"></div>)
<div class="dragSource__content"></div>
</div>
);
}
The dragSource__draggable is absolutely positioned inside dragSource and has opacity: 0 which results in no ghost image being created. I know there are some limitations to this approach but it seems to work well for our case.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
For anyone who's spent days looking for a solution (like me)
https://github.com/zyzo/react-dnd-mouse-backend seems to make IE11 usable.
If always having a covering transparent div is causing troubles, we can partially solve it this way.
import { PureComponent } from 'react';
import { DragSource } from 'react-dnd';
import { getEmptyImage } from 'react-dnd-html5-backend';
import { ItemTypes } from './ItemTypes';
import { Box } from './Box';
function getDragTriggerStyles(props) {
const { left, top, isDragging } = props;
const transform = `translate3d(${left}px, ${top}px, 0)`;
return {
position: 'absolute',
transform,
WebkitTransform: transform,
};
}
function getNewStyles() {
return {
position: 'absolute',
top: 0,
left: 0,
right: 0,
bottom: 0,
opacity: 0
};
}
class DraggableBox extends PureComponent {
componentDidMount() {
const { connectDragPreview } = this.props;
if (connectDragPreview) {
// Use empty image as a drag preview so browsers don't draw it
// and we can draw whatever we want on the custom drag layer instead.
connectDragPreview(getEmptyImage(), {
// IE fallback: specify that we'd rather screenshot the node
// when it already knows it's being dragged so we can hide it with CSS.
captureDraggingState: true,
});
}
}
render() {
const { title, connectDragSource, isDragging } = this.props;
if (!isDragging) {
return connectDragSource(
<div style={getStyles(this.props)} role="DraggableBox">
<Box title={title} isDragging={isDragging}/>
</div>
);
} else {
return (
<div style={getStyles(this.props)} role="DraggableBox">
<Box title={title} />
{connectDragSource(<div style={getNewStyles()}></div>)}
</div>
);
}
}
}
export default DragSource(ItemTypes.BOX, {
beginDrag(props) {
const { id, title, left, top } = props;
return { id, title, left, top };
},
}, (connect, monitor) => ({
connectDragSource: connect.dragSource(),
connectDragPreview: connect.dragPreview(),
isDragging: monitor.isDragging(),
}))(DraggableBox);