Skip to content

[css-cascade-5] Add a R/W CSSStyleSheet.layer attribute for the layer name #7002

@xiaochengh

Description

@xiaochengh

(Edit: fixed some details on settings)

I'm proposing extending the CSSStyleSheet interface with a new attribute, layer.

On getting, it should return the layer name if the sheet is entirely in some cascade layer. In particular:

On setting:

  • If this is a constructed stylesheet and the new value is a non-null string, then the attribute value can be modified, and the stylesheet is treated as entirely in the given layer
  • If this is a constructed stylesheet and the new value is null, then the attribute value can be modified, and the stylesheet is treated as unlayered
  • Otherwise, throws a NotAllowedError DOMException

The primary use case is to allow adding layered constructed stylesheets, especially if the stylesheet is a 3rd party CSS module, and we want to use that to set up a web component (which we currently don't have a good way to make it layered):

import sheet from 3p-foo.css;

sheet.layer = 'new-layer';
shadowRoot.adoptedStylesheets = [sheet];

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions