[whatwg] More stepUp() and stepDown() comments (was: Re: Forms-related feedback)

Ian Hickson ian at hixie.ch
Wed Jan 30 11:43:56 PST 2013


On Wed, 30 Jan 2013, Ian Hickson wrote:
> 
> Mounir and I discussed this on IRC, but we didn't have enough data to 
> come to a conclusion.
>
> [...]
>
> Does anyone have any examples of UIs that give "page up" and "page down" 
> controls to change values that can also be set to out-of-range values so 
> we can study how existing UIs handle this?

In the meantime, I've changed the spec as follows:

 - if there's no valid values, the methods do nothing
 - if the current value isn't numeric, assume it's zero
 - if the current value isn't on a valid step, snap to the nearest valid 
   one in the direction of the method (up or down)
 - otherwise, just go as many steps as the argument says to go
 - finally, clamp the value to the allowed range

So if the range is 0..10, step 1:

   value   stepDown(10) stepDown(1) stepUp(1) stepUp(10)
     0         0            0          1         10
     1         0            0          2         10
     5         0            4          6         10
    10         0            9         10         10
    11         1           10         10         10
    12         2           10         10         10
   100        10           10         10         10
    -1         0            0          0          9
    -5         0            0          0          5
   -10         0            0          0          0
  -100         0            0          0          0
     0.5       0            0          1          1
    -0.5       0            0          0          0
     5.00001   5            5          6          6
     9.5       9            9         10         10
    10.5      10           10         10         10
    ""         0            0          1         10

It's kind of a compromise between what I think is ideal and what Mounir 
describes as what he wants. It has the advantage of being relatively 
simple to reason about. It has the disadvantage of meaning that hitting 
"up" sometimes brings the value down, and hitting "down" sometimes brings 
the value up, and it's not linear in the case of the value not being on a 
step when the algorithm starts.

-- 
Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'



More information about the whatwg mailing list