-
Notifications
You must be signed in to change notification settings - Fork 711
[css-forms-1] For control-value()
to be useful it needs a way to convert to other types.
#11842
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
One possible way around this specifically for progress (and similar for meter( is to do something like below, because their values are encoded in the DOM. progress:not(:indeterminate)::fill {
inline-size: calc(100% * calc(attr(value, 0) / attr(max, 100)));
} |
The current draft includes a type argument, I suppose that argument could just be extended to whatever people find useful, you'd also be able to use it within calc(). I haven't really thought about it too much tbh |
With explicit type conversion as discussed in #6408, I think your examples would look different. progress::fill {
inline-size: convert(calc(convert(content-value(), <number>) * 100), <percentage>);
} and input[type=color]::color-swatch {
background-color: convert(content-value(), <color>);
} Note that there is no need for a progress::fill {
inline-size: convert(calc(content-value(<number>) * 100), <percentage>);
} and input[type=color]::color-swatch {
background-color: content-value(<color>);
} Though maybe it is also possible to make the return value of the function context-sensitive, i.e. let it return a With that, you could skip the explicit type definition/conversion for the progress::fill {
inline-size: convert(calc(content-value() * 100), <percentage>);
} and input[type=color]::color-swatch {
background-color: content-value();
} Sebastian |
I'd also be OK with just supporting |
Ah the |
I would prefer to see a generalized conversion function(#6408). |
This function isn't doing parsing on a value; it shouldn't take a
|
Would it then be reasonable for it to take |
- <attr()>: updated grammar - <control-value()>: new function - <random()>: updated grammar - <random-caching-options>: updated grammar - slider-orientation: new property There are also a bunch of new pseudos from CSS Forms. control-value() should be an arbitrary substitution (w3c/csswg-drafts#11860), which is not implemented in this commit, and it should take a type as a keyword (w3c/csswg-drafts#11842). random() might now be simplified at parse time when <random-caching-options> is specified as a <number>, which is not implemented in this commit.
Just want to confirm that for % we mean the percent of the value between min and max (e.g. |
No, because like I said, this is not doing CSS parsing on a value. The element has already parsed its value in an HTML-specified way, and is holding onto both a parsed and a string form of it. We just need to indicate which version of the value we want, in a way that tells CSS what that type is going to be at stylesheet parse time. Thus, the handful of specialized keywords.
Yup, that's what I meant too. 👍 |
Currently CSS Forms defines
control-value()
to be able to return a string or number, but for this to be useful we would need a way to convert to other CSS types (#6408 ?).Take
<progress>
as an example, it has a position property (which is probably more useful than the value one for this CSS func as it handles the maths between value and max to determine actual progress value) between 0 and 1. This is useful for sizing the fill portion of the control, but for that we'd need a way to make it a (percentage) length instead.Alternatively if we could pass other types into
content-value()
and the browser could do the conversion for us that'd also work?Either of these could also help with styling the color input too (along with #11837 )
The default style could be something like:
The text was updated successfully, but these errors were encountered: