Skip to content

Commit cc70f48

Browse files
authored
Merge pull request #2992 from adumesny/master
gs-size-to-content to support numbers
2 parents 1925cef + 30d9cd2 commit cc70f48

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

doc/CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ Change log
127127
* feat: [#2989](https://github.com/gridstack/gridstack.js/pull/2989) new `updateOptions(o: GridStackOptions)` to update PARTIAL list of options after grid as been created
128128
* fix: [#2980](https://github.com/gridstack/gridstack.js/issues/2980) dd-touch circular dependency
129129
* fix: [#2667](https://github.com/gridstack/gridstack.js/issues/2667) sidebar items not honoring gs-w (enter-leave-re-enter)
130+
* fix: [#2987](https://github.com/gridstack/gridstack.js/issues/2987) gs-size-to-content to support numbers
130131

131132
## 11.4.0 (2025-02-27)
132133
* fix: [#2921](https://github.com/gridstack/gridstack.js/pull/2921) replace initMouseEvent with MouseEvent constructor and added composed: true

src/gridstack.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1781,7 +1781,11 @@ export class GridStack {
17811781
n.noResize = Utils.toBool(el.getAttribute('gs-no-resize'));
17821782
n.noMove = Utils.toBool(el.getAttribute('gs-no-move'));
17831783
n.locked = Utils.toBool(el.getAttribute('gs-locked'));
1784-
n.sizeToContent = Utils.toBool(el.getAttribute('gs-size-to-content'));
1784+
const attr = el.getAttribute('gs-size-to-content');
1785+
if (attr) {
1786+
if (attr === 'true' || attr === 'false') n.sizeToContent = Utils.toBool(attr);
1787+
else n.sizeToContent = parseInt(attr, 10);
1788+
}
17851789
n.id = el.getAttribute('gs-id');
17861790

17871791
// read but never written out
@@ -1800,10 +1804,10 @@ export class GridStack {
18001804
if (n.minH) el.removeAttribute('gs-min-h');
18011805
}
18021806

1803-
// remove any key not found (null or false which is default)
1807+
// remove any key not found (null or false which is default, unless sizeToContent=false override)
18041808
for (const key in n) {
18051809
if (!n.hasOwnProperty(key)) return;
1806-
if (!n[key] && n[key] !== 0) { // 0 can be valid value (x,y only really)
1810+
if (!n[key] && n[key] !== 0 && key !== 'gs-size-to-content') { // 0 can be valid value (x,y only really)
18071811
delete n[key];
18081812
}
18091813
}

0 commit comments

Comments
 (0)