Skip to content

Commit f65bb22

Browse files
authored
Merge pull request #3159 from YOUNGHO8762/master
Fix bug where removeWidget does not function properly
2 parents fe9b219 + 42f0394 commit f65bb22

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

react/lib/grid-stack-provider.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { GridStack, GridStackOptions, GridStackWidget } from "gridstack";
1+
import type { GridItemHTMLElement, GridStack, GridStackOptions, GridStackWidget } from "gridstack";
22
import { type PropsWithChildren, useCallback, useState } from "react";
33
import { GridStackContext } from "./grid-stack-context";
44

@@ -72,7 +72,12 @@ export function GridStackProvider({
7272

7373
const removeWidget = useCallback(
7474
(id: string) => {
75-
gridStack?.removeWidget(id);
75+
const element = document.body.querySelector(`[gs-id="${id}"]`);
76+
77+
if (element) {
78+
gridStack?.removeWidget(element as GridItemHTMLElement);
79+
}
80+
7681
setRawWidgetMetaMap((prev) => {
7782
const newMap = new Map<string, GridStackWidget>(prev);
7883
newMap.delete(id);

0 commit comments

Comments
 (0)