Re: Implementation feedback for :nth-child(An+B of selector)

Thanks for the feedback!

On Oct 6, 2014, at 1:50 PM, L. David Baron <dbaron@dbaron.org> wrote:
> On Monday 2014-10-06 12:27 -0700, Benjamin Poulain wrote:
>> Hi,
>> 
>> I have added :nth-child(An+B of selector) to Webkit (for now as an experimental feature behind a flag but enabled by default in WebKit Nightly).
>> 
>> I have the following feedback:
>> 
>> 1) Because of the definition (An+B-1 matching the selectorList), it is almost always necessary to repeat the selectors outside and inside :nth-child(). Most cases look something like:
>>    li[foo].bar:nth-child(2n+1 of li[foo].bar)
>> 
>> I personally like the power given by that definition but it is counter intuitive to write selectors with it. In my opinion, it would be beneficial to have one example covering this aspect in the specification.
> 
> I wonder if that's really what we want, though.  I tend to think
> it's not.  (Just because the :nth-child() definitions were written a
> certain way before we added the "of" feature doesn't mean that we
> want to keep the formal definition the same way once it starts
> mattering which of two choices [1] we take for how to write the
> formal definition.)
> 
> At the very least, I don't think the group discussed this when
> agreeing to add the feature, and I think we should.

I am very much divided on this.

On one hand, the current definition allows for some cool stuff.

For example, you can easily get any image appearing directly after the first paragraph and only the first paragraph:
 img:nth-child(2 of p)
or with no paragraph above:
 img:nth-child(1 of p)

On the other hand, those selectors are unreadable. I believe matching the current element with “p” would help people keep their sanity.

I am in favor of matching the selector list against the “source element” because it makes the pseudo class easier to use but I am afraid this would cut valid use cases.

>> 2) Currently, the implementation generate a parsing error if pseudo elements are used within the nested selector list. The internal definition is the same as :not().
>> I believe this is the most useful definition for web developers as there is no added magic. Tab was in favor of silently ignoring pseudo elements. I would love to get more feedback on this.
> 
> It's certainly consistent with existing selector behavior to give
> an error; I prefer it for at least that reason.

Great!

>> 3) The spec’s grammar does not cover :nth-child(An+B of selector). The current WebKit implementation make the selector list mandatory if the keyword “of” is present (e.g. :nth-child(2n of ) is invalid). The spec defines ":nth-child(An+B [of sel]?)” then say "If sel is omitted, it defaults to *.”.
> 
> Requiring a nonempty selector after "of" sounds right to me.

Good.

> 
> -David
> 
> [1] "has An+B-1 previous siblings" vs. "is the An+B'th sibling"
> 
> -- 
> 𝄞   L. David Baron                         http://dbaron.org/   𝄂
> 𝄢   Mozilla                          https://www.mozilla.org/   𝄂
>             Before I built a wall I'd ask to know
>             What I was walling in or walling out,
>             And to whom I was like to give offense.
>               - Robert Frost, Mending Wall (1914)

Received on Tuesday, 7 October 2014 01:51:57 UTC