Skip to content
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

[css-values?] Accept <number> where <integer> is expected #6786

Closed
LeaVerou opened this issue Nov 1, 2021 · 4 comments
Closed

[css-values?] Accept <number> where <integer> is expected #6786

LeaVerou opened this issue Nov 1, 2021 · 4 comments
Labels

Comments

@LeaVerou
Copy link
Member

LeaVerou commented Nov 1, 2021

Currently there are a lot of places where authors end up having a <number> instead of an <integer> without realizing, then are puzzled why their code doesn't work.

For example:

--columns: 12;
grid-column-end: span calc(var(--columns) - 8); /* works */
grid-column-end: span calc(var(--columns) / 3); /* fails, IACVT */

Same issues with counter-reset, z-index and the list goes on.

In fact, clever authors have even come up with terrible hacks for working around this by assigning the number to a registered <integer> property and taking advantage of that implicit conversion. Sure, once floor() and friends are supported this would be much simpler, but IMO authors should not even have to think about this. A 5 is a 5, whether it was generated as 4 + 1 or as 15 / 3. Since <number> cannot be disambiguated from <integer>, I doubt we have any syntax that depends on them being incompatible.

Proposal: accept <number> anywhere an <integer> is accepted, after flooring (or rounding, no strong opinion).

@Loirooriol
Copy link
Contributor

The spec already says

Additionally, [=math functions=] that resolve to <<number>>
can be used in any place that only accepts <<integer>>;
the value is [=rounded to the nearest integer=] as it resolves.

@emilio
Copy link
Collaborator

emilio commented Nov 1, 2021

Yeah, this already works per spec. Firefox implements it correctly afaict, not sure about other browsers, but we have tests for this.

@emilio emilio closed this as completed Nov 1, 2021
@LeaVerou
Copy link
Member Author

LeaVerou commented Nov 1, 2021

Yeah, this already works per spec. Firefox implements it correctly afaict, not sure about other browsers, but we have tests for this.

Ah, thanks, must be a Chrome bug then. By "we" you meant csswg tests or Gecko tests?

@Loirooriol
Copy link
Contributor

Chromium was recently fixed in https://crbug.com/931216
There are tests in WPT, like https://wpt.fyi/results/css/css-values/calc-rounds-to-integer.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants