Skip to content

Commit b057075

Browse files
authored
Merge pull request gridstack#2700 from adumesny/master
prevent 'r' rotation to items that can't resize (2)
2 parents 06e558b + 4114425 commit b057075

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

src/dd-draggable.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ export class DDDraggable extends DDBaseImplement implements HTMLElementExtendOpt
291291
grid.engine.restoreInitial();
292292
this._mouseUp(this.mouseDownEvent);
293293
} else if (e.key === 'r' || e.key === 'R') {
294-
if (n.w === n.h) return;
294+
if (!Utils.canBeRotated(n)) return;
295295
n._origRotate = n._origRotate || {...n._orig}; // store the real orig size in case we Esc after doing rotation
296296
delete n._moving; // force rotate to happen (move waits for >50% coverage otherwise)
297297
grid.setAnimation(false) // immediate rotate so _getDragOffset() gets the right dom size below

src/gridstack.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1450,7 +1450,7 @@ export class GridStack {
14501450
public rotate(els: GridStackElement, relative?: Position): GridStack {
14511451
GridStack.getElements(els).forEach(el => {
14521452
let n = el.gridstackNode;
1453-
if (!n || n.w === n.h || n.locked || n.noResize || n.grid?.opts.disableResize || (n.minW && n.minW === n.maxW) || (n.minH && n.minH === n.maxH)) return;
1453+
if (!Utils.canBeRotated(n)) return;
14541454
const rot: GridStackWidget = { w: n.h, h: n.w, minH: n.minW, minW: n.minH, maxH: n.maxW, maxW: n.maxH };
14551455
// if given an offset, adjust x/y by column/row bounds when user presses 'r' during dragging
14561456
if (relative) {

src/utils.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,4 +604,9 @@ export class Utils {
604604
// }
605605
// return el.contains(target);
606606
// }
607-
}
607+
608+
/** true if the item can be rotated (checking for prop, not space available) */
609+
public static canBeRotated(n: GridStackNode): boolean {
610+
return !(!n || n.w === n.h || n.locked || n.noResize || n.grid?.opts.disableResize || (n.minW && n.minW === n.maxW) || (n.minH && n.minH === n.maxH));
611+
}
612+
}

0 commit comments

Comments
 (0)