Re: [csswg-drafts] [css-values-5] Invalidation of `ident()` (#11424)

> attr() has something like that built in, no?

attr(), like var(), is grabbing data from elsewhere, and that data *might not exist* - the custom property might not be defined (or is invalid), and the attribute might not exist. So having a fallback to apply in that case is an important bit of functionality, and is explicitly tied to the function's own behavior.

ident() has none of these issues. It computes its result entirely based on its provided arguments. Those arguments might themselves come from things like var() or attr(), but that's not part of  `ident()`'s functionality or responsibility. Unless we decided that *all* CSS functions should start worrying about that and have the ability to specify a fallback (and, somehow, figured out how to make that grammatically unambiguous across all functions), I don't think we should special-case just the `ident()` function.

We also *already have* a function designed to handle exactly this case: [`first-valid()`](https://drafts.csswg.org/css-values-5/#first-valid).

```
background: first-valid( var(ident("--color-" var(--name))), var(--color-blue) );
```

This tries to parse `background: var(ident("--color-" var(--name)))`, and if that fails *for any reason*, falls back to parsing `background: var(--color-blue)` instead. 

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


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

Received on Thursday, 30 January 2025 17:02:48 UTC