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

undefined should be returned when no classes are needed #182

Closed
jakubsadura opened this issue Nov 1, 2018 · 2 comments
Closed

undefined should be returned when no classes are needed #182

jakubsadura opened this issue Nov 1, 2018 · 2 comments

Comments

@jakubsadura
Copy link

jakubsadura commented Nov 1, 2018

It's quite common that we do not have any class name to be added to DOM, in such case returning undefined would allow having cleaner DOM, without empty class attributes.

Example with React's jsx:

const isFoo = false;
const isBar = false;
const classes = classNames({
  'foo': isFoo,
  'bar': isBar,
});

return (<i className={classes}/>);

results in:
<i class=""/>

while it should be:
<i/>

@see facebook/react#1448

@DiscoNova
Copy link

DiscoNova commented Oct 14, 2019

I may be commenting the obvious on this old PR, but this simply will not work on various cases where classnames is still supposed to do its thing while not introducing unexpected classes to elements.

For example ... document.documentElement.classList.add(undefined) leads to, you may have guessed it ... <html class="undefined"> - which quite likely isn't what the author of the code intended.

@dcousens
Copy link
Collaborator

See #183

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

Successfully merging a pull request may close this issue.

3 participants