Skip to content

Not deleting attributes.className.#36

Closed
saboya wants to merge 2 commits intodevelopit:masterfrom
saboya:className
Closed

Not deleting attributes.className.#36
saboya wants to merge 2 commits intodevelopit:masterfrom
saboya:className

Conversation

@saboya
Copy link
Contributor

@saboya saboya commented Feb 27, 2017

Hi. I came across an issue that, if I use className, when the preact components re-renders, the class attributes in my elements are lost. If I use "class", everything just works. I realize that preact recommends class over className, but since className was supposed to work as well (at least according to preactjs/preact#103), I'd consider this a bug.

This is a simple change, but I imagine this code is here for a reason.

Thanks in advance!


function setClass(attributes, value, append) {
let cl = getClass(attributes);
if (attributes.className) delete attributes.className;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this will mess up rendering. Likely will render class twice (since its aliased)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my tests, here's what happens (post-patch):

If only className is set, works as intended (class rendered once, correctly).
If only class is set, works as intended (class rendered once, correctly)
If both class and className are set, class is ignored and className is rendered correctly (as the class attribute).

Copy link
Owner

@developit developit Feb 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just wondering if it overwrites preact-mdl's class modifications. I can set up a test if needed, could just be this test but with added class and className variants to verify that the MDL button classes still make it out to the DOM:
https://github.com/developit/preact-mdl/blob/master/test/index.js#L27

@saboya saboya closed this Aug 20, 2024
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

Successfully merging this pull request may close these issues.

2 participants