Re: [selectors4] Attribute selectors for numerical comparison

On Mon, Nov 2, 2015 at 9:07 AM, Lea Verou <lea@verou.me> wrote:

> It seems that the need for greater-than and less-than operators in
> attribute selectors (i.e. [attr>value]) is very common, yet we only have
> equality and partial string matching. I imagine this is because every
> attribute is a string, but I don’t understand why we can’t define the
> selector to convert the attribute value to a <number> first, using the same
> grammar as CSS. If the conversion fails, the selector doesn’t match
> anything (this is on par with how comparisons work in JS too).
>
> The main wart with this is that what authors need is not always numerical
> comparison, but sometimes they need to compare e.g. dates [1]. There are
> multiple ways to deal with this:
> 1. We ignore it and just deal with numbers, since that already solves
> several use cases. We can always use different comparison attribute
> selectors in the future for dates.
> 2. We use heuristics to determine whether it's a date or a number. Can’t
> think of any conflict, but it's a bit hacky.
> 3. We use a whitelist, which could be different per host language.
>


+1 but... If we could get custom pseudos done, authors could do this and
experiment and we could look at which kinds of approaches work best for
dealing with numbers, money, dates, alpha, etc.  I realize we'd like to do
it in attrs, but there's definitely more value in my mind to opening up
pseudos and looking at what arises.




>
> [1]: https://lists.w3.org/Archives/Public/www-style/2007Jan/0080.html
>
> Lea Verou ✿ http://lea.verou.me ✿ @leaverou
>
>
>
>
>
>
>
>


-- 
Brian Kardell :: @briankardell :: hitchjs.com

Received on Monday, 2 November 2015 14:23:32 UTC