Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions react/lib/grid-stack-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,8 @@ export function GridStackProvider({

const removeWidget = useCallback(
(id: string) => {
const element = document.body.querySelector(`[gs-id="${id}"]`);

if (element) {
gridStack?.removeWidget(element as GridItemHTMLElement);
}
const element = document.body.querySelector<GridItemHTMLElement>(`[gs-id="${id}"]`);
if (element) gridStack?.removeWidget(element);

setRawWidgetMetaMap((prev) => {
const newMap = new Map<string, GridStackWidget>(prev);
Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ export interface GridItemHTMLElement extends HTMLElement {

/**
* Type representing various ways to specify grid elements.
* Can be a CSS selector string, HTMLElement, or GridItemHTMLElement.
* Can be a CSS selector string, GridItemHTMLElement (HTML element with GS variables when loaded).
*/
export type GridStackElement = string | HTMLElement | GridItemHTMLElement;
export type GridStackElement = string | GridItemHTMLElement;

/**
* Event handler function types for the .on() method.
Expand Down
11 changes: 10 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,17 @@ export class Utils {

let list = root.querySelectorAll(els);
if (!list.length && els[0] !== '.' && els[0] !== '#') {
// see if mean to be a class
list = root.querySelectorAll('.' + els);
if (!list.length) { list = root.querySelectorAll('#' + els) }

// else if mean to be an id
if (!list.length) list = root.querySelectorAll('#' + els);

// else see if gs-id attribute
if (!list.length) {
const el = root.querySelector<HTMLElement>(`[gs-id="${els}"]`);
return el ? [el] : [];
}
}
return Array.from(list) as HTMLElement[];
}
Expand Down