-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Comments
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;
}
} |
@BrannJoly thank you for the find. are you saying using <div className="sidebar-item" data-gridstack-node='{"w":2, "h":2, "content":"..."}'> gives no error ? honestly I don't tend to use DOM for attr (all done in json instead) so this didn't cross my mind. easy enough switch... Also assume you meant const content = el.getAttribute('gridstacknode')?.content || 'Dropped Item'; |
and wouldn't that be the same issues with attr |
* fix gridstack#2900 * use attr `data-gs-widget` instead of `gridstacknode` (supported as well for backward compatibility)
the type definiton above is a ugly hack (I'm modifying the react lib !) needed to use custom attributes not prefixed by data- Attributes starting by data- are considered valid, you could add data-foo='bar' to any div and react/ts wouldn't complain about anything |
Right, but I don't really want to change all existing attr to So the Q is, can gridstack export some types that would spell out those attr (which is great of TS) instead of you doing it since I know all valid attr, and not use |
That's a good point. I think exporting the types would work. And in the meantime, adding this somewhere in the documentation would probably help :) Tahnk you for your work on this very useful library! |
| I think exporting the types would work. what woulkd this look like on the GS side ? any chance you you also post a React example that uses |
* more fix gridstack#2900
* more fix gridstack#2900
* more fix gridstack#2900
in a React + Typescript environment, to use sidebar items, one would write this:
and then, following the docs example
Unfortunatley, this code doesnt compile :
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 ?
The text was updated successfully, but these errors were encountered: