-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Passing an object with a custom toString() as a 'class' attribute #401
Comments
@BenoitZugmeyer I'm actually toying with the idea of dropping support for Object class values. If I did, would this method begin to work? It would simply be removing these three lines: https://github.com/developit/preact/blob/master/src/dom/index.js#L27-L29 |
Just tried commenting those lines, and yes it works as I expect. (Sorry my fix suggestions were on an older version of preact) |
heh yeah things are moving quickly around here 😅 |
@developit the change @BenoitZugmeyer is proposing should also allow glamor to be used with preact. https://github.com/threepointone/glamor/blob/master/src/index.js#L235-L237 |
Oooh that's huge, I am actually looking into glamor right now haha. We might need to have a 7.1 and then immediately an 8.x release though, dropping object |
Came here looking for this since I am using |
Absolutely, should be seeing this land very soon. Cheers! |
So, I tested Preact 8 in a small project of mine, and I found a single issue, related to this ticket. The Test case: <svg class={{ toString() { return "pwet" } }} /> This is because of this test. I tried to search the history the reason of this condition, it has been introduced in 8ff9e32 without any explaination. Would it be possible to remove the |
I'm not even sure why |
Yes the |
I guess some IE or older Android or whatever webkit may reject such direct objects passing and that's why there is a check. Assuming browser does everything right could be a wrong path :-) |
@developit makes sense :-) |
Here we go: #626 |
I am writing a library using objects with a custom
toString()
method to render class names. Simplified example:It works great on plain DOM and React, but can't work with Preact because if a class attribute is an object, it will use the object enumerable keys associated with a truthy value to format the classname.
I understand why you chose to do this, and I find it quite useful. But would you consider changing the condition to format the class objects to something like:
or (might be more robust)
or (not the cleanest but might be more efficient)
I could change my library to return an object with keys as class names, but I'd prefer not to add code specific to preact.
Thank you
The text was updated successfully, but these errors were encountered: