Add CSS styles to classic editor when in a Web Component #7847
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Suggested merge commit message (convention)
Other (build-classic): Update webpack config to save styles to global array.
Change any CSS rules with the :root selector to :root, :host to accommodate Web Components.
Additional information
Related to #3891 and #1483.
By default,
style-loader
will add the CSS styles to the<head>
of the document. However, document styles do not get applied to shadow roots as part of Shadow DOM's style encapsulation. Overriding the default behavior by providing a function to theinsert
option saves all of the styles in a global array in addition to adding them to the document<head>
allows for adding the styles from the array into a shadow root after it's been initialized.For example, if creating a web component with CKEditor, one could do the following in the constructor:
to add the styles to the shadow root.
This PR also changes any CSS rules with the :root selector to :root, :host, as :root doesn't select anything inside of a web component.