[Question] Is it possible to specify where to inject style tags?
I know you guys are doing a lot of reworking on styles right now but trying to use whats out there I have a need to be able to control what document context they are injected in (this could also impact shadowDOM usage). Basically I am using this react component https://github.com/ryanseddon/react-frame-component to gain style isolation which relies on rendering react into a dynamically created iframe. This has numerous benefits and is working well for me in the various SharePoint environments that I have been doing Bootstrap-themed widget development in.
I'd like to use Fabric-UI but right now there does not seem to be a method of overriding where the styles get injected into the page. Maybe I am overlooking something, any help is appreciated, thanks!
I have the exact same question. I am using react-frame-component, and have found that the styles are being injected in the main document.headin Stylesheet.ts, and it doesn't seem to be overridable. Would the team consider an enhancement which would allow Fabric to be used within an iframe?
This is still an issue for me as well.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions to Fabric React!
This issue has been automatically closed because it has not had recent activity after being marked as stale. If you belive this issue is still a problem or should be reopened, please reopen it! Thank you for your contributions to Fabric React! Why am I receiving this notification?
Any updates on this?
@dzearing
This is a really old question, but yes absolutely you can redirect styles. It just requires a little upfront work prior to rendering components.
I made a codepen here to illustrate:
https://codepen.io/dzearing/pen/gEwGVm?editors=1011
The gist is that you need to configure the Stylesheet helper to inject differently:
Stylesheet.getInstance().setConfig({
// Uncomment this to prevent styles from being injected into the document.
// injectionMode: 0,
onInsertRule: (rule) => setText(newText => newText + rule)
});
The onInsertRule callback will be called whenever injection needs to occur. You can use this to project styles elsewhere, and you can use injectionMode: 0 to prevent the default DOM injection.
Hope that answers the question. Sorry for the long reply, I lost track of this issue.
Let us know if you need something different here.
Thanks @dzearing , that's exactly what I need. I just tried something like following and it works as expected, the styles were successfully injected into iframe. Thank you!
Stylesheet.getInstance().setConfig({
injectionMode: 0,
onInsertRule: (rule) => {
console.log(rule);
const css = document.createElement('style');
css.type = 'text/css';
css.innerHTML = rule;
frame.contentDocument.head.appendChild(css);
}
});