Skip to content

Commit d6df3d2

Browse files
committed
dragging nested items no longer clipp
* fix to make #992 better going forward as I'm focusing on nested grids again * dragging sub item between grids no longer get clipped by parent * removed basePosition.aboslute option as I'm not sure how we can make it work (parent has position.relative which will clip us otherwise) * nested.html you can drag pink items between grids (h5 case, JQ still clipps)
1 parent f350f49 commit d6df3d2

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

doc/CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ Change log
6767

6868
## 4.4.0-dev TBD
6969
* fix [#1901](https://github.com/gridstack/gridstack.js/pull/1901) error introduced for #1785 when re-loading with fewer objects
70+
* fix [#1902](https://github.com/gridstack/gridstack.js/pull/1902) nested.html: dragging between sub-grids show items clipped
7071

7172
## 4.4.0 (2021-12-21)
7273
* add [#1887](https://github.com/gridstack/gridstack.js/pull/1887) support for IE (new es5 folder) by [@SmileLifeIven](https://github.com/SmileLifeIven)

src/h5/dd-draggable.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ export interface DDDraggableOpt {
1616
revert?: string | boolean | unknown; // TODO: not implemented yet
1717
scroll?: boolean; // nature support by HTML5 drag drop, can't be switch to off actually
1818
helper?: string | HTMLElement | ((event: Event) => HTMLElement);
19-
basePosition?: 'fixed' | 'absolute';
2019
start?: (event: Event, ui: DDUIData) => void;
2120
stop?: (event: Event) => void;
2221
drag?: (event: Event, ui: DDUIData) => void;
@@ -52,13 +51,11 @@ export class DDDraggable extends DDBaseImplement implements HTMLElementExtendOpt
5251
private parentOriginStylePosition: string;
5352
/** @internal */
5453
private helperContainment: HTMLElement;
55-
/** @internal */
56-
private static basePosition: 'fixed' | 'absolute' = 'absolute';
5754
/** @internal #1541 can't have {passive: true} on Safari as otherwise it reverts animate back to old location on drop */
5855
private static dragEventListenerOption = true; // DDUtils.isEventSupportPassiveOption ? { capture: true, passive: true } : true;
5956
/** @internal */
6057
private static originStyleProp = ['transition', 'pointerEvents', 'position',
61-
'left', 'top', 'opacity', 'zIndex', 'width', 'height', 'willChange'];
58+
'left', 'top', 'opacity', 'zIndex', 'width', 'height', 'willChange', 'min-width'];
6259

6360
constructor(el: HTMLElement, option: DDDraggableOpt = {}) {
6461
super();
@@ -213,13 +210,14 @@ export class DDDraggable extends DDBaseImplement implements HTMLElementExtendOpt
213210

214211
/** @internal */
215212
private _setupHelperStyle(): DDDraggable {
213+
// TODO: set all at once with style.cssText += ... ? https://stackoverflow.com/questions/3968593
216214
this.helper.style.pointerEvents = 'none';
217215
this.helper.style.width = this.dragOffset.width + 'px';
218216
this.helper.style.height = this.dragOffset.height + 'px';
219217
this.helper.style.willChange = 'left, top';
220218
this.helper.style.transition = 'none'; // show up instantly
221-
this.helper.style.position = this.option.basePosition || DDDraggable.basePosition;
222-
this.helper.style.zIndex = '1000';
219+
this.helper.style.position = 'fixed'; // let us drag between grids by not clipping as parent .grid-stack is position: 'relative'
220+
this.helper.style['min-width'] = 0; // since we no longer relative to our parent and we don't resize anyway (normally 100/#column %)
223221
setTimeout(() => {
224222
if (this.helper) {
225223
this.helper.style.transition = null; // recover animation
@@ -232,10 +230,17 @@ export class DDDraggable extends DDBaseImplement implements HTMLElementExtendOpt
232230
private _removeHelperStyle(): DDDraggable {
233231
// don't bother restoring styles if we're gonna remove anyway...
234232
let node = this.helper ? (this.helper as GridItemHTMLElement).gridstackNode : undefined;
235-
if (!node || !node._isAboutToRemove) {
233+
if (this.dragElementOriginStyle && (!node || !node._isAboutToRemove)) {
236234
DDDraggable.originStyleProp.forEach(prop => {
237235
this.helper.style[prop] = this.dragElementOriginStyle[prop] || null;
238236
});
237+
// show up instantly otherwise we animate to off the grid when switching back to 'absolute' from 'fixed'
238+
this.helper.style.transition = 'none';
239+
setTimeout(() => {
240+
if (this.helper) {
241+
this.helper.style.transition = this.dragElementOriginStyle['transition']; // recover animation
242+
}
243+
}, 0);
239244
}
240245
delete this.dragElementOriginStyle;
241246
return this;
@@ -262,7 +267,7 @@ export class DDDraggable extends DDBaseImplement implements HTMLElementExtendOpt
262267
/** @internal */
263268
private _setupHelperContainmentStyle(): DDDraggable {
264269
this.helperContainment = this.helper.parentElement;
265-
if (this.option.basePosition !== 'fixed') {
270+
if (this.helper.style.position !== 'fixed') {
266271
this.parentOriginStylePosition = this.helperContainment.style.position;
267272
if (window.getComputedStyle(this.helperContainment).position.match(/static/)) {
268273
this.helperContainment.style.position = 'relative';
@@ -271,10 +276,10 @@ export class DDDraggable extends DDBaseImplement implements HTMLElementExtendOpt
271276
return this;
272277
}
273278

274-
/** @internal prevent the default gost image to be created (which has wrongas we move the helper/element instead
279+
/** @internal prevent the default ghost image to be created (which has wrong as we move the helper/element instead
275280
* (legacy jquery UI code updates the top/left of the item).
276281
* TODO: maybe use mouse event instead of HTML5 drag as we have to work around it anyway, or change code to not update
277-
* the actual grid-item but move the gost image around (and special case jq version) ?
282+
* the actual grid-item but move the ghost image around (and special case jq version) ?
278283
**/
279284
private _cancelDragGhost(e: DragEvent): DDDraggable {
280285
/* doesn't seem to do anything...

src/h5/dd-resizable.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ export interface DDResizableOpt {
1717
maxWidth?: number;
1818
minHeight?: number;
1919
minWidth?: number;
20-
basePosition?: 'fixed' | 'absolute';
2120
start?: (event: Event, ui: DDUIData) => void;
2221
stop?: (event: Event) => void;
2322
resize?: (event: Event, ui: DDUIData) => void;
@@ -206,9 +205,8 @@ export class DDResizable extends DDBaseImplement implements HTMLElementExtendOpt
206205
if (window.getComputedStyle(this.el.parentElement).position.match(/static/)) {
207206
this.el.parentElement.style.position = 'relative';
208207
}
209-
this.el.style.position = this.option.basePosition || 'absolute'; // or 'fixed'
208+
this.el.style.position = 'absolute';
210209
this.el.style.opacity = '0.8';
211-
this.el.style.zIndex = '1000';
212210
return this;
213211
}
214212

0 commit comments

Comments
 (0)