Skip to content

Commit

Permalink
resize with sizeToContent
Browse files Browse the repository at this point in the history
fix #2612 to allow resize when you have a number (soft max)
  • Loading branch information
adumesny committed Mar 3, 2024
1 parent 03557d4 commit 8d233b0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/dd-gridstack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class DDGridStack {
if (handles === 'all') handles = 'n,e,s,w,se,sw,ne,nw';
// NOTE: keep the resize handles as e,w don't have enough space (10px) to show resize corners anyway. limit during drag instead
// restrict vertical resize if height is done to match content anyway... odd to have it spring back
// if (Utils.shouldSizeToContent(n)) {
// if (Utils.shouldSizeToContent(n, true)) {
// const doE = handles.indexOf('e') !== -1;
// const doW = handles.indexOf('w') !== -1;
// handles = doE ? (doW ? 'e,w' : 'e') : (doW ? 'w' : '');
Expand Down
2 changes: 1 addition & 1 deletion src/dd-resizable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export class DDResizable extends DDBaseImplement implements HTMLElementExtendOpt

/** @internal */
protected _resizeStart(event: MouseEvent): DDResizable {
this.sizeToContent = Utils.shouldSizeToContent(this.el.gridstackNode);
this.sizeToContent = Utils.shouldSizeToContent(this.el.gridstackNode, true); // strick true only and not number
this.originalRect = this.el.getBoundingClientRect();
this.scrollEl = Utils.getScrollElement(this.el);
this.scrollY = this.scrollEl.scrollTop;
Expand Down
8 changes: 5 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,11 @@ export class Utils {
return els;
}

/** true if we should resize to content */
static shouldSizeToContent(n: GridStackNode | undefined): boolean {
return n?.grid && (!!n.sizeToContent || (n.grid.opts.sizeToContent && n.sizeToContent !== false));
/** true if we should resize to content. strict=true when only 'sizeToContent:true' and not a number which lets user adjust */
static shouldSizeToContent(n: GridStackNode | undefined, strict = false): boolean {
return n?.grid && (strict ?
(n.sizeToContent === true || (n.grid.opts.sizeToContent === true && n.sizeToContent === undefined)) :
(!!n.sizeToContent || (n.grid.opts.sizeToContent && n.sizeToContent !== false)));
}

/** returns true if a and b overlap */
Expand Down

0 comments on commit 8d233b0

Please sign in to comment.