Skip to content

Commit 0e5b9a0

Browse files
author
Alain Dumesny
authored
Merge pull request #2470 from adumesny/master
sub-grid styles fix
2 parents f16e0a9 + fafbcd0 commit 0e5b9a0

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

doc/CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Change log
55
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
66
**Table of Contents** *generated with [DocToc](http://doctoc.herokuapp.com/)*
77

8+
- [9.2.1-dev (TBD)](#921-dev-tbd)
89
- [9.2.1 (2023-09-20)](#921-2023-09-20)
910
- [9.2.0 (2023-09-10)](#920-2023-09-10)
1011
- [9.1.1 (2023-09-06)](#911-2023-09-06)
@@ -99,6 +100,9 @@ Change log
99100

100101
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
101102

103+
## 9.2.1-dev (TBD)
104+
* fix - sub-grid styles now look for immediate correct parent, not any depth above.
105+
102106
## 9.2.1 (2023-09-20)
103107
* fix _updateContainerHeight() to use height rather than min-height again (apart for nested grids which need it) and partial getComputedStyle CSS minHeight support
104108

src/gridstack.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,8 @@ export class GridStack {
318318
}
319319

320320
// check if we're been nested, and if so update our style and keep pointer around (used during save)
321-
let parentGridItem = (Utils.closestUpByClass(this.el, gridDefaults.itemClass) as GridItemHTMLElement)?.gridstackNode;
321+
const grandParent: GridItemHTMLElement = this.el.parentElement?.parentElement;
322+
let parentGridItem = grandParent?.classList.contains(gridDefaults.itemClass) ? grandParent.gridstackNode : undefined;
322323
if (parentGridItem) {
323324
parentGridItem.subGrid = this;
324325
this.parentGridItem = parentGridItem;

src/utils.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -314,13 +314,13 @@ export class Utils {
314314
}
315315

316316
/** return the closest parent (or itself) matching the given class */
317-
static closestUpByClass(el: HTMLElement, name: string): HTMLElement {
318-
while (el) {
319-
if (el.classList.contains(name)) return el;
320-
el = el.parentElement
321-
}
322-
return null;
323-
}
317+
// static closestUpByClass(el: HTMLElement, name: string): HTMLElement {
318+
// while (el) {
319+
// if (el.classList.contains(name)) return el;
320+
// el = el.parentElement
321+
// }
322+
// return null;
323+
// }
324324

325325
/** delay calling the given function for given delay, preventing new calls from happening while waiting */
326326
static throttle(func: () => void, delay: number): () => void {

0 commit comments

Comments
 (0)