diff --git a/doc/CHANGES.md b/doc/CHANGES.md index a9168e8a3..bcc3508f3 100644 --- a/doc/CHANGES.md +++ b/doc/CHANGES.md @@ -5,6 +5,7 @@ Change log **Table of Contents** *generated with [DocToc](http://doctoc.herokuapp.com/)* +- [9.2.1-dev (TBD)](#921-dev-tbd) - [9.2.1 (2023-09-20)](#921-2023-09-20) - [9.2.0 (2023-09-10)](#920-2023-09-10) - [9.1.1 (2023-09-06)](#911-2023-09-06) @@ -99,6 +100,9 @@ Change log +## 9.2.1-dev (TBD) +* fix - sub-grid styles now look for immediate correct parent, not any depth above. + ## 9.2.1 (2023-09-20) * fix _updateContainerHeight() to use height rather than min-height again (apart for nested grids which need it) and partial getComputedStyle CSS minHeight support diff --git a/src/gridstack.ts b/src/gridstack.ts index 84d71d123..502b8f7df 100644 --- a/src/gridstack.ts +++ b/src/gridstack.ts @@ -318,7 +318,8 @@ export class GridStack { } // check if we're been nested, and if so update our style and keep pointer around (used during save) - let parentGridItem = (Utils.closestUpByClass(this.el, gridDefaults.itemClass) as GridItemHTMLElement)?.gridstackNode; + const grandParent: GridItemHTMLElement = this.el.parentElement?.parentElement; + let parentGridItem = grandParent?.classList.contains(gridDefaults.itemClass) ? grandParent.gridstackNode : undefined; if (parentGridItem) { parentGridItem.subGrid = this; this.parentGridItem = parentGridItem; diff --git a/src/utils.ts b/src/utils.ts index 114ce0e5b..3da85af18 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -314,13 +314,13 @@ export class Utils { } /** return the closest parent (or itself) matching the given class */ - static closestUpByClass(el: HTMLElement, name: string): HTMLElement { - while (el) { - if (el.classList.contains(name)) return el; - el = el.parentElement - } - return null; - } + // static closestUpByClass(el: HTMLElement, name: string): HTMLElement { + // while (el) { + // if (el.classList.contains(name)) return el; + // el = el.parentElement + // } + // return null; + // } /** delay calling the given function for given delay, preventing new calls from happening while waiting */ static throttle(func: () => void, delay: number): () => void {