I searched and tried to add the <iframe><CustomWebChat/></iframe encapsulation, however I ended up getting empty iframe without the proper styles and with empty head and body. Basically I tried doing 2 approaches:
Replace the
in the index.html with
My understanding is that an iframe provides a portal view to another URL. I don't believe it is used to encapsulate components. @compulim do you have insight?
For <IFRAME>, it should have a src attribute pointing to another HTML file to be shown inside the designated area.
You can put content inside <IFRAME>, but the content will not show up on browsers that supports<IFRAME>. The content of <IFRAME> is fallback for browser which does not support <IFRAME>.
Could you separate Web Chat into its own HTML file and link it to src attribute?
On the other side, we are considering moving to BEM naming convention in CSS and it would reduce conflicts.
I wasn't talking about naming conflicts. Basically if you have a website with body style
.body div {
background-color: blue;
}
And then you insert the widget through the root div, this styling will affect all your divs (if you don't overwrite background-color in your own div's style). So this might not be a problem, however if the body says line-height: 30px... how are you going to know which styles to overwrite. Basically you are inserting the chat in unknown websites body who has who knows what kind of CSS. I can't overwrite nor reset the css, so think about that.. And what if the website's body has !important...
On the other hand if I use it isolates my widget, but it opens another problem. The position and size of my widget has to be set on the same level where the iframe is (and that is on the hosting website) instead from the React project. In order to understand my project structure and this is not clear enough please read my other question here: https://github.com/facebook/create-react-app/issues/6205
@compulim I am using my widget with multiple states:
Launcher (minimized chat)
Suggestion Launcher (minimized chat with short text next to it -> e.g. Hi i am here to help you, click me)
The chat itself...
This is why i want to insert my whole widget inside of iframe that is going to have the stylings of the root div. What I mean is instead of having <div id="root"/> I want to have <iframe id="root"/>... btw i know that iframe requires src, but can't we wrap the widget inside iframe in order to isolate it from inherited styles??? @compulim I don't think this should be a question, rather than that it should be bug or enhancement, but maybe I am wrong, I am not very experienced.
From your description, I believe you want to isolate your Web Chat component from the rest of the html page. Ideally you want to do this with iframe. This is particularly to avoid CSS collisions that may occur.
I took at look at the MDN iframe page and it looks like iframes do not have children (so no divs or other elements inside the iframe). It only links to an external source and does not allow for modification of that source. This means that while your iframe MAY have an id, as you wrote above: <iframe id="root"/>, any styling you apply to the child of #root in your CSS will not affect the linked resource.
I took a look at your facebook create-react-app issue and notice that you make no mention of an iframe over there. It looks like this may be a misunderstanding of the functionality that iframe provides. I think that @compulim's suggestion of hosting your Web Chat on another page and src linking that via iframe is reasonable. This means you can style your Web Chat (including size of the window) however you deem fit on a separate page, and link that to your main page via iframe with no collisions. This could also potentially make debugging and such easier for you. :)
Yes, that is the implementation I went for, thank you @corinagum. But still I would strongly recommend having some mechanism to isolate the web chat from the hosting webpage, because it should work as widget. I am going to close this issue now, but you may consider some solution for the future :)
Now the only problem I am facing is passing the clicks through the transparent background of the iframe... If I disable the clicks (pointer-events: none) then I can't click around in my chat widget.. I will post the solution if I manage to find one :)
@ljubomirsinadinovski Did you get a solution above ?
I can't recall to be honest. This is ancient for me. Try googling and researching, i was beginner back then so i probably didn't post it because of lack of work ethics. I bet there is a solution... always, hust keep pushing.