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

Bug: Prop with name "is" breaks the className prop on tag #17944

Closed
marceloadsj opened this issue Jan 31, 2020 · 5 comments
Closed

Bug: Prop with name "is" breaks the className prop on tag #17944

marceloadsj opened this issue Jan 31, 2020 · 5 comments
Labels
Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug

Comments

@marceloadsj
Copy link

marceloadsj commented Jan 31, 2020

If you add a prop named "is" together with a "className" prop, on a html tag component
(e.g. <div is="p" className="text-red">) it "breaks" the markup and render an attribute "classname" instead of "class".

React & React DOM version: 16.12.0

Steps To Reproduce

  1. Write a simple component that render a html tag
  2. Add a prop named "is" and a "className"
  3. Check the rendered markup

Link to code example: https://codesandbox.io/s/quiet-sun-535rg

Example:
<div is="p" className="text-red">I'm not red</div>

The current behavior

Injecting the props as html attrs.

Markup:
<div is="p" classname="text-red">I'm not red</div>

The expected behavior

Markup:
<div is="p" class="red">I'm red</div>

@marceloadsj marceloadsj added the Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug label Jan 31, 2020
@michalczaplinski
Copy link

If you set an is prop on a react component, react treats it as a Custom Element.

https://github.com/facebook/react/blob/master/packages/react-dom/src/shared/isCustomComponent.js#L12

Because of this, props like className or htmlFor are not translated to class and for because you might have an attribute with that same name (like className or htmlFor) used by your custom element.

The documentation mentions this briefly https://reactjs.org/docs/web-components.html

One common confusion is that Web Components use “class” instead of “className”.

I can agree that it's def a bit confusing 😅

@bvaughn
Copy link
Contributor

bvaughn commented Feb 3, 2020

@michalczaplinski is correct! The is attribute is an HTML standard thing:

https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/is

The is global attribute allows you to specify that a standard HTML element should behave like a defined custom built-in element (see Using custom elements for more details).

In this case, I think React DOM is behaving reasonably (although I understand why it could be a bit surprising too)

@bvaughn
Copy link
Contributor

bvaughn commented Feb 3, 2020

This issue has come up a few times in the past:

Dan's comment seems inline with ours above:
#7200 (comment)

There's also been some extensive discussion about the className property on web components here: #4933

Our web component docs suggest using a class attribute in such cases, as confirmed by this comment.

I'm going to close this issue since I think it's all been discussed before 😄

@bvaughn bvaughn closed this as completed Feb 3, 2020
@marceloadsj
Copy link
Author

Maybe would be good to have a section on docs saying about this. What do you think?

It's hard to search because of the word "is", so, if we add a FAQ explaining, it will avoid that kind of issues being opened.

I just opened because I didn't find anything on docs or github issues, searching for keywords like "prop html tag is className attribute".

:)

@bvaughn
Copy link
Contributor

bvaughn commented Feb 3, 2020

Sure, if you have ideas for how to improve the docs page send them our way.

This page:
https://reactjs.org/docs/web-components.html

Is here:
https://github.com/reactjs/reactjs.org/blob/master/content/docs/web-components.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug
Projects
None yet
Development

No branches or pull requests

3 participants