Dojo Dijit Buttons hide the "real" button offscreen using CSS:
.dijitOffScreen {
position: absolute !important;
left: -10000px !important;
top: -10000px !important;
}
- Why does this cause HTML5 drag and drop to not function correctly in Chrome and FireFox?
- What are alternative methods to hide the input element and maintain the same Dojo Dijit Button behavior? (Adding
display:noneto the offscreen input element seems to work, but does that functionally alter the behavior of the input and thus widget?)
Original question:
Sometimes the default 'ghost' HTML5 drag image is smaller in size or not rendered at all. It varies by browser and there seems to be an interaction with Dojo Dijits involved.
After adding a Dijit Button to a draggable Dijit ContentPane, what causes the drag icon to be tiny in FireFox and not rendered at all in Chrome?
Simple jsFiddle repro:
var cp1 = new ContentPane({
style: "width: 400px; height: 124px; background:red",
content: "cp1: 'ghost 'drag icon is tiny or not visible :(<br />",
});
// Make draggable
domProp.set(cp1.domNode, 'draggable', 'true');
cp1.on('dragstart', onDragStartHandler); // otherwise FF doesn't show drag icon
// PROBLEM -> adding button messes up drag icon
button = new Button({label: 'Dijit Button'});
button.placeAt(cp1.containerNode);
update:
- In addition to rendering the drag icon incorrectly, other HTML5 drag and drop events no longer function correctly. On Chrome, the entire document just disappears after
dragoverand/orendevents are added. On FireFox, the processing of drag events is significantly slower. - Adding generic HTML button inputs instead of Dijit buttons does not result in any of these side effects: definitely Dojo Dijit interfering somehow...
update 2:
- Root cause: Dijit Button hides an HTML button input element via the
dijitOffScreenclass. Removingleft: 10000px !importantandtop: 10000px !importantstyles from the element restores drag and drop at the expense of showing a blank button. credit: Kenneth G. Franqueiro