primereact icon indicating copy to clipboard operation
primereact copied to clipboard

ConfirmDialog: is not loading inside a Shadow DOM

Open kartheekgadduru opened this issue 3 years ago • 9 comments

Describe the bug

I have the code as below with file name testView.tsx `import * as React from "react"; import * as ReactDOM from "react-dom";

import "./theme/resourceapp/theme.css"; import "primereact/resources/primereact.min.css"; import "primeicons/primeicons.css"; import {TuningBucket} from "./components/tuning/TuningBucket"; import {TestView} from "./components/TestView";

const root = document.getElementById("test-view") as HTMLElement; const shadowRoot = root.attachShadow({ mode: "open" });

const reactRoot = document.createElement("div"); shadowRoot.appendChild(reactRoot);

const event = new Event("react-ready"); document.dispatchEvent(event);

ReactDOM.render(, reactRoot);`

And TestView.tsx file code `import * as React from "react"; import {useState} from "react"; import {Button} from "primereact/button"; import {ConfirmDialog} from "primereact/confirmdialog";

export const TestView = () => { const [visible, setVisible] = useState(false); const reject = () => { console.log("reject "); }; const accept = () => { console.log("accept "); }; return (

<Button label={"Update"} onClick={() => setVisible(true)} > <ConfirmDialog visible={visible} onHide={() => setVisible(false)} message="Are you sure you want to proceed?" header="Confirmation" icon="pi pi-exclamation-triangle" accept={accept} reject={reject}/>
); }` ConfirmDialog code is loading outside of Shadow Dom (shadow-root) when I inspect from developer tools because of that stylings of primereact is not applying to ConfirmaDialog component. can be seen with below image.

  • From the image the one which is rounded with black is the output for the ConfirmDialog component
  • Rounded with Green is the Shadow Dom code which includes all the Primereact stylings
  • And Rounded with Red is the code of ConfirmDialog at run time loading out side of ShadowDom

confirmDialogIssue

Reproducer

No response

PrimeReact version

^8.1.1

React version

17.x

Language

TypeScript

Build / Runtime

Create React App (CRA)

Browser(s)

No response

Steps to reproduce the behavior

No response

Expected behavior

No response

kartheekgadduru avatar Feb 24 '23 11:02 kartheekgadduru

Need you guys help to fix such that ConfirmDialog code should come inside of Shadow dom code So that the styling of the ConfirmDialog code applied correctly.

kartheekgadduru avatar Feb 24 '23 11:02 kartheekgadduru

Can you create a reproducer so we can see what you are talking about and debug it?

melloware avatar Feb 24 '23 12:02 melloware

confirmDialog

kartheekgadduru avatar Feb 25 '23 02:02 kartheekgadduru

Screenshots don't help.
A Code Sanbox reproducer would help.

melloware avatar Feb 25 '23 03:02 melloware

Hi,

Unfortunately, I couldn't replicate this issue. Please try; https://codesandbox.io/s/primereact-test-forked-uxr48m?file=/src/index.js

If the problem persists, please reopen this issue. For now, closed. Thanks a lot for your understanding!

Best Regards,

mertsincan avatar Mar 09 '23 11:03 mertsincan

@mertsincan Your codesandbox example does exactly what @kartheekgadduru describes :) Look at your confirm an delete buttons. The are not styled because the are in the shadow dom. Now your Dialog is placed outside the shadow DOM (in the normal DOM tree) so it is styled.

But this is how I solved my normal Dialog in the Shadow Dom <Dialog appendTo={context.shadowRoot} />

Where my context knows about the shadowRoot and the entire App waits until it is available.

This probably will work for @kartheekgadduru and the ConfirmDialog as well.

rogiermulders avatar Mar 09 '23 13:03 rogiermulders

I tried this <ConfirmDialog appendTo={context.shadowRoot}/> but that does indeed not work.

The Dialog component works though. See both in action here https://codesandbox.io/s/5wou0t

At this moment I do not know how to get all the primereact css in the Shadow DOM of codesandbox so just one class there, but you should get the point.

PS I really really like primereact so thank you all.

rogiermulders avatar Mar 10 '23 08:03 rogiermulders

HI @melloware and @rogiermulders Please find my codesandbox url (https://codesandbox.io/s/vigorous-framework-ngnggk) for the code in my project in which I am testing the ConfirmDialog should render inside the shadowRoot and should apply all the styles of prime react for the ConfirmDialog component

 import 'primeicons/primeicons.css';
import 'primereact/resources/themes/lara-light-indigo/theme.css';
import 'primereact/resources/primereact.css';

but in my code I supposed to have anchored tag similar to after login button from codesandbox url

 <a href="./testView.do">
        testView
    </a>

Whatever the code which have provided from the codesandbox url is working in my local. I think this info is helpful to address my issue related to ConfrimDialog primereact component please let me know if you need some more information which is needed for this issue

kartheekgadduru avatar Mar 10 '23 10:03 kartheekgadduru

Fixed with: https://github.com/primefaces/primereact/pull/5566

melloware avatar Jan 05 '24 22:01 melloware