Skip to content

Can an @apply rule be used inside a custom property bag declaration by the same name? #43

@philipwalton

Description

@philipwalton

For example, imagine inside <my-element> you have the following style declaration:

:host {
  /* Sets some defaults */
  --my-element-styles: {
    color: red;

    /* But also applies any inherited declarations. */
    @apply --my-element-styles;
  }
}

I've been experimenting with the @apply feature in Polymer and, when composing elements, I quickly found myself wanting to have the composing element set some custom property values yet still allow for parent elements to override them. As far as I can tell, that's not supported (at least not explicitly) in this proposal (Polymer fails when trying this).

Conceptually related, it's not clear to me whether custom property bags operate as a merge (like they do on elements) or as an override.

For example, consider the following HTML structure and CSS rules:

<div class="parent">
  <div class="child">
    <div class="grandchild">
      text...
    </div>
  </div>
</div>
.parent {
  --styles: {
    font-family: monospace;
  }
}
.child {
  --styles: {
    color: red;
  }
}
.grandchild {
  @apply --styles;
}

Is the text red and monospaced, or is it just red because --styles was overriden in .child?

What I suspect is that the declarion is overridden, and if so, that could be an argument in favor of custom pseudo-elements as they could more gracefully (and predictably) handle merging of properties via the cascade.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions