Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 942a9f6

Browse files
committed
fix: remove style node when attached to parent node
1 parent cea18b6 commit 942a9f6

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/gridstack.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,7 +1489,8 @@ export class GridStack {
14891489
protected _removeStylesheet(): GridStack {
14901490

14911491
if (this._styles) {
1492-
Utils.removeStylesheet(this._styleSheetClass);
1492+
const styleLocation = this.opts.styleInHead ? undefined : this.el.parentNode as HTMLElement;
1493+
Utils.removeStylesheet(this._styleSheetClass, styleLocation);
14931494
delete this._styles;
14941495
}
14951496
return this;
@@ -1517,7 +1518,7 @@ export class GridStack {
15171518
// create one as needed
15181519
if (!this._styles) {
15191520
// insert style to parent (instead of 'head' by default) to support WebComponent
1520-
let styleLocation = this.opts.styleInHead ? undefined : this.el.parentNode as HTMLElement;
1521+
const styleLocation = this.opts.styleInHead ? undefined : this.el.parentNode as HTMLElement;
15211522
this._styles = Utils.createStylesheet(this._styleSheetClass, styleLocation, {
15221523
nonce: this.opts.nonce,
15231524
});
@@ -2216,7 +2217,7 @@ export class GridStack {
22162217
if (this._gsEventHandler['dropped']) {
22172218
this._gsEventHandler['dropped']({...event, type: 'dropped'}, origNode && origNode.grid ? origNode : undefined, node);
22182219
}
2219-
2220+
22202221
return false; // prevent parent from receiving msg (which may be grid as well)
22212222
});
22222223
return this;

src/utils.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,9 @@ export class Utils {
182182
}
183183

184184
/** removed the given stylesheet id */
185-
static removeStylesheet(id: string): void {
186-
let el = document.querySelector('STYLE[gs-style-id=' + id + ']');
185+
static removeStylesheet(id: string, parent?: HTMLElement): void {
186+
const target = parent || document;
187+
let el = target.querySelector('STYLE[gs-style-id=' + id + ']');
187188
if (el && el.parentNode) el.remove();
188189
}
189190

0 commit comments

Comments
 (0)