Skip to content

Prevent page styles from bleeding into the component #1274

@rameshanandakrishnan

Description

@rameshanandakrishnan

Currently, OC components are within the scope of the light DOM and do not provide any forms of style isolation out of the box. This potentially leaves the components to be altered by rogue global styles. Style isolation will be a nice feature to have so that we can ensure that the component will look the same regardless of where you use it. I would like to propose the inclusion of shadow DOM as part of the OC to prevent page styles from affecting the component and also prevent the component styles from leaking out.

I have played around with a POC and this is how it can be achieved:

  1. The means of toggling the shadow DOM feature can be handled via data-attributes (e.g. <oc-component …. data-enableShadow=true … /> ) of the OC element.
  2. We will need to update oc-clint.js in OC-CLIENT-BROWSER to handle the creation of shadow root in which the HTML markup can be set. This can be done in the processHTML method.
  3. Update the relevant templates to indicate that the target node is currently present in the shadow root rather than the light DOM.

I would like your feedback on this matter and am happy to make a PR once we agree on a solution.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions