Skip to content

Conversation

@keithamus
Copy link
Member

Closes #12599


<pre class=prod>
:heading() = :heading( <<An+B>># )
:heading() = :heading( <integer># )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<integer> would allow things like calc() in here. This probably only wants to permit literal integers? IDK, maybe calculations on env vars could be useful.

Though... I don't think CSS has an "integer literal" type anyway. Just a <number-token> one.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really? https://drafts.csswg.org/css-values-4/#integers doesn't seem to suggest that, instead saying it's a subset of <number-token>.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the important phrase there is "When written literally". It's not super clear in that phrasing, but you can definitely use calc() for other things that take <integer>, for example z-index

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sure calc() isn't allowed inside of selectors but I cannot find the relevant prose in spec to say where calc() is allowed.

Perhaps @tabatkins can point us in the right direction.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we've previously had a situation where a numeric type is allowed in a selector, though I might have missed that. I'm definitely nit-picking on technicalities here. 😅 But yeah Tab will know.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess calc() is supported for the <length> of a media query (although not a selector, it demonstrates that calc() has support outside of declaration values).

Perhaps I can update the spec prose here to explicitly call out that only literal <integer> values are allowed and calc() would result in a parse error? I can also update the tests to reflect this.

Copy link
Contributor

@zcorpan zcorpan Aug 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://drafts.csswg.org/css-values-4/#math says

A math function represents a numeric value, one of:
...

  • <integer>
    [...] and can be used wherever such a value would be valid.

Are arguments to functional selectors "values"? It's not super-clear to me if they should apply.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, selectors are kinda a weird space here. As we add more "generic" value-handling functions (like ident()), we'll have to make a general decision on whether they're allowed in places like a rule's selector. I lean towards disallowing, matching how An+B only allows literal ints.

So I guess, just to be clear, I recommend using <number-token>, with prose specifying that the token's type flag has to be "integer", a la the an+b definition.

(Looking at this, I just realized we have two competing definitions of <integer>, one from Syntax and one from Values, which have different definitions. That's not great. I should scope the Syntax definitions there to be specifically for an+b.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opted for <level> as a discrete type just for a little more clarity. Hopefully this works, happy to use <number-token> instead though.

@keithamus keithamus requested review from annevk and tabatkins August 21, 2025 16:23
@SebastianZ
Copy link
Contributor

Nit: The commit message and title misspell "heading" as "headng".

Sebastian

@keithamus keithamus force-pushed the css-selectors-5-move-from-heading-an-b-to-headng-integer branch from bbdca2e to 7856852 Compare August 22, 2025 08:23
@keithamus keithamus force-pushed the css-selectors-5-move-from-heading-an-b-to-headng-integer branch from 7856852 to 77149b6 Compare August 27, 2025 11:33
@keithamus keithamus force-pushed the css-selectors-5-move-from-heading-an-b-to-headng-integer branch from 77149b6 to 5300992 Compare August 27, 2025 11:33
@zcorpan zcorpan changed the title [css-selectors-5]: move from :heading(<An+B>#) to :headng(<integer>#) [css-selectors-5]: move from :heading(<An+B>#) to :heading(<integer>#) Aug 27, 2025
@keithamus keithamus merged commit 8eb3787 into w3c:main Aug 27, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reconsider <An+B># for :heading

5 participants