Re: [css-houdini-drafts] [css-typed-om] Something about !important (#922)

Oh, this is a tricky one. Made a little trickier because we're adding it in after much of the API is stable.

Important is a characteristic of a _declaration_, not a _value_. But, neither old CSSOM nor Typed OM have an object that represents an individual declaration, only a declaration block ([CSSStyleDeclaration](https://drafts.csswg.org/cssom/#cssstyledeclaration) and [StylePropertyMap](https://drafts.css-houdini.org/css-typed-om/#the-stylepropertymap)).

CSSStyleDeclaration has a [separate getter](https://drafts.csswg.org/cssom/#dom-cssstyledeclaration-getpropertypriority) for retrieving the priority versus the value. So, easiest solution for retrieving the flag would be to mimic that and add a `getPriority(property)` method on StylePropertyMapReadOnly.

We can't just copy existing CSSOM approach for _setting_ important flags, though. That's done through a [third parameter to `CSSStyleDeclaration.setProperty()`](https://drafts.csswg.org/cssom/#dom-cssstyledeclaration-setproperty).  But the TypedOM equivalent, [`StylePropertyMap.set()`](https://drafts.css-houdini.org/css-typed-om/#dom-stylepropertymap-set) is defined to coalesce all subsequent parameters into a `values` array.

I'd lean towards having a separate `setPriority(priorityFlag)` method. It's not great that it is inconsistent with base CSSOM, but it _would_ be more consistent internally to have matching getter & setters.  And it makes it possible to toggle the important state without re-setting the value.  Next questions:

- Should we continue to require a literal `"!important"` string as the parameter? That's kind of annoying for devs, but leaves the API open to other `!something` flags getting added to CSS in the future.

- On the other hand, if other flags may be added in the future, is "priority" really the best name for the flag(s)?

- What should happen if you set a priority value for a property that doesn't yet exist in the style map? Options: ignore it silently, throw, or generate a new declaration with the value set to [`unset`](https://drafts.csswg.org/css-cascade-4/#inherit-initial).


-- 
GitHub Notification of comment by AmeliaBR
Please view or discuss this issue at https://github.com/w3c/css-houdini-drafts/issues/922#issuecomment-514754033 using your GitHub account

Received on Wednesday, 24 July 2019 18:48:11 UTC