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

Cast className using toString #2309

merged 2 commits into from Nov 24, 2018


Copy link

@porsager porsager commented Nov 24, 2018


When mithril normalizes classNames it now ensures toString is called before concatenating strings. This ensures mithril works like the browser does when setting dom.className =. The browser always calls toString for either dom.classList.add() or dom.className =

Motivation and Context

This makes mithril behave more like the dom, and allows bss (and maybe others) to support casting to a className using a period when doing

m('div' + b('background blue')) => m('div.bssClass')

and not adding a period when doing

m('div', { class: b('background blue') }) => m('div', { class: 'bssClass' })

flems with fixed mithril

flems without fix

How Has This Been Tested?

Added a test to check if toString is called when using className attr.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation change


  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • I have updated docs/

@porsager porsager requested a review from pygy as a code owner November 24, 2018 12:07
@project-bot project-bot bot added this to Needs triage in Triage/bugs Nov 24, 2018
Copy link

@dead-claudia dead-claudia left a comment

Choose a reason for hiding this comment

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


@dead-claudia dead-claudia merged commit 421474c into MithrilJS:next Nov 24, 2018
Triage/bugs automation moved this from Needs triage to Closed Nov 24, 2018
Copy link

This reads more like a bug than anything (hence the quick merge). @porsager If you wouldn't mind, would you like to ensure the rest of the renderer prefers toString over valueOf for coercing to strings?

Copy link
Contributor Author

Sure thing, I'll try to go through it Monday 😉

Copy link
Contributor Author

Ok, just went through it, and I don't think there are other places where it matters.

There is some "" + value usage, but that's dom.value, so I don't think that should change..

Copy link

Okay, thanks!

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

Successfully merging this pull request may close these issues.

None yet

2 participants