styled-jsx icon indicating copy to clipboard operation
styled-jsx copied to clipboard

Add support for custom HTML tags

Open ottobonn opened this issue 4 years ago • 2 comments

This PR is my follow-up to the discussion in https://github.com/zeit/next.js/discussions/13376. It adds support for custom HTML tags (whose names are lower case and contain hyphens) to styled-jsx.

Here's an example of such a tag in React:

export default function Test() {
  return (
    <my-test class="root">
      <style jsx>{`
        .root {
          margin: 0;
          width: 100%;
          height: 100%;
        }
      </style>
    </my-test>
  );
}

Before this PR, the output of styled-jsx would be:

<my-test class="root" className="jsx-12345">

This output is not quite right, because React passes through the raw class attribute of the element for custom HTML tags, and styled-jsx is attaching additional class names to className.

This PR adds code to detect custom element names and to use class instead of className for them.

ottobonn avatar May 27 '20 04:05 ottobonn

Looks like the CI build failed due to the Zeit/Vercel rename...

ottobonn avatar May 28 '20 02:05 ottobonn

Thanks for figuring this out @ottobonn! Running into this issue with people trying to use styled-jsx with media-chrome custom elements. Is there something I can do to help get this over the line?

heff avatar Mar 23 '21 04:03 heff