Re: [csswg-drafts] [css-forms-1] `control-value()` function (#7869)

@nt1m Thanks. I think it would be helpful if `control-value()`'s type argument matched the API recently decided on for `attr()`, allowing for shorthand assertions like `px`, `rem`, `string`, or any specific type using `type()` like `type(<length>)`, `type(<color>)`, etc.

This would be extremely helpful for certain input types like `color` or for converting a number type to include a unit without having to resort to the old `calc(control-value(number) * 1px)` that the latest `attr()` improvements sought to fix/avoid.

---

### Another argument for `type(<boolean>)`

Furthermore, I think this is a key example of why it would help for CSS to add support for `type(<boolean>)`. This would be timely, as CSS has approved and is imminently working to add support for functions and conditional checks like `if()`. When storing the value of an input of type `checkbox` or `radio`, it would help for those values to be stored as primitive boolean values (e.g. `true` and `false`) for explicit and clear boolean checks.

Alternatively, boolean fields could be asserted as strings (e.g. `'true'` and `'false'`), numbers or integers (e.g. `1` and `0`), or percentages (e.g. `0%` and `100%`).

I think allowing for Boolean coercion like that cloths be extremely useful, but I still feel that having an explicit `type(<boolean>)` type with primitive `true` and `false` values would be the best default here for use in functions and in `if()`.
cc @tabatkins @mirisuzanne 

---

The final missing piece in making `control-value()` extremely useful is providing a way to expose these values in the global state, if we can find a way of avoiding circulatory issues or making an exception in this case.

I proposed one solution to this in https://github.com/w3c/csswg-drafts/issues/7866

If the proper solution is not hoisting these values truly globally, perhaps it's exposing them on a `form` element associated with a control, if there's is one, since forms are naturally connected to their controls' states anyway.

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


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

Received on Wednesday, 2 April 2025 13:09:56 UTC