Skip to content

[css-cascade] Idea: Multiple Values for a Property #9490

Open
@AdamSobieski

Description

@AdamSobieski

Introduction

What if a property could have multiple values?

What if a property could have multiple values which were aggregated or pooled from multiple declarations?

Syntax

Generators-based Option

Let us consider the following generators-based syntax idea:

div { *prop: yield(x); }
#el { *prop: yield(y); }
.cls { *prop: yield(z) yield(w) !important; }

which intends to communicate that the element:

<div id="el" class="cls" />

would have multiple values, {z, w}, for its property prop.

Aggregation from Multiple Declarations

Let us add a prefixed symbol, ^, to be able to express that the resultant iterable value is desired to aggregate or to pool values from multiple declarations. The following syntax:

div { ^*prop: yield(x); }
#el { ^*prop: yield(y); }
.cls { ^*prop: yield(z) yield(w); }

intends to communicate that the element:

<div id="el" class="cls" />

would have multiple values, {x, y, z, w}, for its property prop.

Single-valued and Multiple-valued Semantics

Traditional single-valued and new multiple-valued semantics could co-exist in a system. This co-existence would be enhanced if multiple-value declarations would be processed in an algorithmic ordering (see: cascade and specificity). This would provide an interesting default sorting on sequences of values with respect to iteration.

Object Model

With respect to adding this functionality to CSS, we might want to consider CSSStyleDeclaration which provides the getPropertyValue() method which is specified as returning a CSSOMString value rather than an object value. An object value could indicate that a return value could be a string or an iterable of strings, e.g., an array or list. For a string-based output for multiple values, perhaps a delimited string could be utilized? Perhaps there could also be a getPropertyValues() (plural) function on CSSStyleDeclaration which would return an iterable of strings, e.g., an array or list, this having one element for single-value scenarios.

Perhaps something like the following might work:

var element = document.getElementById('el');

for (const value of element.style.getPropertyValue('prop'))
{
  console.log(value);
}

this outputting something like

x
y
z
w

Conclusion

I hope that these ideas are of some interest to the group. What do you think of the capability for properties to have multiple values? Do any other syntax possibilities come to mind with which to express these ideas?

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