Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sidebar items rely on attribute gridstacknode, it should be data-gridstacknode instead for react+TS compatiblity #2900

Open
BrannJoly opened this issue Dec 11, 2024 · 1 comment

Comments

@BrannJoly
Copy link

BrannJoly commented Dec 11, 2024

in a React + Typescript environment, to use sidebar items, one would write this:

<div className={`sidebar`}>
 <div className="sidebar-item" gridstacknode='{"w":2, "h":2, "content":"..."}'> // ts error : property 'gridstacknode' does not exist on type 'DetailedHTMLProps<HTMLAttributes, HTMLDivElement>
         ...
  </div>
</div>

and then, following the docs example

  const myClone = (el: HTMLElement): HTMLElement => {
    const clone = el.cloneNode(true) as HTMLElement;
    const content = el.getAttribute('gridstacknode') || 'Dropped Item';
    clone.innerHTML = content;
    return clone;
  };

Unfortunatley, this code doesnt compile :

Type '{ children: string; className: string; gridstacknode: string; }' is not assignable to type 'DetailedHTMLProps<HTMLAttributes, HTMLDivElement>'.
Property 'gridstacknode' does not exist on type 'DetailedHTMLProps<HTMLAttributes, HTMLDivElement>'.ts(2322)

The normal fix would be to prefix the unknown attribute by data (ie data-gridstacknode), so I tried that in both the div and the myclone function, but it doesnt work. I dug around, and it turns out 'gridstacknode' is actually hardcoded in gridstack.ts

In order to retain backwards compatiblity, maybe it would make sense to first check 'gridstacknode' and then, if it is not found, to fall back on data-gridstacknode ?

@BrannJoly
Copy link
Author

I fixed the issue in my codebase by doing this, but this should be handled in gridstack IMHO!

declare module 'react' {
  interface HTMLAttributes<T> {
    gridstacknode?: string;
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant