react-colorful icon indicating copy to clipboard operation
react-colorful copied to clipboard

react-colorful not working if we use it with react-shadow

Open hamed-musallam opened this issue 2 years ago • 3 comments

here is a sample of the code, I just embedded your HexColorPicker component under the root shadow

https://codesandbox.io/s/react-colorful-demo-forked-6vivtb?file=/src/App.js

import React, { useState } from "react";
import { HexColorPicker } from "react-colorful";
import root from "react-shadow/emotion";

export default function App() {
  const [color, setColor] = useState("#b32aa9");

  return (
    <root.div>
      <HexColorPicker color={color} onChange={setColor} />
    </root.div>
  );
}

hamed-musallam avatar May 05 '22 09:05 hamed-musallam

This is intended and a side-effect from how react-colorful distributes the CSS by injecting it directly into the head of the document:

https://github.com/omgovich/react-colorful/blob/a85e5b36b55cae7e95c73c8ecde0bc881e8e3b1f/src/hooks/useStyleSheet.ts#L11-L30

This just won't work with shadow DOM.

rschristian avatar May 09 '22 00:05 rschristian

CodeSandbox for the issue: HexColorPicker with shadowroot .

definite2 avatar Jun 05 '22 18:06 definite2

I fixed it by injecting the styles as global styles and I got it from here: https://github.com/omgovich/react-colorful/blob/master/src/css/styles.css

blackforestboi avatar Dec 14 '22 17:12 blackforestboi