Re: [csswg-drafts] [css-forms-1] For `control-value()` to be useful it needs a way to convert to other types. (#11842)

With explicit type conversion as discussed in #6408, I think your examples would look different.

```css
progress::fill {
    inline-size: convert(calc(convert(content-value(), <number>) * 100), <percentage>);
}
```

and

```css
input[type=color]::color-swatch {
     background-color: convert(content-value(), <color>);
}
```

Note that there is no need for a `type()` function. And as @nt1m pointed out in the previous comment, it also isn't part of the draft spec.
With the type attribute from the spec., those examples should look like this:

```css
progress::fill {
    inline-size: convert(calc(content-value(<number>) * 100), <percentage>);
}
```

and

```css
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 `<number>` value for `<progress>`, `<input type="range">` and other elements, a `<color>` value for `<input type="color">`, a `<url>` value for `<input type="url">`, etc.

With that, you could skip the explicit type definition/conversion for the `content-value()` function for the given use cases and write this:

```css
progress::fill {
    inline-size: convert(calc(content-value() * 100), <percentage>);
}
```

and

```css
input[type=color]::color-swatch {
     background-color: content-value();
}
```

Sebastian

-- 
GitHub Notification of comment by SebastianZ
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/11842#issuecomment-2702211969 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Wednesday, 5 March 2025 22:22:07 UTC