Skip to content

Emotion and Shadow DOM support #7158

@cee-chen

Description

@cee-chen

Problem

Currently, EUI uses several Emotion <Global /> components which inject styles directly into the head:

return <Global styles={styles} />;

return <Global styles={globalStyles(euiTheme)} />;

<Global styles={euiOverlayMaskBodyStyles} />

<Global styles={{ ':root': themeCSSVariables }} />

This head insertion occurs even when EUI is instantiated from the shadow DOM (when styles should instead be inserted into the shadow DOM container)

Solution

We need to do the following:

  1. Either:
    1. Attempt to automatically detect when EuiProvider is instantiated within a shadow context, or
    2. Allow consumers to pass us a prop that says EUI is being used within shadow DOM (my strong preference, as far less will go wrong this way)
  2. Add our own <GlobalOrHost /> component that returns a global if not shadow DOM, and a :host stylesheet/selector if shadow DOM
  3. Require consumers to pass us their Shadow DOM container/root (required for us to append styles to the correct location)

TO INVESTIGATE: Will absolutely or fixed positioned items like headers & flyouts still work as expected? Is the shadow DOM iframe-like in behavior in that regard?

Other resources/reading:

Metadata

Metadata

Assignees

No one assigned

    Labels

    emotionstale-issue(Don't delete - used for automation)stale-issue-closed(Don't delete - used for automation)

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions