-
Notifications
You must be signed in to change notification settings - Fork 716
[css-values-5] attr() and forwards compatible parsing #11035
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Not just for forwards compat, but this could help for things like display: attr(foo block | flex | grid) As per the rules in https://drafts.csswg.org/css-values-4/#component-combinators, visually it looks like there are 3 alternatives: display: attr(foo [block | flex | grid]) But separating the attr name from the syntax may be better. |
Yeah, I think just putting a comma there is what we need, similar to how we use commas to separate calculations (even when not strictly required for ambiguity, just because it makes things easier to read). This does mean that we'll have to make the type required in order to supply a fallback (we can't otherwise tell a type and a fallback apart), but that's fine I think. |
I don't think that's fine? Omitting the |
Yeah, on review I realized the same thing, so I ended up keeping the |
Is there a way forward here?
|
I think we should probably lean toward matching what @function is doing, with |
In private conversation, @fantasai pointed out that, while this is nicely unambiguous, it's starting to get pretty heavy for simple cases. For example, to indicate that you want to parse the attribute as a number and interpret it as a px length, you'd write She suggests going with the
This gives us the best of both worlds for this simple case. And I don't think it should extend to other users of |
That makes sense to me for
So this means we're dropping |
So, the exact proposal is that the parsing specifier for
|
The CSS Working Group just discussed
The full IRC log of that discussion<fantasai> Scribenick: fantasai<fantasai> TabAtkins: We switched attr() to use type definition syntax, similar to variables <fantasai> TabAtkins: But working through that, we lost some abilities <fantasai> TabAtkins: for example, saying the attr is a number representing px values <fantasai> TabAtkins: It started to get too complicated for common cases <fantasai> TabAtkins: For grammar ambiguity reasons, we suggest to wrap in type() function <fantasai> TabAtkins: and end up with a lot for simple cases. <fantasai> TabAtkins: Suggestion is to keep the <syntax> argument, but wrapped in type() <fantasai> TabAtkins: but for two cases we have an easier way to specify <fantasai> TabAtkins: for default behavior of treating attr value as a string, we introduce a keyword (string) so you can say so explicitly <fantasai> TabAtkins: and secondly, add all units as keywords, which parse as a number and attach that unit <fantasai> TabAtkins: this does slightly reduce the power of the syntax compared to before, since can't mix this behavior with other values <fantasai> TabAtkins: but I think it's OK, not a high-value use case right now; can evaluate later or add to <syntax> production <fantasai> TabAtkins: but instead of type(<number px>) can just write px, much simpler <fantasai> TabAtkins: so proposal is <fantasai> 1. Add type() wrapper around <syntax> <Rossen0> q? <kizu> +1 to the proposal <fantasai> 2. Introduce string keyword for explicitly indicating string parsing <chrishtr> +1 <fantasai> 3. Add all units to attach to a <number> <lea> I don't understand the proposed options <TabAtkins> attr(foo type(<length>)) <TabAtkins> attr(foo string) (deffault behavior) <fantasai> attr(attributename [ type(<syntax>) | string | <unit> ], fallback) <TabAtkins> attr(foo type(*)) <fantasai> lea: can you parse in a token stream? <fantasai> TabAtkins: yes, use * just like in custom properties <ydaniv> +1 <fantasai> lea: what's without the proposal? <fantasai> attr(attributename <syntax>, fallback) <fantasai> TabAtkins: wanted to wrap type() because <syntax> would make parsing complicated if we add anything in the future <fantasai> lea: could we use keyword instead of type()? <florian> wfm <fantasai> TabAtkins: using type() because that's what we do in custom functions <fantasai> TabAtkins: thought about using 'as' but consistency is good <fantasai> lea: no way to use 'as' in functions? presumably want to know where the syntax terminates <fantasai> TabAtkins: yes, and in some cases if you want to accept several keywords... <fantasai> TabAtkins: having type() wrapper makes it clearer <lea> +1 <TabAtkins> attr(foo type(one | two | three)) <oriol> +1 <fantasai> wfm <fantasai> Rossen0: Anyone else? Any objections? <fantasai> RESOLVED: Accept proposal to use type(<syntax>), add string, and add units as keywords. |
Closing, as the WG resolution successfully resolved this. The |
Recent spec resolution [0] introduced the following changes to attr type syntax: 1. Add type() wrapper around <syntax> 2. Introduce string keyword for explicitly indicating string parsing 3. Add dimension units to attach to a <number> [0] w3c/csswg-drafts#11035 (comment) Bug: 369858674, 40320391 Change-Id: I04356918cceaf8445fcdfd896bf3567b2cce792f Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6020597 Reviewed-by: Anders Hartvoll Ruud <[email protected]> Commit-Queue: Munira Tursunova <[email protected]> Cr-Commit-Position: refs/heads/main@{#1383003}
Recent spec resolution [0] introduced the following changes to attr type syntax: 1. Add type() wrapper around <syntax> 2. Introduce string keyword for explicitly indicating string parsing 3. Add dimension units to attach to a <number> [0] w3c/csswg-drafts#11035 (comment) Bug: 369858674, 40320391 Change-Id: I04356918cceaf8445fcdfd896bf3567b2cce792f Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6020597 Reviewed-by: Anders Hartvoll Ruud <[email protected]> Commit-Queue: Munira Tursunova <[email protected]> Cr-Commit-Position: refs/heads/main@{#1383003}
… changes, a=testonly Automatic update from web-platform-tests Change attr type syntax with recent spec changes Recent spec resolution [0] introduced the following changes to attr type syntax: 1. Add type() wrapper around <syntax> 2. Introduce string keyword for explicitly indicating string parsing 3. Add dimension units to attach to a <number> [0] w3c/csswg-drafts#11035 (comment) Bug: 369858674, 40320391 Change-Id: I04356918cceaf8445fcdfd896bf3567b2cce792f Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6020597 Reviewed-by: Anders Hartvoll Ruud <[email protected]> Commit-Queue: Munira Tursunova <[email protected]> Cr-Commit-Position: refs/heads/main@{#1383003} -- wpt-commits: 51ac948eb3f2859dab874d2103c9e14cf4cfd5b5 wpt-pr: 49173
… changes, a=testonly Automatic update from web-platform-tests Change attr type syntax with recent spec changes Recent spec resolution [0] introduced the following changes to attr type syntax: 1. Add type() wrapper around <syntax> 2. Introduce string keyword for explicitly indicating string parsing 3. Add dimension units to attach to a <number> [0] w3c/csswg-drafts#11035 (comment) Bug: 369858674, 40320391 Change-Id: I04356918cceaf8445fcdfd896bf3567b2cce792f Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6020597 Reviewed-by: Anders Hartvoll Ruud <[email protected]> Commit-Queue: Munira Tursunova <[email protected]> Cr-Commit-Position: refs/heads/main@{#1383003} -- wpt-commits: 51ac948eb3f2859dab874d2103c9e14cf4cfd5b5 wpt-pr: 49173
… changes, a=testonly Automatic update from web-platform-tests Change attr type syntax with recent spec changes Recent spec resolution [0] introduced the following changes to attr type syntax: 1. Add type() wrapper around <syntax> 2. Introduce string keyword for explicitly indicating string parsing 3. Add dimension units to attach to a <number> [0] w3c/csswg-drafts#11035 (comment) Bug: 369858674, 40320391 Change-Id: I04356918cceaf8445fcdfd896bf3567b2cce792f Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6020597 Reviewed-by: Anders Hartvoll Ruud <[email protected]> Commit-Queue: Munira Tursunova <[email protected]> Cr-Commit-Position: refs/heads/main@{#1383003} -- wpt-commits: 51ac948eb3f2859dab874d2103c9e14cf4cfd5b5 wpt-pr: 49173
Now that
attr()
's syntax expands toattr(<qname> <syntax>? [, <fallback-value>]?)
where<syntax>
has a fairly complex grammar, I was wondering if we need a divider between the two in case we ever want to expand the first argument?(That said, I do like having the symmetry with
var()
, which delineates the variable as the variable before a comma, and the fallback value as everything after.)The text was updated successfully, but these errors were encountered: